Coding/Perl 삽질기2010. 2. 25. 01:23
IP주소 검색 : 
((([01]?[0-9][0-9]?)|(2([0-4][0-9]|5[0-5])))\.){3}(([01]?[0-9][0-9]?)|(2([0-4][0-9]|5[0-5])))

시간찾기 :
\d{2}:\d{2}:\d{2}
Posted by chobocho
Coding/Perl 삽질기2010. 2. 10. 01:44
#
# Date : 2010. 2. 10
#
###############################################
# Folder Name

$DIR_NAME = ".";
###############################################

@expressions = ( "Hello", "world" );

opendir (DIR, $DIR_NAME) || die "Can't open folder";
@FILE_LIST = readdir DIR; 
closedir (DIR);


foreach $filename(@FILE_LIST)
{
    if (-f $filename) 
    {
        print $filename."\n";
    
        open (IN_FILE, "<".$filename) || die $!;
         
        while (my $line = <IN_FILE>) 
        {
            foreach $expression(@expressions)
            {
                if ( $line =~ /$expression/ )
                {
                    print $line;
                }
            }
        }

        close (IN_FILE);
    } 
}

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

자주 쓰는 정규 표현식  (0) 2010.02.25
[Perl] Hex2Ascii  (0) 2009.06.16
Perl 공부 다시 시작하다.  (0) 2006.10.07
Posted by chobocho
Coding/Python 삽질기2010. 2. 2. 01:23

#-*- coding: cp949 -*-
# Name        : py_email.py
# Author      : chobocho.com
# Version     :
# Copyright   :
# Description : Simple template maker
#

from Tkinter import *
import tkMessageBox
import os.path
import glob 
import re
 
class App:
    def __init__ (self, master):
        frame = Frame(master)
        frame.pack()
       
        # Text Area
        f0 = Frame(frame, width = 100, height = 100)
        f0.grid(row = 0, column = 0)
        self.text_scrollbar = Scrollbar (f0, orient=VERTICAL)
        self.text = Text(f0, width=80, height = 20, yscrollcommand=self.text_scrollbar.set)
        self.text_scrollbar.config(command=self.text.yview)
        self.text_scrollbar.pack(side=RIGHT, fill=Y)
        self.text.pack() 
       
        # List Box area
        f1 = Frame(frame, width = 100, height = 100)
        f1.grid(row = 0, column = 1)
       
        self.list_label = Label(f1, text="Template")
        self.list_label.pack()
       
        self.listbox_scrollbar = Scrollbar (f1, orient=VERTICAL)
        self.listbox = Listbox(f1, height=19, yscrollcommand=self.listbox_scrollbar.set)
        self.listbox_scrollbar.config(command=self.listbox.yview)
        self.listbox_scrollbar.pack(side=RIGHT, fill=Y)
        # 파일에서 템플릿을 읽어서 보여 줄 것
        self.ReadTemplate()
        self.listbox.bind("<Double-Button-1>", self.LoadFile)
        self.listbox.pack(side=RIGHT)
       
        # 보내는 사람과 받는 사람을 저장하는 부분
        f3 = Frame(frame, width = 100, height = 40)
        f3.grid(row = 1, column = 0)
       
        self.label_From = Label(f3, text="From")
        self.label_From.grid(row = 0, column = 0, sticky = W)
        self.label_To = Label(f3, text="To")
        self.label_To.grid(row = 1, column = 0, sticky = W)
        self.input_from = Entry(f3)
        self.input_from.grid(row = 0, column = 1)
        self.input_to = Entry(f3)
        self.input_to.grid(row = 1, column = 1)

        # 버튼을 그려주는 부분
        f4 = Frame(frame, width = 100, height = 40)
        f4.grid(row = 1, column = 1)
       
        #self.load_button = Button(f4, text="Load", command = self.LoadFile)
        #self.load_button.grid(row = 0, column = 0)
        self.clear_button = Button(f4, text="Clear", command = self.ClearText)
        self.clear_button.grid(row = 0, column = 0)
        self.info_button = Button(f4, text="Info", command = self.ShowInfo)
        self.info_button.grid(row = 0, column = 1)


    def ClearText(self):
        self.text.delete(1.0, END) 
   
    def ShowInfo(self):
        tkMessageBox.showinfo("Information","http://chobocho.com\nVersion 0.2")
   
    def GetFromTo(self):
        self.sender = self.input_from.get()
        self.receiver = self.input_to.get()

    def ReadTemplate(self):
        all_flist = glob.glob ("*.txt")
       
        for f in all_flist:
            if os.path.exists(f):
                self.listbox.insert(END, f.decode('cp949'))
               
    def LoadFile(self, event):
        self.items = self.listbox.curselection()
        self.el = self.listbox.get(self.items)
       
        self.GetFromTo()
        self.ClearText()
        if os.path.exists(self.el):
            self.fp = open(self.el, 'r')
            self.tempFileData = self.fp.read()
            self.fp.close()
            self.text_data_1 = re.sub('\$SENDER_NAME_' , self.sender , self.tempFileData)
            self.text_data   = re.sub('\$RECEIVER_NAME_' , self.receiver , self.text_data_1)
            self.text.insert(1.0, self.text_data.decode('cp949'))
