Skip to content

Instantly share code, notes, and snippets.

View mbergal's full-sized avatar

Misha Bergal mbergal

View GitHub Profile
exception ErrorB;
exception ErrorA;
exception ExceptionWithStackTrace(exn, string);
let raise_trace = (exc: exn) => {
let stackTrace: string = [%bs.raw {|new Error().stack|}];
raise(ExceptionWithStackTrace(exc, stackTrace));
};
/* @flow */
import { MongoClient } from "mongodb";
import * as md5 from "md5";
const streamToObservable = require("stream-to-observable");
const LOCAL_MONGO_URL = "mongodb://localhost:32768/peardeck";
const mongoUrl = PRODUCTION_MONGO_URL;
import { Observable } from "rxjs";
/* @flow */
type A = { a: string; }
var a = { a: 'a', b: 'b' };
function f(a: A) {
return { ...a, sum: 0 };
}
type A = { a: string; }
var a = { a: 'a', b: 'b' };
function f(a: A) {
return { ...a, sum: 0 };
}
function g<T extends A >(a: T): T&{sum:number} {
return { ...a, sum: 0 };
import Date exposing (Date)
type alias Model =
{ mediaUrl : String
, description : String
, currentUser : User
, comments : List MediaComment
}
// https://raw.githubusercontent.com/flowtype/flow-typed/master/definitions/npm/underscore_v1.x.x/flow_v0.13.x-/underscore_v1.x.x.js
// type definitions for (some of) underscore
declare module "underscore" {
declare interface Collection<T> {}
declare interface Dictionary<T> extends Collection<T> {
[index: string]: T;
}
@mbergal
mbergal / gist:d4fb2fa79fd2978c45bd05aeaf10eda6
Created August 2, 2016 23:57
Attempt to use Proxy to intercept calls to undefined state members
return (new Proxy( a, {
get: function(target, name, receiver) {
if ( target[name] !== undefined || name === 'window' || name === 'children')
return target[name];
else
{
debugger;
console.log(name);
}
},
type Base = {
common: string;
}
type A = Base & {
type: 'a'
}
type B = Base & {
type: 'b'
@mbergal
mbergal / configureInterpolateDebugging.js
Created July 12, 2016 05:48
Angular interceptor debugging
function configureInterpolateDebugging($provide) {
$provide.decorator("$interpolate", function($delegate){
var interpolateWrap = function(){
var interpolationFn = $delegate.apply(this, arguments);
if (interpolationFn) {
return interpolationFnWrap(interpolationFn, arguments);
}
};
@mbergal
mbergal / flow.js
Last active July 8, 2016 18:27
Flow Disjoint Unions vs Elm Tagged Unions
/* @flow */
type BookComment = { kind: 'book', url: string, created: Date, bookOrSomething: string }
type AudioComment = { kind: 'audio', url: string, created: Date, audioOrSomething: string }
type MediaComment =
BookComment
| AudioComment;
var comments : MediaComment[] = [
{ kind: 'book', url: 'b', created: new Date(), bookOrSomething: 'book' },