This file contains hidden or 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
# 整数を割り算すると、デフォルトで小数点以下が切り捨てになる | |
12 / 26 | |
#0 | |
float(12) / 26 | |
#0.46153846153846156 | |
12 * 1.0 / 26 | |
#0.46153846153846156 |
This file contains hidden or 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
// 1つの場合 | |
function preloader() { | |
heavyImage = new Image(); | |
heavyImage.src = "sample.jpg"; | |
} | |
// 複数ある場合 | |
function preloader() { | |
// counter | |
var i = 0; |
This file contains hidden or 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
l = [1, 1, 2, 2, 3] | |
distinct_result = list() | |
map(lambda x: not x in distinct_result and distinct_result.append(x), l) | |
print(distinct_result) | |
#[1, 2, 3] | |
distinct_result = list(set(l)) | |
print(distinct_result) | |
#[1, 2, 3] |
This file contains hidden or 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 sys | |
argvs = sys.argv | |
print(argvs) | |
# ターミナルで以下のように打つと | |
#python comand-line.py あ a 1 | |
# 以下の内容が返ってくる | |
#['comand-line.py', 'あ', 'a', '1'] |
This file contains hidden or 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
Array.prototype.distinct = function() { | |
var u = {}, a = []; | |
for(var i = 0, l = this.length; i < l; ++i){ | |
if(u.hasOwnProperty(this[i])) { | |
continue; | |
} | |
a.push(this[i]); | |
u[this[i]] = 1; | |
} | |
return a; |
This file contains hidden or 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
# Pythonっぽい書き方 | |
a = '1,2,3,4,5,' | |
# その1 | |
p1 = [item for item in a.split(',') if not item == ''] | |
print(p1) | |
#['1', '2', '3', '4', '5'] | |
# その2 |
This file contains hidden or 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 markdown | |
md = markdown.Markdown(extensions=['codehilite']) | |
sample = """ | |
sample text | |
:::python | |
import sys | |
def sample(): | |
print 'sample' | |
""" |
This file contains hidden or 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
var str = 'iPhone'; | |
str.replace(/(iPhone)/g); // 括弧でくくった部分が格納される | |
console.log(RegExp.$1); |
This file contains hidden or 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
# インデックスつきループ | |
# listの場合enumerateを使う | |
sample_list = ['i', 'ro', 'ha', 'ni', 'ho', 'he', 'to'] | |
for i, v in enumerate(sample_list): | |
print(i, v) | |
# dictionaryで3.xの場合itemsを使う | |
# iteritemsは廃止 | |
sample_dictionary = {0:'i', 1:'ro', 2:'ha', 3:'ni', 4:'ho', 5:'he', 6:'to'} |
This file contains hidden or 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
# jinjaでenumerate() | |
<ul> | |
{%- for item in items %} | |
# loop.indexだと1から始まる | |
<li>{{ item }} - {{ loop.index0 }}</li> | |
{%- endfor %} | |
</ul> |