Skip to content

Instantly share code, notes, and snippets.

View jbmilgrom's full-sized avatar

Jonathan Milgrom jbmilgrom

View GitHub Profile
scope.greeting = 'hi there';
var getGreeting = function(scope) {
return scope.greeting;
};
scope.$watch(getGreeting, function(greeting) {
console.log('greeting: ', greeting); // greeting: hi there
});
@jbmilgrom
jbmilgrom / permutations.scm
Last active January 19, 2017 17:24
A method for permuting a set in scheme
(define (permutations s)
(if (null? s)
(list s)
(flatmap (lambda (x)
(map (lambda (p) (cons x p))
(permutations (remove x s))))
s)))
; Helper methods
<div ng-switch-when="isEdit" class="edit-ad-wrapper"
ng-init="vm.heading = vm.getAdHeading({ad: vm._adBeingEdited}); vm.caption = vm.getAdCaption({ad: vm._adBeingEdited})">
<tl-circular-checkbox class="check-toggle-wrapper"
is-checked="true">
</tl-circular-checkbox>
<div class="image" style="background-image:url({{ ::vm.getAdImageUrl({ad: vm._adBeingEdited}) }})">
</div>
<div class="edit-fields-wrapper">
<ad-preview-form-heading class="form-heading-wrapper" label="Heading"
num-characters="vm.heading.length">
/**
* Transform an object from one basis to another - i.e map keys - using a specification
* @param {Object[]} specification - a collection of objects specifying relationship
* @param {Object} options
* @param {String} options.from - name of source key
* @param {String} options.to - name of target key
* @param {Object} hash - subject of the basis change
* @return {Object} - new object with new set of keys
*
* @example
@jbmilgrom
jbmilgrom / bst.js
Last active April 19, 2017 12:39
binary search tree factory
var binaryTreeFactory = (function() {
return function create(source, isLeft) {
isLeft = isLeft || lessThan;
var root = seed(source.slice() /* shallow copy */, isLeft);
return {
insert: function(thing) {
insertNode(root, makeNode(thing), isLeft);
},
<?php
abstract class Assert
{
function strictlyEquals($a, $b)
{
echo $a === $b ? 'Sure does' : 'Sure doesnt';
}
function kindaEquals($a, $b)
@jbmilgrom
jbmilgrom / combineReducers.ts
Last active August 7, 2017 12:47
Redux: Naive combineReducers implementation in typescript
interface Reducer {
(state: object, action: object): object
}
interface Reducers {
[key: string]: Reducer
}
/**
* Combine map of reducers keyed off of state key
@jbmilgrom
jbmilgrom / Connect.tsx
Last active August 11, 2017 16:17
React-Redux: High-level implementation of Connect in TypeScript intended to provide type declarations that highlight both synchronous and asynchronous use-cases all in one place.
import * as React from 'react';
import { mapValues } from 'lodash';
/**
* All action objects must have a 'type' key
*/
interface ActionSync {
type: any;
}
@jbmilgrom
jbmilgrom / less-params-narrow-type.ts
Created September 18, 2017 19:51
Typescript: example of lesser number of parameters as a narrow type.
interface CallbackWithNameParameter {
cb: (name: string) => void
}
type CallbackWithNoParameter = () => void;
const aCallbackWithNoParameter: CallbackWithNoParameter = () => {};
const aCallback: CallbackWithNameParameter = { // okay
cb: aCallbackWithNoParameter
};
@jbmilgrom
jbmilgrom / creative-management-store-shape.example.ts
Last active November 10, 2017 20:43
Example of a creative library of format type `scroll` intended exemplify the relationship between a library and its associated ads (in this case, scrolls)
store.creativeLibraries = [{
...
},{
'id': 4855,
'active': 1,
'deleted': 0,
'name': 'new scroll ad (copied)',
'member_id': null,
'advertiser_id': 1092,
'brand_id': null,