This file contains 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
#!/usr/bin/env python | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
from sklearn.feature_extraction.text import CountVectorizer | |
from sklearn.decomposition import TruncatedSVD | |
from sklearn.preprocessing import Normalizer | |
def tf(doc): | |
vectorizer = CountVectorizer(token_pattern=u'(?u)\\b\\w+\\b') | |
features = vectorizer.fit_transform(doc) | |
terms = vectorizer.get_feature_names() |
This file contains 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
#!/usr/bin/env python | |
from sklearn.cluster import KMeans | |
def kmeans(features, k=10): | |
km = KMeans(n_clusters=k, init='k-means++', n_init=1, verbose=True) | |
km.fit(features) | |
return km.labels_ | |
def plot(features, labels): | |
import matplotlib.pyplot as plt |
This file contains 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
Sketch.prototype.setStrokeStyle = function(color) { | |
this.context.strokeStyle = color; | |
}; |
This file contains 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 Sketch = require('./sketch.js'); | |
// スケッチを作る | |
var sketch = new Sketch('sketch'); | |
// スケッチの機能を使う | |
// (x, y) に円を描く | |
sketch.drawCircle(point.x, point.y); | |
// スケッチを白紙にする |
This file contains 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
ArrayList<PVector> points; | |
boolean isDrawing; | |
void setup() { | |
size(640, 480); | |
points = new ArrayList<PVector>(); | |
} |
This file contains 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 loadFile = function(filename) { | |
var dfd = Promise.defer(); | |
var xhr = new XMLHttpRequest(); | |
xhr.onload = function() { | |
dfd.resolve(xhr.responseText); | |
}; | |
xhr.open("GET", filename, true); | |
xhr.send(null); |
This file contains 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
#!/usr/bin/env python | |
import fitbit | |
CONSUMER_KEY = '' | |
CONSUMER_SECRET = '' | |
def init_fitbit(token=None): | |
client = fitbit.FitbitOauthClient(CONSUMER_KEY, CONSUMER_SECRET) | |
if not token: |
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from dmm import DMM | |
api_id = 'hogehoge' | |
affiliate_id = 'hugehuge' | |
dmm = DMM(api_id, affiliate_id) | |
print dmm.search_by_keyword(u'つぼみ') |
This file contains 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 json | |
data = {"hoge": 1, "hige": 2, "huge" 3} | |
json_data = json.dumps(data, ensure_ascii=False, indent=2) | |
print json_data |
This file contains 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
print sum(1 for _ in re.finditer(pattern, text)) |