Skip to content

Instantly share code, notes, and snippets.

View tkmru's full-sized avatar
💭
🍣 💰 🍖 🍶

@tkmru tkmru

💭
🍣 💰 🍖 🍶
View GitHub Profile
@tkmru
tkmru / listsWithZip.py
Last active August 29, 2015 13:55
This extract element from lists with zip() at the same time.
list_a = ['foo', 'bar']
list_b = ['hoge', 'fuga']
list_c = [123, 456]
for tuple in zip(list_a, list_b, list_c):
print '%s - %s / %s'% tuple
>> foo - hoge / 123
bar - fuga / 456
@tkmru
tkmru / current_time.js
Created February 6, 2014 01:00
This code get current time.
function current_time() {
var d = new Date();
var month = d.getMonth() + 1;
var day = d.getDate();
var hour = d.getHours();
var minute = d.getMinutes();
var second = d.getSeconds();
var w = ["日","月","火","水","木","金","土"];
//convert to a two-digits number
@tkmru
tkmru / arrayDiff.js
Created March 3, 2014 05:25
This code get difference of the two array.It use "indexOf" and "filter".http://e10s.hateblo.jp/entry/20070526/1180173036
function arrayDiff(older, newer) { // filter only addition
function callback_filter(element, index, array) {
return (this.indexOf(element) == -1); // element not included is true
}
return newer.filter(callback_filter, older);
}
[1,2,3].toString();
>> "1,2,3"
JSON.stringify([1,2,3]);
>> "[1,2,3]"
import os
import time
os.utime(filename, None) # set current time
access_time = fix_time = time.mktime((2009, 1, 2, 3, 4, 5, 0, 0, -1)) # 2009/01/02 03:04:05
os.utime(filename, (access_time, fix_time))
function hoge(width, height) {
var w = width || 100; //if width is undefined, width = 100
var h = height || 200; //if height is undefined, height = 200
return width*height;
}
var png = mainCanvas.toDataURL()
f = open(path, "rb")
hex_data = f.read().encode("hex")
hex_data_replaced = re.sub('(..)', r'\1 ', hex_data)
print hex_data_replaced
f.close()
int(F, 16)
>> 15
list1 = ["a", "b", "c"]
text = "".join(list1)
>> "abc"
list2 = [1, 2, 3]
text = "".join(map(str, list2))
>> "123"
list3 = list(map(int, text))
print list3