Skip to content

Instantly share code, notes, and snippets.

View bluven's full-sized avatar

Jianbo Yan bluven

  • BoCloud
  • Beijing
  • 13:50 (UTC +08:00)
View GitHub Profile
@bluven
bluven / sec_looper.py
Created March 28, 2012 09:03
在给定的时间里计数
#!/usr/bin/python
# coding:utf-8
from time import time
def loop_in_sec(duration = 1):
start = time()
count = 1
while (time() - start) < duration:
yield count
@bluven
bluven / attr.py
Created May 9, 2012 03:40
getter setter
def attr(name):
n = '__' + name
def fget(self):
print 'get'
return self.__dict__[n]
def fset(self, x):
print 'set'
self.__dict__[n] = x
tmp = locals()
@bluven
bluven / .bashrc
Created August 30, 2013 08:33 — forked from samuelleach/.bashrc
# From http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
export MARKPATH=$HOME/.marks
function jump {
cd -P $MARKPATH/$1 2> /dev/null || echo "No such mark: $1"
}
function mark {
mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1
}
function unmark {
rm -i $MARKPATH/$1
@bluven
bluven / xml2obj.py
Created December 23, 2013 09:25
简化项目中协议的描述,解析与生成
import base64
import xml.etree.ElementTree as ET
BEGIN_TAG = 'CM'
PARAMETER_TAG = 'Parameter'
ENCODED_TAGS = ['DataType', 'FileName', 'ContentName', 'Revision', 'Title']
def encode(value):
return base64.encodestring(value.encode('utf-8'))
@bluven
bluven / sum-even-fib.clj
Created May 4, 2014 14:02
计算某数值以下的偶数fib和
(def fib-seq
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))
(def even-fib-seq (filter even? fib-seq))
(defn sum-fib [limit]
(loop [i 1
fib-num (nth even-fib-seq i)
seqn []]
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import re
ntfs_pattern = re.compile(r'File System Personality: NTFS')
ntfs_device_node = re.compile(r'.*Device Node:.*')
device_dict = {}
@bluven
bluven / camel_to_snake
Last active August 29, 2015 14:05
turn camel case into snake case
def camel_to_snake(name):
# for example: _getHTTPResponseCodeTest123Lab
# after first sub, name is _getHTTP_ResponseCodeTest123Lab
name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
# after second sub, name is _get_http_response_code_test123_lab
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()
@bluven
bluven / validate_parentheses
Created September 1, 2014 12:28
check if a string is parentheses balanced
def is_parentheses_balanced(expression):
stack = []
for symbol in expression:
if symbol == '(':
stack.append(symbol)
if symbol == ')':
@bluven
bluven / reverse_singly_linklist.py
Created September 1, 2014 13:12
reveerse singly linked list
@bluven
bluven / reverse_sentence.py
Last active August 29, 2015 14:05
reverse sentence
#!/usr/bin/env python
# encoding: utf-8
import array
def reverse_array(letters, start, end):
while start < end: