Skip to content

Instantly share code, notes, and snippets.

View jcouyang's full-sized avatar
🈚
💢

Jichao Ouyang jcouyang

🈚
💢
View GitHub Profile

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 January 26, 2021 02:13
Intellij Emacs Keymap
<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 February 23, 2020 03:13
my blog comments
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 November 27, 2022 06:01
Firefox Surfingkeys Settings
settings.startToShowEmoji = 3;
settings.tabsMRUOrder = false;
settings.tabsThreshold = 4;
api.mapkey(';oc', 'Org Capture', function() {
location.href='org-protocol://capture?' +
new URLSearchParams({
template: 'x',
url: window.location.href,
title: document.title,
// 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 September 10, 2017 03:20
BMI Calculator
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 July 29, 2017 06:06
/etc/init.d/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 July 29, 2017 06:02
/etc/init.d/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 December 9, 2023 16:46
Promise All with Limit of Concurrent N

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')])

@jcouyang
jcouyang / haskell.hs
Created March 7, 2017 08:44
Hackerrank IO
import Control.Monad
import Data.List
solution n =
undefined
readInt :: IO Int
readInt = readLn
getInputs :: Int -> IO [Int]
getInputs lines = replicateM lines readInt