#----------------------------------------------------------
# main
if __name__ == "__main__":     
    root = Tk()
    app = App(root)
    root.mainloop()


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

Quick Sort  (0) 2010.06.10
[Python] 짧은 코드 모음  (0) 2010.01.22
[Python] 초간단 Lotto 생성기 소스  (0) 2010.01.22
Posted by chobocho
Coding/CPP 삽질기2010. 1. 28. 00:18

//============================================================================
// Name        : ChoboSplit.cpp
// Author      : chobocho.com
// Version     : v0.011
// CopyLeft
// Description : File Split
// Date        : 2010. 10. 28
//============================================================================

#include <iostream>
#include <fstream>
using namespace std;

#define _10MB (10*1024*1024)

class CSplit {
public:
    CSplit();
    ~CSplit();
    bool split(char *fileName);
    void make_batch_file (char *fileName, int count);
private:
    fstream source_fp;
    fstream target_fp;
};

CSplit::CSplit()
{

}

CSplit::~CSplit()
{
    source_fp.close();
    target_fp.close();
}


bool CSplit::split(char *fileName)
{
    int nof_target = 0;
    int count = 0;
    int read_size = 8192;
    char buffer[8192];

    string target_filename = fileName;
    target_filename += ".sh";

    source_fp.open(fileName, ios::binary|ios::in);
    target_fp.open(target_filename.c_str(), ios::binary|ios::out|ios::trunc);
    if (!source_fp)
    {
       cout << "Error : Can't find " << fileName << " !!" << endl;
       return false;
    }

    source_fp.seekg(0, ios_base::end);
    long source_filesize = source_fp.tellg();

    cout << "source file size : " << source_filesize << endl;

     // 10MB 이하의 파일은 분할 할 필요가 없음
    if ( source_filesize <= _10MB )
    {
         cout << "No need to split!" << endl;
         source_fp.close();
         return false;
     }

     source_fp.seekg(ios_base::beg);

     if (!target_fp)
    {
        cout << "Error : Can't open target file !!" << endl;
        return false;
    }

    while(( !source_fp.eof() )&& (source_filesize > 0) )
    {
        memset(buffer, 0, 8192);

        if (source_filesize < read_size)
        {
            read_size = source_filesize;
         }

         source_fp.read( buffer, read_size );
         target_fp.write( buffer, read_size );
         count += read_size;
         source_filesize -= read_size;

        if (count >= _10MB)
        {
            count = 0;
            target_fp.close();
            cout << "Make " << nof_target+1 << " file!" <<endl;
            char next_target_filename[256];
            sprintf( next_target_filename, "%s.s%d", fileName, nof_target++ );
            target_fp.open(next_target_filename, ios::binary|ios::out|ios::trunc);
            if (!target_fp)
            {
                source_fp.close();
                cout << "Error : Can't open target file !!" << endl;
                return false;
             }
        }
    }

    source_fp.close();
    target_fp.close();

    make_batch_file (fileName, nof_target);

    return true;
}

