http://formatmysourcecode.blogspot.tw/


JerryCheng 發表在 痞客邦 留言(0) 人氣()

Reference

  • Introduction to datetime object

http://www.seehuhn.de/pages/pdate

JerryCheng 發表在 痞客邦 留言(0) 人氣()

Return Value of threads

# -*- coding: UTF-8 -*-
def foo(bar, result, index):
    print 'hello {0}'.format(bar)
    result[index] = "foo"

from threading import Thread

threads = [None] * 10
results = [None] * 10

for i in range(len(threads)):
    threads[i] = Thread(target=foo, args=('world!', results, i))
    threads[i].start()

# do some other stuff

for i in range(len(threads)):
    threads[i].join()

print " ".join(results)  # what sound does a metasyntactic locomotive make?

Basic example:

JerryCheng 發表在 痞客邦 留言(0) 人氣()

Reference

  • [1]static method in javascript
  • http://stackoverflow.com/questions/1535631/static-variables-in-javascript
  • [2]Public / Private variable and method 
  • http://phrogz.net/JS/classes/OOPinJS.html

 

JerryCheng 發表在 痞客邦 留言(0) 人氣()

#!/bin/bash

count=0
while [ true ]
do
        count=$(( $count+1 ))
        echo $count
        if [ $count -eq 10 ];then
                break
        fi
        sleep 1
done


JerryCheng 發表在 痞客邦 留言(0) 人氣()

#!/opt/csw/bin/expect

set timeout 20

spawn sftp root@host

expect "*password*"
send "ej03xu35k3au4a83\r"
expect "*sftp*"
send "cd /usr/bin/\r"
expect "*sftp*"
send "put rsync\r"
expect "*sftp*"
send "exit\r"
interact


JerryCheng 發表在 痞客邦 留言(0) 人氣()

< >


JerryCheng 發表在 痞客邦 留言(0) 人氣()

ref :http://blog.longwin.com.tw/2006/07/color_ls_in_bash_2006/

  Display : ls --color

JerryCheng 發表在 痞客邦 留言(0) 人氣()

class base:
        def __init__(self, name):
                self.name = name

        def show(self):
                print "Base Class is here!!"

        def show_name(self):
                print "name:", self.name

        def process(self):
                self.show_name()
                self.show()

class sub(base):
        def show(self):   // override show method
                print "Sub class is here!!"

base_class = base("Base Class")
base_class.process()

sub_class = sub("Sub Class")
sub_class.process()


JerryCheng 發表在 痞客邦 留言(0) 人氣()

d = {1: 2, 3: 4, 4:3, 2:1, 0:0}
sorted(d.items(), key=lambda x: x[1])

JerryCheng 發表在 痞客邦 留言(0) 人氣()

            idList = [];
            $('.jobs').each(function(){
                if($(this).attr("checked"))
                {
                    idList.push($(this).attr('jobid'));
                }
            });

JerryCheng 發表在 痞客邦 留言(0) 人氣()

# -*- coding: UTF-8 -*-


import time
import threading


def myfunc(i):
        time.sleep(5)
        print "finished sleeping from thread %d"%(i)


def main():
        for i in range(10):
                t = threading.Thread(target = myfunc , args=(i,))
                time.sleep(1)
                t.start()
                print t.name


if __name__ == '__main__':
        main()


JerryCheng 發表在 痞客邦 留言(0) 人氣()

import time
import datetime

def interval_secs(time_start , time_end):
        diff = time_end - time_start
        return diff.seconds + diff.days * 24 * 60 * 60

time_start = datetime.datetime.now().strftime("%y-%m-%d-%H-%M-%S")
time_start = datetime.datetime.strptime(time_start , "%y-%m-%d-%H-%M-%S")
print time_start
time.sleep(3)
time_end = datetime.datetime.now()
print interval_secs(time_start , time_end)

JerryCheng 發表在 痞客邦 留言(0) 人氣()

int hcf(int a , int h)
{
        int temp;
        while(1)
        {
                temp = a % h;
                if(temp == 0)
                {
                        return h;
                }
                a = h;
                h = temp;
        }
}

int relativePrimes(int* num , int n)
{
        int count = 0;
        for(int i = 0 ; i < n ; i++)
        {
                for(int j = i + 1 ; j < n ; j++)
                {
                     int a = *(num + i);
                     int b = *(num + j);
                     int gcd = hcf(a , b);
                     if(gcd == 1)
                     {
                        count++;
                     }   
                }
        }
        return count;
}

JerryCheng 發表在 痞客邦 留言(0) 人氣()

int hcf(int a , int h)
{
        int temp;
        while(1)
        {
                temp = a % h;
                if(temp == 0)
                {
                        return h;
                }
                a = h;
                h = temp;
        }
}

JerryCheng 發表在 痞客邦 留言(0) 人氣()

int combination_pascal(int n , int r)
{
        if(r == 0 || n == r)
        {
                return 1;
        }
        return combination_pascal(n - 1 , r) + combination_pascal(n - 1 , r - 1); 
}

JerryCheng 發表在 痞客邦 留言(0) 人氣()

int factor(int n)
{
        int ret = 1;
        for(int i = 2 ; i <= n ; i++ )
        {
                ret = ret * i;
        }
        return ret;
}

int combination(int n , int r)
{
        int ret = factor(n) / (factor(r) * factor(n-r));
        return ret;
}

文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣()

int* numArray(int n)
{
        int* num = (int*)malloc(n * sizeof(int));
        
        for(int i = 0 ; i < n ; i++)
        {
                scanf("%d\n" , num + i);
        }

        return num;
}

文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣()

  • Mar 29 Sat 2014 17:32
  • factor

int factor(int n)
{
        int ret = 1;
        for(int i = 2 ; i <= n ; i++ )
        {
                ret = ret * i;
        }
        return ret;
}

文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣()

ref : http://stackoverflow.com/questions/2693776/removing-trailing-newline-character-from-fgets-input


文章標籤

JerryCheng 發表在 痞客邦 留言(0) 人氣()