Skip to content

Instantly share code, notes, and snippets.

View timruffles's full-sized avatar

Tim Ruffles timruffles

View GitHub Profile
@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>
@timruffles
timruffles / normalizeCoordinates.js
Created October 22, 2015 15:50
normalizes a set of positive coordinates to 0..1
function normaliseCoordinates(asObjects) {
var dimensions = {
x: [Infinity, -Infinity],
y: [Infinity, -Infinity],
}
var axisToDeltas = {
x: "width",
y: "height",
};
@timruffles
timruffles / google-sheets-formula.vb
Last active January 25, 2022 11:24
google sheets - uk stamp duty calculator, new rate (2015)
// put this into a cell and then name a range 'housePrice'
=MIN(MAX(0,housePrice-250000),250000-125000)*0.02 + MIN(MAX(0,housePrice - 250000), 925000-250000) * 0.05 + MIN(MAX(0,housePrice - 9250000), 1500000-925000) * 0.1
@timruffles
timruffles / svg-html-entities.js
Created May 27, 2015 08:29
svg - supporting HTML entities, to avoid 'entity not defined' when you're exporting SVGs from the browser
// create a doctype that includes definitions for all HTML entities - http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
var doctype = '<?xml version="1.0" standalone="no"?>' +
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ '
+ HTML_ENTITIES() + ' ]>';
function HTML_ENTITIES() {
return '<!ENTITY quot "&#34;"> <!ENTITY amp "&#38;"> <!ENTITY apos "&#39;"> <!ENTITY lt "&#60;"> <!ENTITY gt "&#62;"> <!ENTITY nbsp "&#160;"> <!ENTITY iexcl "&#161;"> <!ENTITY cent "&#162;"> <!ENTITY pound "&#163;"> <!ENTITY curren "&#164;"> <!ENTITY yen "&#165;"> <!ENTITY brvbar "&#166;"> <!ENTITY sect "&#167;"> <!ENTITY uml "&#168;"> <!ENTITY copy "&#169;"> <!ENTITY ordf "&#170;"> <!ENTITY laquo "&#171;"> <!ENTITY not "&#172;"> <!ENTITY shy "&#173;"> <!ENTITY reg "&#174;"> <!ENTITY macr "&#175;"> <!ENTITY deg "&#176;"> <!ENTITY plusmn "&#177;"> <!ENTITY sup2 "&#178;"> <!ENTITY sup3 "&#179;"> <!ENTITY acute "&#180;"> <!ENT