Skip to content

Instantly share code, notes, and snippets.

Avatar
🈚
💢

Jichao Ouyang jcouyang

🈚
💢
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am jcouyang on github.
  • I am oyanglulu (https://keybase.io/oyanglulu) on keybase.
  • I have a public key ASDd7C_jnHrfyZ-hv7yEPxWFSwbOCfYOX_oqoujJ55JeXwo

To claim this, I am signing this object:

@jcouyang
jcouyang / Emacs linux.xml
Created Jan 26, 2021
Intellij Emacs Keymap
View Emacs linux.xml
<keymap version="1" name="Emacs copy" parent="macOS For All">
<action id="$Copy">
<keyboard-shortcut first-keystroke="alt c" />
</action>
<action id="$Cut">
<keyboard-shortcut first-keystroke="shift delete" />
</action>
<action id="$Delete">
<keyboard-shortcut first-keystroke="delete" />
<keyboard-shortcut first-keystroke="ctrl d" />
@jcouyang
jcouyang / hypothesis-rss.rb
Last active Feb 23, 2020
my blog comments
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 Mar 16, 2021
Surfingkeys Settings
View surfingKeys.js
settings.stealFocusOnLoad = false;
map('<Ctrl-n>', 'j');
map('<Ctrl-f>', 'l');
map('<Ctrl-b>', 'h');
map('<Ctrl-p>', 'k');
map('<Ctrl-e>', '$');
map('<Ctrl-a>', '0');
map('<Ctrl-v>', 'd');
map('e', 'f');
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 Nov 19, 2021
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