Skip to content

Instantly share code, notes, and snippets.

View JustinSDK's full-sized avatar
👨‍👩‍👧
Working from home

Justin Lin JustinSDK

👨‍👩‍👧
Working from home
View GitHub Profile
function(sprite, spriteContainer) {
var spriteMouseDowns = Observable.fromEvent(sprite, "mousedown"),
spriteContainerMouseMoves = Observable.fromEvent(spriteContainer, "mousemove"),
spriteContainerMouseUps = Observable.fromEvent(spriteContainer, "mouseup"),
spriteMouseDrags =
// For every mouse down event on the sprite...
spriteMouseDowns.
flatMap(function() {
return spriteContainerMouseMoves;
}).takeUntil(spriteContainerMouseUps);
function(sprite, spriteContainer) {
// All of the mouse event sequences look like this:
// seq([ {pageX: 22, pageY: 3423, offsetX: 14, offsetY: 22} ,,, ])
var spriteMouseDowns = Observable.fromEvent(sprite, "mousedown"),
spriteContainerMouseMoves = Observable.fromEvent(spriteContainer, "mousemove"),
spriteContainerMouseUps = Observable.fromEvent(spriteContainer, "mouseup"),
// Create a sequence that looks like this:
// seq([ {pageX: 22, pageY:4080 },,,{pageX: 24, pageY: 4082},,, ])
spriteMouseDrags =
// For every mouse down event on the sprite...
@JustinSDK
JustinSDK / YCombinator.hs
Last active March 9, 2017 14:33
Y Combinator in Haskell
import Unsafe.Coerce
y :: (a -> a) -> a
y = \f -> (\x -> f (unsafeCoerce x x))(\x -> f (unsafeCoerce x x))
-- Ref: [Y Combinator in Haskell](http://stackoverflow.com/questions/4273413/y-combinator-in-haskell)
-- a fibonacci example
main = putStrLn $ show $ y (\fact -> \n -> if n < 2 then 1 else n * fact (n - 1)) 5
@JustinSDK
JustinSDK / yun.ino
Created July 22, 2015 03:03
Arduino Yún 加 Motoduino 的網路小車(一)
#include <Wire.h>
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
// Yun server
YunServer server;
void setup() {
// Join i2c bus (address optional for master)
@JustinSDK
JustinSDK / motoduino.ino
Created July 22, 2015 03:04
Arduino Yún 加 Motoduino 的網路小車(二)
#include <Wire.h>
// Motor pins
int speed_motor1 = 6;
int speed_motor2 = 5;
int direction_motor1 = 7;
int direction_motor2 = 8;
// Sensor pins
int distance_sensor = A0;
@JustinSDK
JustinSDK / Dockerfile
Last active September 5, 2015 07:37
Dockerfile for caterpillar/rpi-gradle
FROM resin/rpi-raspbian
MAINTAINER Justin Lin <[email protected]>
# Basic tools
RUN apt-get -qq update && \
apt-get -qqy install wget && \
apt-get -qqy install vim && \
apt-get -qqy install unzip && \
apt-get -qqy install git
@Wei1234c
Wei1234c / Oracle-Java8.armv7.dockerfile
Last active September 4, 2015 02:55
Dockerfile for Oracle-Java8 with Ubuntu on RPi2
# Oracle Java 8 Dockerfile
#
# https://github.com/dockerfile/java
# https://github.com/dockerfile/java/tree/master/oracle-java8
#
# origin: https://github.com/dockerfile/java/blob/master/oracle-java8/Dockerfile
# modified by: Wei Lin
# date: 2015/9/2
# Pull base image.
@Wei1234c
Wei1234c / SSHD.armv7.dockerfile
Last active September 4, 2015 02:01
Dockerfile for SSHD with Ubuntu on RPi2
# sshd
# VERSION: 0.0.2
# origin:
# MAINTAINER Sven Dowideit <[email protected]>
# https://docs.docker.com/examples/running_ssh_service/
#
# modified by: Wei Lin
# date: 2015/9/2
# Pull base image.
@JustinSDK
JustinSDK / Dockerfile
Last active September 5, 2015 07:36
Dockerfile for caterpillar/rpi-dev-java
FROM armv7/armhf-ubuntu:14.04
MAINTAINER Justin Lin <[email protected]>
ENV TERM linux
# Basic tools
RUN apt-get -qq update && \
apt-get -qqy install wget && \
apt-get -qqy install vim && \
apt-get -qqy install unzip && \
@JustinSDK
JustinSDK / sort.pl
Last active December 5, 2016 16:11
Prolog … 快速排序法 … 白話版… XD
Prolog … 快速排序法 … 白話版… XD
/*
* [] 附加 Result 的 結果為 Result
*/
append([], Result, Result).
/*
* Tail 附加 Other 的結果為 Subappend => [Head | Tail] 附加 Other 的結果為 [Head | Subappend]
*