Skip to content

Instantly share code, notes, and snippets.

View jsliang's full-sized avatar

Jui-Shan Liang (Jenny) jsliang

View GitHub Profile
javascript:function minutesSeconds(s){return(s-(s%=60))/60+(9<s?':':':0')+s}function start(){var currentURL=window.location.href;var bar=document.getElementsByClassName("ytp-progress-bar")[0];var seconds=bar.getAttribute("aria-valuenow");var secondsInMS=minutesSeconds(seconds);var URL=currentURL+"?t="+seconds;var obsidianFormat="["+secondsInMS+"]("+URL+")";navigator.clipboard.writeText(obsidianFormat);null;var elemDiv=document.createElement('div');elemDiv.innerHTML="<h1 style='font-size:100px; color:white; text-align:center; margin-top:2em;'>"+secondsInMS+"</h1>";elemDiv.style.cssText='position:absolute;width:100%;height:100%;opacity:0.8;z-index:1000;background:#000;';document.body.appendChild(elemDiv);setTimeout(function(){elemDiv.style.display="none"},600)}start();
@mofas
mofas / stream.js
Created April 29, 2018 00:50
Try to implement simple stream
// Stream
const stream = f => (x => x(x))(y => init => [init, m => y(y)(f(m))]);
const add3Stream = stream(n => n + 3);
const mult2Stream = stream(n => n * 2);
const inspect = stream(n => {
console.log('inspect:' + n);
return 0;
});
const pipe = s1 => s2 => x => {
@mofas
mofas / y-combinator.js
Last active May 9, 2018 06:16
y-combinator
// basic idea
(f => f(f)(5))(f => n => n == 0 ? 1 : (n * f(f)(n-1)));
// This version doesn't work, because js is not lazy.
// const Y = f => (x => f(x(x)))(x => f(x(x)));
// const Y = f => (x => x(x))(x => f(a => x(x)(a)));
const Y = f => (x => f(y => x(x)(y)))(x => f(y => x(x)(y)));
@mofas
mofas / map.js
Last active May 9, 2018 06:16
Build map in function closure
// At first, we need to build empty map.
// Empty map is just a function, it will return undefined when invoked.
// When you set new key-value into map, it will wrap a new function around previous map,
// and when you get something from map with key, it will pass key to every nested function until it match or hit empty map.
const map = () => undefined;
const set = map => (key, value) => q => q === key ? value: map;
const get = map => key => typeof map === 'function' ? get(map(key))(key) : map;
// Demo time!
@mofas
mofas / list.js
Last active May 9, 2018 06:16
Build list structure by using function closure
// First we need to build data structure pair(a, b)
// cons: given a and b, and return a function.
// when you pass cons(a, b) as argument to car, it will return a;
// if you pass it to cdr, it will return b.
const cons = (a, b) => p => p ? a : b;
const car = pair => typeof pair === 'function' ? pair(1) : null;
const cdr = pair => typeof pair === 'function' ? pair(0) : null;
// Now we can build list by chaining pair.
// For example, list [1, 2, 3] will be represented as cons(1, cons(2, 3))
@mterwill
mterwill / USAGE.md
Last active February 16, 2024 09:23
Beancount importers, scripts, etc.

Note: everything here is pretty specific to my usage/accounts and not written for public use... You'll probably have to tweak a bunch of stuff.

$ bean-extract config.py ~/Downloads # the csvs should be in here
@fokusferit
fokusferit / enzyme_render_diffs.md
Last active June 18, 2024 11:27
Difference between Shallow, Mount and render of Enzyme

Shallow

Real unit test (isolation, no children render)

Simple shallow

Calls:

  • constructor
  • render
@nunomorgadinho
nunomorgadinho / gist:b2d8e5b8f5fec5b0ed946b24fa288a91
Created February 10, 2017 13:30
PHPCS + WordPress Coding Standards
# Install brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Install composer
brew install homebrew/php/composer
### PHPCS
composer global require "squizlabs/php_codesniffer=*"
# Add to your .bash_profile
@marty-wang
marty-wang / gist:5a71e9d0a6a2c6d6263c
Last active June 27, 2024 13:34
Compile and deploy React Native Android app of Release version to device.
Disclaimer: The instructions are the collective efforts from a few places online.
Nothing here is my original. But I want to put them together in one place to save people from spending the same time as I did.
First off, bundle.
==================
1. cd to the project directory
2. Start the react-native packager if not started
3. Download the bundle to the asset folder:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
@ik5
ik5 / colors.go
Last active April 8, 2024 14:25
Simple golang expirement with ANSI colors
package main
// http://play.golang.org/p/jZ5pa944O1 <- will not display the colors
import "fmt"
const (
InfoColor = "\033[1;34m%s\033[0m"
NoticeColor = "\033[1;36m%s\033[0m"
WarningColor = "\033[1;33m%s\033[0m"
ErrorColor = "\033[1;31m%s\033[0m"
DebugColor = "\033[0;36m%s\033[0m"