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
def escape_html(self, var): | |
meta_chars = { | |
'"': '"', | |
'\'': ''', | |
'&': '&', | |
'<': '<', | |
'>': '>', | |
} | |
escaped_var = "" | |
for i in var: |
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 pymongo, re | |
regx = re.compile("^foo",re.IGNORECASE) | |
db.users.find({"name": regx}) |
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
form datetime import datetime | |
date = '2013-05-20 16:31:59.199579' | |
strptime = datetime.strptime(date, '%Y-%m-%d %H:%M:%S.%f') | |
strftime = strptime.strftime('%B %d, %Y') |
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> |
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
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
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
# 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
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
import sys | |
argvs = sys.argv | |
print(argvs) | |
# ターミナルで以下のように打つと | |
#python comand-line.py あ a 1 | |
# 以下の内容が返ってくる | |
#['comand-line.py', 'あ', 'a', '1'] |
OlderNewer