Skip to content

Instantly share code, notes, and snippets.

View ryohey's full-sized avatar

ryohey ryohey

View GitHub Profile
@ryohey
ryohey / upload-example.coffee
Created July 6, 2014 06:00
node-multiparty-upload-example-app
express = require "express"
multiparty = require "multiparty"
app = express()
app.get "/", (req, res) ->
res.send """
<form action="/" enctype="multipart/form-data" method="post">
<input type="file" name="uploadFile">
<input type="submit">
@ryohey
ryohey / mongo-passport-twitter-example.coffee
Last active August 11, 2020 15:04
Node.js Passport Twitter login and storing user with MongoDB (mongoose)
# launch the mongoDB before running the server
# mongod --dbpath /path/to/db
# ------------------------------
# passport
# ------------------------------
passport = require("passport")
TwitterStrategy = require("passport-twitter").Strategy
Twit = require "twit"
twit = new Twit
consumer_key: "TWITTER_CONSUMER_KEY"
consumer_secret: "TWITTER_CONSUMER_SECRET"
access_token: "ACCESS_TOKEN"
access_token_secret: "ACCESS_TOKEN_SECRET"
twit.get "account/verify_credentials", (err, data, res) ->
twitterId = data.id
next = (value) -> "🐱"+value
back = (value) -> value.slice("🐱".length, value.length)
zero = "🐶"
# next = (value) -> [value]
# back = (value) -> value.pop()
# next = (value) -> -> value
# back = (value) -> value()
@ryohey
ryohey / communicate-with-child-process.coffee
Created November 20, 2015 15:27
Wrapping a child process as a class and communicate in electron
remote = global.require "remote"
child_process = remote.require "child_process"
class Foo
start: ->
@child = child_process.spawn "fooProgram", [barArgument]
doFooBar: (arg1, callback) ->
@child.stdin.write arg1
@ryohey
ryohey / json2html.coffee
Last active December 4, 2015 17:43
convert object to <ul><li> and <dl><dt><dd> in CoffeeScript for React.js
json2html = (obj) ->
if obj instanceof Array
list = json2html o for o in obj
<ul>{list}</ul>
else if obj instanceof Object
list = ([
<dt>{key}</dt>
<dd>{json2html value}</dd>
] for key, value of obj)
<dl>{list}</dl>
//
// main.cpp
// FaceTracker
//
// Created by ryohey on 2015/12/11.
//
#include <iostream>
#include <cv.h>
#include <highgui.h>
@ryohey
ryohey / main.coffee
Last active January 6, 2016 00:48
Export Github wiki to esa.io
fs = require "fs"
req = require "request"
## config
teamName = "your esa.io team name"
accessToken = "your esa.io personal access token"
# the directory markdown files saved (git clone git@github.com:USERNAME/REPONAME.wiki.git)
dir = "path/to/reponame.wiki"
@ryohey
ryohey / main.coffee
Created January 13, 2016 16:11
The Wolfram 2, 3 Turing Machine in CoffeeScript
logTm = (tm) ->
text = tm.colors
.map (s, i) -> if i is tm.pos then "%c" + ["▲", "▼"][tm.state] else "%c "
.join ""
style = tm.colors.map (c) -> "background-color:" + ["white", "yellow", "orange"][c] + ";"
console.log.apply console, [text].concat style
# [state, color] = [state, color, offset]
rule = {}
rule[[0, 2]] = [0, 1, -1]