Skip to content

Instantly share code, notes, and snippets.

Jafar Husain jhusain

Block or report user

Report or block jhusain

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
@jhusain
jhusain / gist:26382a1b2267691284fbe0bcdc44e519
Created Aug 13, 2018
kth largest card (heap remove broken)
View gist:26382a1b2267691284fbe0bcdc44e519
/*
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.
View falcor stuff
https://github.com/Netflix/falcor-path-utils/blob/master/lib/toTree.js
[
["list",{from:0,to:9],["name","rating"]],
["list", "length"]
]
->
{
@jhusain
jhusain / MyFree.purs
Created Jan 17, 2018
MyFree implementation
View MyFree.purs
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 }
View test.java
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 Jan 4, 2018
You can't write fold in TypeScript (doesn't compile)
View nofold.ts
interface Combinable<T> {
plus(T): T,
zero(): T
}
class Max implements Combinable<Max> {
private value: number
constructor(num: number) {
this.value = num;
}
@jhusain
jhusain / failingfunctor.purs
Last active Dec 20, 2017
Functor instance won't compile
View failingfunctor.purs
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)
import Data.Map (Map, lookup, insert, empty)
import Data.List
import Data.Either
View Observable.pipe
class Observable<T, E> {
// cant be typed in flow, but perhaps we can
// somehow declare several overloads?
// pipe(Observable<T0, E0> => Observable<T1, E1>): Observable<T1, E1>
// pipe(Observable<T0, E0> => Observable<T1, E1>, Observable<T1, E1> => Observable<T2, E2>): Observable<T2, E2>
// etc...
pipe(...operators) {
return operators.reduce((acc, curr) => curr(acc), this);
}
View gist:d6007e9cce59ac6f173449cd6841f9fc
someObservable.retry(3)
consts tasks =
{
....{....5......2.......3...}
............{......5............4....3}
............................................{5...2...4}
.....................................................{...5}
}
@jhusain
jhusain / Simple Observable impl
Created May 4, 2017
Observable implementation which optimizes very well in prepack
View Simple Observable impl
function Observable(subscribe) {
this._subscribe = subscribe;
}
const of = (v) => new Observable(observer => {
return observer.next(v);
});
Observable.prototype = {
map(f) {
@jhusain
jhusain / PEG grammer for pattern match syntax
Created Oct 29, 2016
PEG grammer for pattern match syntax. Forked from JSON grammer.
View PEG grammer for pattern match syntax
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
You can’t perform that action at this time.