Skip to content

Instantly share code, notes, and snippets.

View timruffles's full-sized avatar

Tim Ruffles timruffles

View GitHub Profile
@timruffles
timruffles / functors.ts
Created June 7, 2016 09:30
functor in TypeScript - this is probably in violation of many functor laws :/
interface Functor<T> {
map(mapper: (x: T) => T): Functor<T>;
ret(x: T): Functor<T>;
}
class Maybe<T> implements Functor<T> {
constructor(private value: T) {}
private nowt() {
@timruffles
timruffles / di-taste.md
Last active June 2, 2016 11:53
DI taste question

In the DI DOCs the 'why' given for the component injector tree is to get multiple instances of a dependency. The editor component explicitly provides RestoreService to ensure it gets its own instance.

                                 providers                   instance of `RestoreService`
rootInjector                     [provide(RestoreService)]   instance A
 - heroEditorComponentInjector   [provide(RestoreService)]   instance B
   - childOfHero                 []                          instance B
 - someOtherEditor               []                          instance A
@timruffles
timruffles / recursive-change.js
Created May 17, 2016 19:43
(tail) recursive solution to giving change
"use strict";
/**
* The function will use a Greedy method to solve the problem of giving
* change.
*
* @param {Integer} the amount for which we have to give change
* @param {Array} the values of the coins that are available
*
* @return {Array} the list of the selected coins, sorted ascending by value,
@timruffles
timruffles / README.md
Created March 17, 2016 14:25
npm readme.md template

PROJECT_NAME

PROJECT_NAME is XXX.

Installation

npm install --save PROJECT_NAME
@timruffles
timruffles / attack.md
Last active November 21, 2020 17:35
Chrome/Gmail attack received 11/03/2016. Not sure if the Chrome meta refresh + data:text,html technique is novel.

The following attack will display a "you've been signed out" page for GMail, and attempt to steal your account credentials.

DO NOT PUT ANY ACCOUNT CREDENTIALS INTO ANY TABS CREATED AFTER VISITING THESE LINKS :)

I received an email in my GMail inbox with a fake attachment image, styled to look like the real GMail attachment UI:

fake

This linked to a page that ended up displaying a fake "you've been signed out" link, via the data:text/html... URL feature of Chrome:

@timruffles
timruffles / deploy.sh
Last active June 22, 2018 19:01
pure bash provisioning - node + postgres on ubuntu 15.10. Whole /deployment directory has been scp'd to machine, containing all config files etc
#!/bin/bash
# run on source machine to build and then copy over
set -eo pipefail
main() {
if [[ -z $SKIP_BUILD ]]; then
grunt build
fi
@timruffles
timruffles / nestedLooper.js
Last active February 26, 2016 11:51
arbitrarily deep nested loops over hierarchical data
// takes a collection, a variable length list of fns, and a function
//
// for each item in the collection the list of fns that returns a value or values
// is called, with the output from the first function being threaded into the second.
//
// it won't blow the stack.
//
// e.g
//
// util.nestedLoops([ { items: [{ name: "bob"}, {name: "sue"}] } ], _.property("items"), _.property("name"), function(group, item, name) {
@timruffles
timruffles / readQuoted.js
Created December 15, 2015 12:01
reads strings like `" 'hello I am string one', \"i'm string two\" 'cool ' "` into `["hello I am string one", "i'm string two", "cool "]`
// read a list of strings which are enclosed in quotes. ignores whitespace (= anything outside quotes)
function readQuoted(s) {
var i = 0;
var quote = false;
var strs = [];
var str = "";
var c;
while(c = s[i++]) {
if(quote) {
@timruffles
timruffles / angular-named-element.js
Created December 7, 2015 16:22
if a directive has a need to collaborate with an element up the tree, use this to make that relationship explicit and testable
/**
* if a directive has a need to collaborate with
* an element up the tree, use this to make that
* relationship explicit and testable
*
* ```html
* <div named-element="someCtrl.someElement">
* </div>
* <some-crazy-component element="someCtrl.someElement">
* </some-crazy-component>