Skip to content

Instantly share code, notes, and snippets.

View mtford90's full-sized avatar

Michael Ford mtford90

View GitHub Profile
enum MyEnum {
/* ... */
}
function stringToEnum(str: string): MyEnum | undefined {
return new Map(Object.entries(MyEnum)).get(str)
}
@mtford90
mtford90 / run.sh
Last active February 22, 2023 14:27
Running Ethereum wallet in light mode on Mac OSX
# Install ethereum
brew tap ethereum/ethereum
brew install ethereum
# Run a light ethereum node
geth --syncmode="light"
# Open wallet in light mode (will need to install wallet from github first)
open -n /Applications/Ethereum\ Wallet.app --args -node-light
function rgba (hex, opacity) {
return `rgba(${hexToR(hex)}, ${hexToG(hex)}, ${hexToB(hex)}, ${opacity})`
}
function hexToR (h) {return parseInt((cutHex(h)).substring(0, 2), 16)}
function hexToG (h) {return parseInt((cutHex(h)).substring(2, 4), 16)}
function hexToB (h) {return parseInt((cutHex(h)).substring(4, 6), 16)}
function cutHex (h) {return (h.charAt(0) == "#") ? h.substring(1, 7) : h}
@mtford90
mtford90 / gist:f09924dcaf329aafd142
Last active August 29, 2015 14:18
resizeToFit angular directive
angular.module('farm4trade')
.directive('resizeToFit',
function() {
return {
restrict: 'EA',
replace: false,
transclude: true,
link: function(scope, elem) {
var $parent = $(elem[0]),
$span = $parent.find('.resize'),

Useful Links

Random stuff that would be useful in making a (much better) Pocket alternative

Libraries

Content Extraction

  • readability.js - a JS library that performs text extraction
  • goose - a mature content/article extractor in scala
var myAPI = {
doSomeShit: function (cb) {
// Need to preserve the binding of cb,
// but you can't do cb.this - there's no way to find out what it's bound to
cb.call(cb.this, 'arg1', 'arg2')
}
};
function MyClass() {
this.shitIsDone = false;
var oldOn = siesta.events.on;
siesta.events.on = function (event, fn) {
oldOn.call(siesta.events, event, function (e) {
$rootScope.$apply(function () {
fn(e);
})
});
}
function Something() {
_.extend(this, {
attr: 1,
_extras = {},
__setattr__: function (key, value) {
this._extras[key] = value;
},
__getattr__: function (key) {
return this._extras[key] || 'That attribute doesnt exist yet!';
}
Car = Collection.model('Car', {
id: 'id',
attributes: ['colour'],
properties: {
blah: {
get: function () {
return this.colour ? this.colour.toUpperCase() : this.colour;
},
// Workaround for chrome.
var LETTERS = 'acdegilmnoprstuw';
/**
* The provided hash function with additional logging
* @param s
* @returns {number}
*/
function hash(s) {
var h = 7;
for (var i = 0; i < s.length; i++) {