Skip to content

Instantly share code, notes, and snippets.

View nashibao's full-sized avatar

Naoki Shibayama nashibao

View GitHub Profile
@nashibao
nashibao / co.js
Last active January 2, 2016 09:09
minimum coroutine module (without error handling, dictionary). like https://github.com/visionmedia/co.
var co = function(fn){
function is_gen(obj) {
return obj && obj.constructor && 'GeneratorFunctionPrototype' == obj.constructor.name;
}
return function(done){
var gen = fn;
if(typeof gen == 'function')
gen = gen();
@nashibao
nashibao / simple_co.js
Last active January 2, 2016 10:59
for study.
var co = function(fn){
// callback
var done = function(val){
// yieldに値を流し込む
gen.next(val);
}
// make a generator
var gen = fn(done);
// start
gen.next();
@nashibao
nashibao / co-gate-sample.js
Created January 13, 2014 04:35
co-gate sample script.
// require co
var co = require('co')
, Gate = require('co-gate')
, fs = require('fs');
co(function *(){
// create gate
var gate = new Gate()
, val = undefined;
@nashibao
nashibao / karte_asp_api.md
Last active August 29, 2015 13:56
How to connect karte asp api to your app.

How to connect karte api to your app

  1. request for creating(updating) a project(per store) in karte
  2. embed js code in html header
  • [APP_PUBLIC_KEY] & [APP_PRIVATE_KEY] would be sent from karte.io per app.

1. request for creating(updating) a project in karte

@nashibao
nashibao / component_with_requirejs.md
Last active August 29, 2015 13:58
Makefile to make `component/component` working with `requirejs`.

I found some modules of component/component (ex: lodash) may cause a problem with AMD module loader like requirejs.
You should delete locally the define property to make a component working nicely with these loaders.

like below..

install: components index.js
	component build --standalone app --out . --name app-temp
	sed -e "s/;(function(){/;(function(){var define = undefined;/g" app-temp.js > app.js
@nashibao
nashibao / dnode_performance.coffee
Created April 17, 2014 09:47
dnode performance.
dnode = require 'dnode'
async = require 'async'
iteration_num = 100
# setup
server = dnode {
test: (a, b, cb)->
cb(null, a + b)
}
server.listen(8062)
from os.path import realpath
import sys
import numpy as np
from numpy.random import rand
from numpy import matrix
from numpy import multiply
from pyspark import SparkContext
LAMBDA = 0.01 # regularization for als
@nashibao
nashibao / blog1.sql
Last active November 30, 2016 14:14
blog1
SELECT corpus, word, word_count FROM tbl
WHERE LENGTH(word) > 4
ORDER BY word_count
DESC LIMIT 5
@nashibao
nashibao / blog2.sql
Created November 30, 2016 14:17
blog2.sql
SELECT corpus, word, SUM(word_count) AS total FROM tbl
WHERE ...
Group By corpus
ORDER BY total
DESC LIMIT 5
@nashibao
nashibao / blog3.sql
Created November 30, 2016 14:18
blog3.sql
SELECT hoge FROM a
JOIN
(SELECT fuga FROM b) AS c
ON a.hoge = c.fuga