Skip to content

Instantly share code, notes, and snippets.

🚼

Jichao Ouyang jcouyang

🚼
Block or report user

Report or block jcouyang

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View hypothesis-rss.rb
require "httparty"
require 'json'
url = "https://hypothes.is/api/search?wildcard_uri=https://blog.oyanglul.us/*&sort=created"
HEADER = <<-EOXML
<?xml version="1.0"?>
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
@jcouyang
jcouyang / surfingKeys.js
Last active May 2, 2018
Surfingkeys Settings
View surfingKeys.js
settings.stealFocusOnLoad = false;
// an example to create a new mapping `ctrl-y`
mapkey('<Ctrl-y>', 'Show me the money', function() {
Front.showPopup('a well-known phrase uttered by characters in the 1996 film Jerry Maguire (Escape to close).');
});
// an example to replace `T` with `gt`, click `Default mappings` to see how `T` works.
map('gt', 'T');
// an example to remove mapkey `Ctrl-i`
View typeclass-in-typescript.ts
// Higher Kind Type dictionary
interface _<A> { }
type HKT = keyof _<any>
type $<F extends HKT, A> = _<A>[F]
// Functor Type Class
interface Functor<F extends HKT> {
map<A, B>(f: (a: A) => B, fa: $<F, A>): $<F, B>
@jcouyang
jcouyang / bmi-calc.rb
Last active Sep 10, 2017
BMI Calculator
View bmi-calc.rb
height = params['height'].to_f
weight = params['weight'].to_f
bmi = weight * 10000.0 / (height * height)
health = if(bmi < 18.5)
'underweight'
elsif (bmi < 24.9)
'normal'
elsif (bmi < 30)
'Overweight'
elsif (bmi >= 30)
@jcouyang
jcouyang / syncthing
Created Jul 29, 2017
/etc/init.d/syncthing
View syncthing
#!/bin/sh
### BEGIN INIT INFO
# Provides: syncthing
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Multi-user daemonized version of syncthing.
@jcouyang
jcouyang / ipfs
Created Jul 29, 2017
/etc/init.d/ipfs
View ipfs
#!/bin/sh
### BEGIN INIT INFO
# Provides: ipfs daemon
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts the ipfs daemon
# Description: Starts the ipfs daemon using the start-stop-daemon
### END INIT INFO
@jcouyang
jcouyang / README.org
Last active Jun 27, 2019
Promise All with Limit of Concurrent N
View README.org

The Promise All Problem

in case of processing a very large array e.g. Promise.all(A_VERY_LARGE_ARRAY_OF_XHR_PROMISE)

which would probably blow you browser memory by trying to send all requests at the same time

solution is limit the concurrent of requests, and wrap promise in thunk

Promise.allConcurrent(2)([()=>fetch('BLAH1'), ()=>fetch('BLAH2'),...()=>fetch('BLAHN')])

View haskell.hs
import Control.Monad
import Data.List
solution n =
undefined
readInt :: IO Int
readInt = readLn
getInputs :: Int -> IO [Int]
getInputs lines = replicateM lines readInt
@jcouyang
jcouyang / aqi.ino
Last active Dec 19, 2016
Interface to Shinyei Model PPD42NS Particle Sensor
View aqi.ino
/*
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
View pratical Monads.org

Practical Monads

ToC

  • Monad
  • Promise
  • Observable
  • Demo

Monad

You can’t perform that action at this time.