Coding/Python 삽질기2008. 9. 14. 00:15
#-*- coding: cp949 -*-
# 메모장
from Tkinter import *
import tkMessageBox
import os.path
 
filename = "data.txt"
def ClearText():
    text.delete(1.0, END)  
def SaveData():
    textData = text.get(1.0, END).encode('cp949')
    tempFileData = ""
   
    if os.path.exists(filename):
        fp = open(filename, 'r')
        tempFileData = fp.read()
        fp.close()
   
    fp = open(filename, 'w')
    fp.write(textData)
    fp.write(tempFileData)
    fp.close()
   
def ShowInfo():
    tkMessageBox.showinfo("Information","http://chobocho.com\nVersion 0.1")
   
   
#----------------------------------------------------------
# main
if __name__ == "__main__":     
    root = Tk()
   
    text = Text(root, width=50, height = 20)
    text.pack()
    save_button  = Button(root, text="Save", command = SaveData)
    clear_button = Button(root, text="Clear", command = ClearText)
    info_button = Button(root, text="Info", command = ShowInfo)
    info_button.pack(side=RIGHT)
    clear_button.pack(side=RIGHT)
    save_button.pack(side=RIGHT)
    root.mainloop()


사용자 삽입 이미지

'Coding > Python 삽질기' 카테고리의 다른 글

간단한 메모장2  (0) 2008.09.17
Fractal Tree  (0) 2008.06.21
파일을 HEX 값으로 보여 주는 소스  (0) 2008.05.19
Posted by chobocho
Coding/JavsScript 삽질기2008. 8. 20. 23:14

[Source Code]

* 현재 사칙연산만 구현 되었습니다.

'Coding > JavsScript 삽질기' 카테고리의 다른 글

[Flex] 계산기  (0) 2009.07.25
[Flex] Hello, World!  (0) 2009.07.25
자바스크립트 팁  (0) 2006.01.11
Posted by chobocho
Coding/Python 삽질기2008. 6. 21. 02:07

사용자 삽입 이미지

사용자 삽입 이미지

사용자 삽입 이미지



#-*- coding: cp949 -*-
from Tkinter import *
import math
import random
RADIAN = math.pi / 180
aColor = [ "brown", "red", "blue", "green", "orange", "black" ]
def DrawTree( startX, startY, angle, length, depth ):
    if depth == 0:
        return
   
    rand=random.random;
    endX = startX + length * math.cos(angle * RADIAN)
    endY = startY - length * math.sin(angle * RADIAN)
    myCanvas.create_line( startX, startY, endX, endY, width = depth, fill=aColor[int(depth * rand()) % 6])
   
    rand=random.random;
    DrawTree( endX, endY, angle + 30 * rand(), length * (rand() + 0.2), depth - 1 )
    rand=random.random;
    DrawTree( endX, endY, angle - 30 * rand(), length * (rand() + 0.2), depth - 1 )
#----------------------------------------------------------
# main
if __name__ == "__main__": 
    root = Tk()
    scrollbarX = Scrollbar( root, orient = "horizontal" )
    scrollbarY = Scrollbar( root)
  
    myCanvas = Canvas(root, xscrollcommand = scrollbarX.set,  yscrollcommand = scrollbarY.set, confine = 0, scrollregion = (0, 0, 480, 640 ))
   
    scrollbarX.config (command=myCanvas.xview)
    scrollbarY.config (command=myCanvas.yview)
   
    scrollbarX.pack (side=BOTTOM, fill=X)
    scrollbarY.pack (side=RIGHT, fill=Y)
   
    root.configure(width=640, height=640)
    DrawTree(240, 320, 90, 40, 12)
    myCanvas.pack()
    root.mainloop()

'Coding > Python 삽질기' 카테고리의 다른 글

