Skip to content

Instantly share code, notes, and snippets.

function demo(num){
if(num<=1){
return 1;
}
return num*demo(num-1);
}
alert(demo(5)) //stdout:120
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import threading
import time
class Mythreading(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
#self.daemon=True
@davidbj
davidbj / python yield demo
Created September 4, 2014 10:32
python yield demo
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#Function: python yield demo
Queue=[1, 2, 3, 4, 5, 6]
def foo(regex):
print "start..."
while True:
I. open a tar file
import tarfile
import glob
t = tarfile.open("foo.tar", 'w')
t.add("README")
for pyfile in glob.glob('*.py'):
t.add(pyfile)
t.close()
II.
I.Example of how to read a compressed file:
import gzip
f = gzip.open('file.tar.gz', 'rb')
file_content = f.read()
f.close()
II.Example of how to create a compressed GZIP file:
import gzip
I.pickle exmaple
"""object save to file."""
import pickle
obj = Someobject()
f = open(filename, 'wb')
pickle.dump(obj, f)
f.close()
1.rpm install puppetlabs-release
rpm -ivh http://yum.puppetlabs.com/el/6.4/products/i386/puppetlabs-release-6-6.noarch.rpm
sudo yum clean all
2.Install puppet-server and puppet-agent
sudo yum install puppet-server puppet
1. yum install inxi for Centos
yum install inxi
2.View help information
inxi --help
I. change yum source
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
II. yum install nginx
yum install nginx -y
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os
impost sys
def walk(path):
isdir, isfile, join = os.paht.isdir, os.path.isfile, os.path.join
lsdir = os.listdir(path)
dirs = [i for i in lsdir if isdir(join(path, i))]