This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 []] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_parentheses_balanced(expression): | |
stack = [] | |
for symbol in expression: | |
if symbol == '(': | |
stack.append(symbol) | |
if symbol == ')': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
class Node(object): | |
def __init__(self, value, next=None): | |
self.value = value | |
self.next = next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import array | |
def reverse_array(letters, start, end): | |
while start < end: |
OlderNewer