간단한 메모장  (0) 2008.09.14
파일을 HEX 값으로 보여 주는 소스  (0) 2008.05.19
Post it 만들기  (0) 2008.03.04
Posted by chobocho
Coding/Python 삽질기2008. 5. 19. 00:42
#-*- coding: cp949 -*-
# @Author : chobocho
# @Title  : Simple Hex viewer
# @Date   : 2008. 5. 18
import sys
def main(source_file):
   
    source = open(source_file, 'rb')
    source_data = source.read()
    source.close()
   
    char_count = 0
    buffer = ""
   
    for ch in source_data:
        if (char_count % 16 == 0):
            print "|  %s\n%05X " % (buffer, char_count),
            buffer = ""
        if (char_count % 4 == 0):
            print " ",
        print "%02X" % int( ord(ch) ),
       
        if (ch == '\r'):
            buffer += ""
        elif (ch == '\n'):
            buffer += '\\n'
        elif (ch == '\t'):
            buffer += '\\t'
        else :
            buffer += ch
       
        char_count += 1
       
  
   
#-------------------------------------------------------------------------------
# main
if __name__ == "__main__": 
    if len(sys.argv) < 2:
        print "Usage : hex target"
    else:
        main(sys.argv[1])

'Coding > Python 삽질기' 카테고리의 다른 글

Fractal Tree  (0) 2008.06.21
Post it 만들기  (0) 2008.03.04
Python으로 만든 file copy 예제  (2) 2007.11.20
Posted by chobocho
Coding/리눅스 삽질기2008. 5. 13. 01:06
사용자 삽입 이미지

'Coding > 리눅스 삽질기' 카테고리의 다른 글

[Linux] DSL 설치  (0) 2009.11.04
SIGBUS  (0) 2005.09.21
Mplayer Porting  (3) 2005.06.03
Posted by chobocho
Coding/CPP 삽질기2008. 3. 8. 00:43

정파 계열의 무공은 느리지만 초절정에 이를 수 있다는 장점이 있고,
마공 계열의 무공은 속성으로 익힐 수 있지만 초절정에 이를 수 있다는 단점이 있음을 많은 이들이 알고 있다. 하지만 이런 마공의 무서움에도 많은 이들이 애용하는 신공이 있으니 바로
Copy & Paste 신공이다. 배우지 않아도 자연히 알 수 있으며, 한 번 사용하면 끊을 수 없는 무서운 신공이다.
이미 초절정에 이른 많은 선배 고수들의 비급 부터 시작해서, 입문서에 반드시 나오는 절대 쓰면 안되는 신공으로 분류 되고 있으나, 속성이라는 그 달콤한 유혹은 누구나 떨칠 수 없어, 많은 강호인들이 애용하는 신공이다. 속성의 장점이 있으나 마공으로 분류되는 이유는 치명적 버그의 발생 가능성이 크기 때문이다. 단순 반복적인 초식의 반복으로 변이 강조되어야 하는 초식에 함부로 사용할 경우, 컴파일 오류라는 단순 외상으로 시작해서, 주화입마에 빠져 버릴 가능성이 높은 무서운  신공이다. 이런 단점에도 불구하고 시간이 금인 시기에 속성이라는 유혹은 떨쳐버리기 어려워, 지금도 수많은 이들이 이 시간에도 사용하는 신공이다.

'Coding > CPP 삽질기' 카테고리의 다른 글

[CPP] STL에서 List의 sorting 방법  (0) 2008.10.30
연산자 우선 순위  (0) 2008.01.13
심심풀이 프로그래밍...2  (0) 2007.09.17
Posted by chobocho
Coding/Python 삽질기2008. 3. 4. 02:15

[2008. 3. 3]

from Tkinter import *

root = Tk()
text = Text(root, width=20, height=20)
text.pack()

root.mainloop()

Posted by chobocho
Coding/CPP 삽질기2008. 1. 13. 01:33

#include <stdio.h>

int
main(void)
{
    int a = 0;
    int b = 0;
    int c = 0;

    a++ || b++ && c ++ ;
    printf ("a = %d, b = %d, c = %d\n", a, b, c);

    return 0;
}

위 코드를  실행하면 아래와 같이 나온다.
a = 1, b = 1, c = 0

위 와 같은 결과가 나오는 것은 C의 연산자 우선 순위 때문이다.
C 에서는 && 가 || 보다 우선 순위가 높다. 그래서 위의
a++ || b++ && c++ 은 a++ || ( b++ && c++) 와 동일한 문장이다.
Short Circuit에 의해서 먼저 a++이 연산이 되는데,
1) a++이 판단되는데, a = 0 이므로 거짓이 되고, a++ 이 수행되므로  a = 1 이된다.
2) 앞 구문이 거짓이므로 b++ && c++ 가 수행되는데, b = 0 이므로 && 조건에 의해
c++은 수행되지 않는다. 단, b++에 의해서 b = 1 이된다.
그래서 a++ 과 b++만 수행되고, c++은 수행 되지 않으므로
a = 1, b = 1, c = 0 이 된다.

