Skip to content

Instantly share code, notes, and snippets.

var spec = { enumerable: false }
var x = {};
Object.defineProperty(x, "test", spec);
x.test = "what"
alert(JSON.stringify(x));
var y = {};
Object.defineProperty(y, "test", spec);
@jhusain
jhusain / PEG grammer for pattern match syntax
Created October 29, 2016 03:29
PEG grammer for pattern match syntax. Forked from JSON grammer.
JSON_text
= ws value:value ws { return value; }
begin_array = ws "[" ws
begin_object = ws "{" ws
end_array = ws "]" ws
end_object = ws "}" ws
name_separator = ws ":" ws
value_separator = ws "," ws
@jhusain
jhusain / Simple Observable impl
Created May 4, 2017 00:26
Observable implementation which optimizes very well in prepack
function Observable(subscribe) {
this._subscribe = subscribe;
}
const of = (v) => new Observable(observer => {
return observer.next(v);
});
Observable.prototype = {
map(f) {
@jhusain
jhusain / MyFree.purs
Created January 17, 2018 17:57
MyFree implementation
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Data.Foldable (fold)
import TryPureScript (DOM, h1, h2, p, text, list, indent, link, render, code)
type Video = { name:: String }
/*
* Performs a exclusive waiting for the first to finish before subscribing to another observable.
* Observables that come in between subscriptions will be dropped on the floor.
* @returns {Observable} A exclusive observable with only the results that happen when subscribed.
*/
observableProto.exclusive = function () {
var sources = this;
return new AnonymousObservable(function (observer) {
var hasCurrent = false,
isStopped = false,
@jhusain
jhusain / gist:d6007e9cce59ac6f173449cd6841f9fc
Created May 20, 2017 19:12
"Animations Allowed" problem
someObservable.retry(3)
consts tasks =
{
....{....5......2.......3...}
............{......5............4....3}
............................................{5...2...4}
.....................................................{...5}
}
@jhusain
jhusain / gist:26382a1b2267691284fbe0bcdc44e519
Created August 13, 2018 04:40
kth largest card (heap remove broken)
/*
Bar Problem
N friends are playing a game. Each of them has a list of numbers in front of himself.
Each of N friends chooses a number from his list and reports it to the game administrator. Then the game administrator sorts the reported numbers and shouts the K-th largest number.
You want to know the count all possible numbers that the game administrator can shout.
@jhusain
jhusain / falcor stuff
Created April 18, 2018 21:46
falcor stuff
https://github.com/Netflix/falcor-path-utils/blob/master/lib/toTree.js
[
["list",{from:0,to:9],["name","rating"]],
["list", "length"]
]
->
{
import cyclops.control.Unrestricted;
import io.reactivex.Observable;
public class ObservableInterpreter {
public static <R> Observable<R> interpret(Unrestricted<R> program){
//walk the Free data structure and handle each command,
@jhusain
jhusain / nofold.ts
Last active January 4, 2018 18:11
You can't write fold in TypeScript (doesn't compile)
interface Combinable<T> {
plus(T): T,
zero(): T
}
class Max implements Combinable<Max> {
private value: number
constructor(num: number) {
this.value = num;
}