void CSplit::make_batch_file (char *fileName, int count)
{
    int i = 0;

    ofstream target("run.bat", ios::out);
    target << "echo off" << endl;

    target << "if not exist "<< fileName <<".sh goto error" << endl;
    for (i = 0; i < count ; i++)
    {
         target << "if not exist " << fileName << ".s" << i << " goto error" << i << endl;
    }

    target << "copy /b "<< fileName <<".sh";
    for (i = 0; i < count ; i++)
    {
     target << " + " << fileName << ".s" << i;
    }
    target << " " << fileName << endl;
    target << "goto finish" << endl;

    target << ":error" << endl;
    target << "echo Error : " << fileName << ".sh not exist" << endl;
    target << "goto finish" << endl;

    for (i = 0; i < count; i++)
    {
        target << ":error" << i << endl;
        target << "echo Error : " << fileName <<".s" << i << " not exist" << endl;
        target << "goto finish" << endl;
    }
    target << ":finish" << endl;
    target << "echo Finish" <<endl;
    target.close();
}

int main(int argc, char **argv) {
    cout << "!!!Chobo Spilt V0.011!!!" << endl;

    CSplit mySplit;

    if (argc >= 2)
   {
       mySplit.split(argv[1]);
    }
    cout << "!!!End!!!" <<endl;
    return 0;
}



실행결과

생성파일 : Run.bat + 분할된 파일들

Run.bat 의 내용
echo off
if not exist test.zip.sh goto error
if not exist test.zip.s0 goto error0
if not exist test.zip.s1 goto error1
if not exist test.zip.s2 goto error2
if not exist test.zip.s3 goto error3
if not exist test.zip.s4 goto error4
copy /b test.zip.sh + test.zip.s0 + test.zip.s1 + test.zip.s2 + test.zip.s3 + test.zip.s4 test.zip
goto finish
:error
echo Error : test.zip.sh not exist
goto finish
:error0
echo Error : test.zip.s0 not exist
goto finish
:error1
echo Error : test.zip.s1 not exist
goto finish
:error2
echo Error : test.zip.s2 not exist
goto finish
:error3
echo Error : test.zip.s3 not exist
goto finish
:error4
echo Error : test.zip.s4 not exist
goto finish
:finish
echo Finish



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

간단한(?) 퀴즈  (2) 2011.02.06
[CPP] Lotto 생성기  (0) 2010.01.22
[CPP] 폴더내 파일 목록을 보여 주는 코드 조각  (1) 2009.03.24
Posted by chobocho
Coding/CPP 삽질기2010. 1. 22. 23:58

