Skip to content

Instantly share code, notes, and snippets.

View jcouyang's full-sized avatar
🈚
💢

Jichao Ouyang jcouyang

🈚
💢
View GitHub Profile
@jcouyang
jcouyang / aqi.ino
Last active April 26, 2020 09:36
Interface to Shinyei Model PPD42NS Particle Sensor
/*
Interface to Shinyei Model PPD42NS Particle Sensor
Program by Christopher Nafis
Written April 2012
http://www.seeedstudio.com/depot/grove-dust-sensor-p-1050.html
http://www.sca-shinyei.com/pdf/PPD42NS.pdf
JST Pin 1 (Black Wire) => Arduino GND
JST Pin 3 (Red wire) => Arduino 5VDC
@jcouyang
jcouyang / pratical Monads.org
Last active June 3, 2016 15:40
Practical Monads

Practical Monads

ToC

  • Monad
  • Promise
  • Observable
  • Demo

Monad

@jcouyang
jcouyang / rethinking-react-dataflow.blog.md
Created February 12, 2016 14:59
Rethinking React Data Flow

Redux is so popular, and it really can handle component state pretty well, but after working around with large scale project, it seems not as good as it’s promising.

#What’s the problem

##1. Reusability

All reducers is a pure function which is really great, which makes all reducers composible, predictable. However, the switch case statement in reducer ruined all those good parts from pure function. 

Switch cases make function multiple purpose, which breaks both single responsibility and open close principle. Breaking the principles means it’s hard to compose and reuse any data flow(tiny reducer) in switch cases. 

@jcouyang
jcouyang / clojure-vector-persistent-tree.dot
Last active March 5, 2016 13:36
Clojure vector persistent digraph
digraph {
node[shape=record]
newrank=true;
subgraph cluster_level1{
style=dotted;
vec2[shape=plaintext]
node0[label = "<f0> root |<f1> tail"];
node1[label="<f0>|<f1>"];
node2[label="<f0>|<f1>"];
node3[label="<f0>|<f1>"];
@jcouyang
jcouyang / contribution-svg.rb
Last active February 11, 2023 22:32
SVG image for your github contributions calendar
require "nokogiri"
require "open-uri"
url = "https://github.com/#{params['username']}"
document = Nokogiri::HTML(open(url))
contrib_boxes = document.css('svg.js-calendar-graph-svg')[0]
contrib_boxes['xmlns']="http://www.w3.org/2000/svg"
width = (params['width']||54*13-2).to_i
height = (params['height']||89).to_i
contrib_boxes.css('text').remove
contrib_boxes['width']=(width+11).to_s+'px'
@jcouyang
jcouyang / circle.yml
Last active November 25, 2015 16:25
Circle CI Github Page and NPM deploy
general:
branches:
only:
- master
machine:
node:
version: 5.0.0
dependencies:
pre:
- npm install -g babel-cli
@jcouyang
jcouyang / embedding-gist in orgmode file.md
Created November 7, 2015 14:26
include a file from gist to you org file

we all know orgmode can #+include localfile, but how we can include a file somewhere on the web, for example gist.

here's how you can embedding a org source from gist and include in your org file.

#+BEGIN_SRC sh :exports results :results raw
curl https://gist.githubusercontent.com/jcouyang/d8086961761f28f35bb9/raw/2c6df28e349ab81ac10e3f6f63d65e20df296729/glist-testing.md
#+END_SRC
require "nokogiri"
require "open-uri"
url = "https://github.com/#{params['username']}"
document = Nokogiri::HTML(open(url))
{
:pop_repos => document.css('.js-pinned-items-reorder-list').to_html,
:calendar => document.css('.js-calendar-graph-svg').to_html
}
@jcouyang
jcouyang / data-source.json
Created August 21, 2015 02:35
falcor react todo mvc
{"todos":{
"0":{"name":"get milk from corner store","done":false},
"1":{"name":"take a dump","done":true},
"2":{"name":"make someone eat the dump","done":false},
"length":10}
}
@jcouyang
jcouyang / arity.sjs
Last active August 29, 2015 14:22
Clojure style arity function
macro caseFunc {
case {_ ($args...) {$body... $last:expr}} =>
{
letstx $len = [makeValue(#{$args...}.length , null)];
return #{
case $len:
return (function($args...){$body... return $last}).apply(this, arguments)
}
}
}