Skip to content

Instantly share code, notes, and snippets.

@8maki
8maki / convert_datetime_from_str.py
Created September 14, 2011 11:15
convert_datetime_from_str by python
import datetime
import time
def convert_datetime_from_str(str):
return datetime.datetime.fromtimestamp(
time.mktime(
time.strptime(
str,"%Y-%m-%d %H:%M:%S")))
@8maki
8maki / convert_obj_to_json.py
Created September 18, 2011 07:45
object to json including datetime.datetime
dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else None
json.dumps(data, default=dthandler)
@8maki
8maki / sort_dict_by_value.py
Created October 4, 2011 11:52
sort_dict_by_value
for k, v in sorted(d.items(), key=lambda x:x[1]):
print k, v
@8maki
8maki / convert_datetime_to_unixtime.py
Created October 5, 2011 10:06
convert_datetime_to_unixtime
def convert_datetime_to_unixtime(d)
time.mktime(d.timetuple())
re.sub(u'([ぁ-ゞァ-ヾ一-龠0−9!?]+)', lambda m: urllib2.quote(m.group(0).encode('utf8')), k)
@8maki
8maki / sort_list.py
Created November 8, 2011 02:32
sort_list
list.sort( cmp=lambda x, y: cmp(x, y), reverse=True )
@8maki
8maki / sort_list_by_value.py
Created November 21, 2011 02:29
sort_list_by_value
list.sort(cmp=lambda x,y: cmp(int(x), int(y)))
@8maki
8maki / sort_dirlist_by_ctime.py
Created November 21, 2011 02:31
sort_dirlist_by_ctime
dir_names.sort(cmp=lambda x,y: cmp(os.path.getctime('%s/%s' % (base_dir, x)), os.path.getctime('%s/%s' % (base_dir, y)))
@8maki
8maki / is_dict.py
Created December 31, 2011 16:50
is_dict
aaa = {}
isinstance(aaa, dict)
@8maki
8maki / isNumber.js
Created February 27, 2012 11:08
isNumber
function isNumber(str) {
return !isNaN(+str)
}