어셈블러로 구현된 코드를 살펴보면 아래와 같다.

    int a = 0;
0040101E  mov         dword ptr [a],0
    int b = 0;
00401025  mov         dword ptr [b],0
    int c = 0;
0040102C  mov         dword ptr [c],0

    a++ || b++ && c ++ ;
00401033  mov         eax,dword ptr [a]
00401036  mov         ecx,dword ptr [a]
00401039  add         ecx,1
0040103C  mov         dword ptr [a],ecx
0040103F  test        eax,eax
00401041  jne         main+5Ch (40105Ch)
00401043  mov         edx,dword ptr [b]
00401046  mov         eax,dword ptr [b]
00401049  add         eax,1
0040104C  mov         dword ptr [b],eax
0040104F  test        edx,edx
00401051  je          main+5Ch (40105Ch)
00401053  mov         edx,dword ptr [c]
00401056  add         edx,1
00401059  mov         dword ptr [c],edx

'Coding > CPP 삽질기' 카테고리의 다른 글

Copy & Paste 신공  (0) 2008.03.08
심심풀이 프로그래밍...2  (0) 2007.09.17
비트 연산자  (0) 2007.04.24
Posted by chobocho
Coding/Python 삽질기2007. 11. 20. 23:34
급하게 파일을 합쳐하 하는 일이 생겨서 만든 파이썬 스크립트이다.
 
기능은 단지 여러개의  파일을 하나로 붙여준는 것 말고는 없다.

#-*- coding: cp949 -*-
# ACopy
# filename : acopy.py
# author    : chobocho at korea.com
# date        : 2007. 11. 20
#
# 여러개의 파일을 붙여 주는 프로그램
import sys
def main(files):
    file_number = len(files)
    target_file = files[1];
        
    target = file(target_file, 'wb')
 
    for idx in range (2, file_number):
        source = file(files[idx], 'rb')
        source_data = source.read()
        source.close()
        target.write(source_data)
    target.close()
   
#-------------------------------------------------------------------------------
# main
if __name__ == "__main__": 
    if len(sys.argv) < 3:
        print "Usage : acopy target source1 [source2]*"
    else:
        main(sys.argv)


'Coding > Python 삽질기' 카테고리의 다른 글

Post it 만들기  (0) 2008.03.04
http://www.pythonchallenge.com...Level1  (1) 2007.09.29
http://www.pythonchallenge.com  (0) 2007.09.28
Posted by chobocho
Coding/Python 삽질기2007. 9. 29. 11:59
http://www.pythonchallenge.com Level 1을 풀었다. 풀고나서 보니 maketrans라는 아주 좋은 함수가 있다는 사실을 알았다. 나는 너무 프로그램을 무식하게 짜는 것 같다.
역시 잘모르니 손발이 고생한다.

#!/usr/local/bin/python
#-*- coding: cp949 -*-
#http://www.pythonchallenge.com
#text =  "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."

alpha = {'a':'c', 'b':'d', 'c':'e', 'd':'f', 'e':'g', 'f':'h', 'g':'i', 'h':'j', 'i':'k', 'j':'l', 'k':'m', 'l':'n', 'm':'o', 'n':'p', 'o':'q', 'p':'r', 'q':'s', 'r':'t', 's':'u', 't':'v', 'u':'w', 'v':'x', 'w':'y', 'x':'z', 'y':'a', 'z':'b'}
count = 0
result_text = ""
for ch in text:
   print ch
   if ch >= 'a' and ch <='z':
       result_text = result_text + alpha.get(ch)
   else:
       result_text = result_text + ch
   count = count + 1
print result_text

'Coding > Python 삽질기' 카테고리의 다른 글

Python으로 만든 file copy 예제  (2) 2007.11.20
http://www.pythonchallenge.com  (0) 2007.09.28
피보나치 수열 문제  (0) 2007.09.16
Posted by chobocho