Skip to content

Instantly share code, notes, and snippets.

@puriketu99
puriketu99 / file0.txt
Created May 13, 2014 03:37
特定の拡張子のファイルを削除 ref: http://qiita.com/puriketu99/items/02d5e4611192077dabd6
find dir_name -name "*.org"|xargs rm
@puriketu99
puriketu99 / file0.rb
Created May 7, 2014 08:34
Nokogiriでiso-8859-1で文字化けする場合の問題の解消方法 ref: http://qiita.com/puriketu99/items/102af64a9450b3278ae4
def url2text(url)
html = open(url).read
doc = Nokogiri::HTML(html.toutf8, nil, 'utf-8')
doc.text
end
@puriketu99
puriketu99 / file0.txt
Created March 23, 2014 08:15
Mac OS Xのバージョンがあげたらhomebrewでnpmが使えなくなる問題の解消方法 ref: http://qiita.com/puriketu99/items/79fbf6591d4f347d1ae2
node: Beginning with 0.8.0, this recipe now comes with npm.
It appears you already have npm installed at /usr/local/lib/node_modules/npm.
To use the npm that comes with this recipe, first uninstall npm with
`npm uninstall npm -g`, then run this command again.
If you would like to keep your installation of npm instead of
using the one provided with homebrew, install the formula with
the `--without-npm` option.
Error: An unsatisfied requirement failed this build.
a = [{"word":"a","tfidf":0.5},
{"word":"b","tfidf":0.1},
{"word":"c","tfidf":0.2}]
b = [{"word":"d","tfidf":0.3},
{"word":"a","tfidf":0.2},
{"word":"c","tfidf":0.4}]
c = [{"word":"a","tfidf":0.7},
{"word":"b","tfidf":0.1},
@puriketu99
puriketu99 / file1.txt
Created January 8, 2014 07:35
1分で実現できる!関数の実行結果をmemcachedにキャッシュするデコレータ ref: http://qiita.com/puriketu99/items/a228d8a0ff8b9ba800a1
def decorator_with_args(decorator_to_enhance):
"""
デコレータに引数を与えて返す関数
"""
def decorator_maker(*args, **kwargs) :
def decorator_wrapper(func) :
return decorator_to_enhance(func, *args, **kwargs)
return decorator_wrapper
return decorator_maker
@puriketu99
puriketu99 / console.assert
Last active December 29, 2015 21:19
1分で実現できるjavascriptにおけるconsoleまわりの有用なテクニック4つ ref: http://qiita.com/puriketu99/items/92b83172268685fceaf2
//console.assertの第一引数がfalseの場合、第二引数が表示されます
//trueの場合は何も表示されません。
console.assert(true,"trueだと何も表示しない")
console.assert(false,"falseだとこの内容を出力する")
@puriketu99
puriketu99 / file0.txt
Created November 6, 2013 05:11
pythonのデフォルトエンコーディングをutf-8に変更する ref: http://qiita.com/puriketu99/items/55e04332881d7b679b00
#こんなエラーが出たときの対処法
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position xx: ordinal not in range(128)
@puriketu99
puriketu99 / サンプルコード
Created September 27, 2013 01:01
1分でPython&CSSセレクタによるスクレイピングを実現する ref: http://qiita.com/puriketu99/items/8f81e6b02476c8e38e0e
# -*- coding: utf-8 -*-
from pyquery import PyQuery as pq
url = "http://www.sicafe.net/macPackageManageTips/html/homebrewPythonInstall.html"
query = pq(url)
for a in query.find("a"):#CSSセレクタ!!
print pq(a).text()
#出力結果
#前略
@puriketu99
puriketu99 / ページランクを出力
Created September 21, 2013 01:31
童貞でもできるページランク計算(全行コメント解説つき) ref: http://qiita.com/puriketu99/items/67643a9942923f4f5f67
# -*- coding: utf-8 -*-
import networkx as nx#先ほど入れたnetworkxをインポート
g = nx.DiGraph()#有向グラフを表現するためのオブジェクトを作成
g.add_edge("user1","user3")#user1からuser3に投票
g.add_edge("user2","user3")#user2からuser3に投票
g.add_edge("user2","user1")#user2からuser1に投票
g.add_edge("user3","user1")#user3からuser1に投票
g.add_edge("user4","user2")#user4からuser2に投票
g.add_edge("user1","user4")#user1からuser4に投票
@puriketu99
puriketu99 / file0.sh
Created August 12, 2013 16:36
非エンジニア向けのMercurial入門 ref: http://qiita.com/puriketu99/items/291601cdc3cfdee9d49b
hg init