Skip to content

Instantly share code, notes, and snippets.

@piglovesyou
piglovesyou / gist:2a2ce39de7ea6368a56a
Created September 30, 2014 00:09
node-flask-router snipet
var path = require('path');
var http = require('http');
var connect = require('connect')();
var router = require('flask-router')();
connect.use(require('serve-static')('public'));
connect.use(router.route);
router.get('/', function(req, res) {
res.write('yeah');
res.end();
@piglovesyou
piglovesyou / gist:25383968406af5bea4af
Created October 4, 2014 17:18
userInteractionEnabled
viewController.userInteractionEnabled = true すると viewController.touchBegan メソッドが呼ばれるようになる。でも viewController.view を触ったときだけで、subview を触っても呼ばれない。
@piglovesyou
piglovesyou / gist:1d0f65a58d7880e69b92
Created October 5, 2014 06:12
feely-like vertical swipe
import UIKit
class ViewController: UIViewController {
var red : UIView?
var blue : UIView?
var green : UIView?
var current : Int?
override func viewDidLoad() {
@piglovesyou
piglovesyou / gist:e57e135079e6f954fad2
Created October 13, 2014 08:52
web scraping snippet
# Install querySelector command
wget -O tmp.zip https://github.com/piglovesyou/jsdom/archive/master.zip
unzip tmp.zip
npm install jsdom-master -g
rm -rf tmp.zip jsdom-master
# Scrape something
Dir=result
mkdir -p $Dir
for N in `seq 1 13`; do
@piglovesyou
piglovesyou / gist:aad48d6e440993829918
Last active August 29, 2015 14:10
Promise where consumers consumes tasks concurrently
var Q = require('q');
var pool = [];
while (pool.length < 45) pool.push('yeah' + pool.length);
doConcurrent(sampleTask, pool, 8)
.then(console.log);
function doConcurrent(task, pool, concurrent) {
@piglovesyou
piglovesyou / gist:fc7fbfff400068f838e3
Created January 16, 2015 16:13
thousand items list in react
var itemHeight = 47;
var MyListItem = React.createClass({
render: function render() {
var style = {
top: this.props.index * itemHeight
};
return (
<div className="listitem" style={style}>
item{this.props.index}..
@piglovesyou
piglovesyou / gist:a2f479a5911b9c04fd76
Created February 12, 2015 14:45
goog.Promise typecheck example
goog.require('goog.Promise');
delay(6)
.then(multiply);
// 36
delay('yeah')
.then(multiply);
// main.js:9: WARNING - actual parameter 1 of goog.Promise.prototype.then does not match formal parameter
// found : function (number): undefined
var co = require('co');
var Q = require('q');
delay(400)
.then(console.log)
.then(delay.bind(null, 400))
.then(console.log)
.then(delay.bind(null, 400))
.then(console.log)
.catch(err => console.error(err.stack))
@piglovesyou
piglovesyou / Runner.java
Last active August 29, 2015 14:16
Load CommonJS JavaScript module, call function in it with Rhino
import java.util.Arrays;
import java.util.List;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.commonjs.module.Require;
import org.mozilla.javascript.tools.shell.Global;
@piglovesyou
piglovesyou / Test.java
Last active August 29, 2015 14:16
String Concatenation in Java and Rhino JavaScript
import java.util.Arrays;
import java.util.List;
import java.lang.StringBuffer;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.commonjs.module.Require;
import org.mozilla.javascript.tools.shell.Global;