/*
 ============================================================================
 Name        : Lotto.c
 Author      : chobocho
 Version     :
 Copyleft
 Description : Lotto
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void lotto(int num, int max_number);

void lotto(int num, int max_number)
{
    int number[100] = {0, };
    int i = 0;
    int prev = 0;
    int next = 0;
    int temp = 0;

    if (num > max_number || max_number < 0 || max_number >= 100)
    {
        return;
     }

    for (i = 0; i < max_number; i++)
    {
        number[i] = i+1;
     }

    srand((time(NULL)));

    for (i = 0; i < 1000; i++)
    {
        prev = rand() % max_number;
        next = rand() % max_number;

        temp = number[prev];
        number[prev] = number[next];
        number[next] = temp;
    }

    for (i = 0; i < num; i++)
    {
         printf ("%d ", number[i]);
     }
     puts("\n");

}

int main(int argc, char **argv) {
    lotto(6, 46);
    return 0;
}

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

[CPP] 파일 분할 프로그램 v0.01  (0) 2010.01.28
[CPP] 폴더내 파일 목록을 보여 주는 코드 조각  (1) 2009.03.24
함수 포인터  (0) 2009.01.08
Posted by chobocho
Coding/Python 삽질기2010. 1. 22. 01:10
# 리스트에서 음수 제거 하기
def remove_neg(num_list):
    num_list[:] = filter(lambda x: x > 0, num_list)
#-----------------------------------------------------------------------------------

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

[Python] Simple template maker  (0) 2010.02.02
[Python] 초간단 Lotto 생성기 소스  (0) 2010.01.22
[Python] Simple file viewer  (0) 2010.01.02
Posted by chobocho
Coding/Python 삽질기2010. 1. 22. 00:41
import random

lotto_set = ()
while ( len(lotto_set) < 6 ):
    lotto_set = set([random.randrange(1, 47, 1) for k in range(6)])
    
lotto = list(lotto_set)
lotto.sort()

print lotto

[2, 26, 33, 36, 39, 46]

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

[Python] 짧은 코드 모음  (0) 2010.01.22
[Python] Simple file viewer  (0) 2010.01.02
[Python] 회전 이동  (0) 2009.08.25
Posted by chobocho
Coding/Python 삽질기2010. 1. 2. 00:47

#-*- coding: cp949 -*-
# Name        : py_fileview.py
# Author      : chobocho.com
# Version     :
# Copyright   :
# Description : Simple text file viewer
#

from Tkinter import *
import tkMessageBox
import os.path
import glob 
 
class App:
    def __init__ (self, master):
        frame = Frame(master)
        frame.pack()
       
        # Text Area
        f0 = Frame(frame, width = 100, height = 100)
        f0.grid(row = 0, column = 0)
        self.text_scrollbar = Scrollbar (f0, orient=VERTICAL)
        self.text = Text(f0, width=80, height = 20, yscrollcommand=self.text_scrollbar.set)
        self.text_scrollbar.config(command=self.text.yview)
        self.text_scrollbar.pack(side=RIGHT, fill=Y)
        self.text.pack() 
       
        # List Box area
        f1 = Frame(frame, width = 100, height = 100)
        f1.grid(row = 0, column = 1)
       
        self.list_button = Button(f1, text="File List", command=self.ShowInfo)
        self.list_button.pack()
       
        self.listbox_scrollbar = Scrollbar (f1, orient=VERTICAL)
        self.listbox = Listbox(f1, height=19, yscrollcommand=self.listbox_scrollbar.set)
        self.listbox_scrollbar.config(command=self.listbox.yview)
        self.listbox_scrollbar.pack(side=RIGHT, fill=Y)
        # 파일 내용을 읽어서 보여 줄 것
        self.ReadTemplate()
        self.listbox.bind("<Double-Button-1>", self.LoadFile)
        self.listbox.pack(side=RIGHT)

    def ClearText(self):
        self.text.delete(1.0, END) 
   
    def ShowInfo(self):
        tkMessageBox.showinfo("Information","http://chobocho.com\nVersion 0.2")
   
    def ReadTemplate(self):
        all_flist = glob.glob ("*.txt")
       
        for f in all_flist:
            if os.path.exists(f):
                self.listbox.insert(END, f.decode('cp949'))
               
    def LoadFile(self, event):
        self.items = self.listbox.curselection()
        self.el = self.listbox.get(self.items)
        self.ClearText()
        if os.path.exists(self.el):
            self.fp = open(self.el, 'r')
            self.tempFileData = self.fp.read()
            self.fp.close()
            self.text.insert(1.0, self.tempFileData.decode('cp949'))

#----------------------------------------------------------
# main
if __name__ == "__main__":     
    root = Tk()
    app = App(root)
    root.mainloop()



실행화면

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

[Python] 초간단 Lotto 생성기 소스  (0) 2010.01.22
[Python] 회전 이동  (0) 2009.08.25
WxPython - HelloWorld  (0) 2008.12.22
Posted by chobocho
Coding/Haskell2009. 11. 12. 00:35
quicksort []       =  []
quicksort (x:xs)  = quicksort[y | y <- xs, y < x] ++ [x] ++ quicksort[y | y <- xs, y >= x]

Posted by chobocho
Coding/리눅스 삽질기2009. 11. 4. 01:20

용량 50M의 저용량 리눅스 Damn Small Linux를 Virtual Box로 부팅.

가볍 다는 이유로 설치 했는데, 한글이 지원 안되는걸 깜박했다. ^^;

홈페이지 : http://damnsmalllinux.org/

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

Virtual Box를 이용한 Ubuntu 설치  (0) 2008.05.13
SIGBUS  (0) 2005.09.21
Mplayer Porting  (3) 2005.06.03
Posted by chobocho