Skip to content

Instantly share code, notes, and snippets.

Kindle Son Status Board

An e-ink status board so my mum knows what's up

Stack

Node:

@codeincontext
codeincontext / persistent_keychain_mock.js
Created November 26, 2015 16:17
An ngCordova mock for the keychain that persists values with localstorage
/**
* Overriding the keychain ngCordovaMock to use localStorage
**/
angular.module('ngCordovaMocks')
.factory('$cordovaKeychain', ['$q', function ($q) {
console.log('persistent keychain mock loaded')
return {
getForKey: function (key, serviceName) {
// note: this implementation doesn't fail on an invalid servicename

Keybase proof

I hereby claim:

  • I am skattyadz on github.
  • I am adz (https://keybase.io/adz) on keybase.
  • I have a public key whose fingerprint is 5AE7 65BA 4634 6D42 A08A 77E8 E1D9 AC48 59B2 2D32

To claim this, I am signing this object:

@codeincontext
codeincontext / gist:1979a8f13d1ef47a8b76
Created September 14, 2015 09:15
Page element watcher with scheduler and logging
# page-element-watcher
#
# Checks the contents of an element on a remote page and sends an SMS if it has changed
require 'nokogiri'
require 'open-uri'
require 'redis'
require 'twilio-ruby'
require 'rufus-scheduler'
@codeincontext
codeincontext / fix-pg.sh
Created August 16, 2015 16:00
temporary hack to deal with an ever-changing pg port (should link instead)
postgresql_id=$(docker ps | grep jeffutter/postgresql:latest | awk '{print $1}')
postgresql_private_ip=$(docker inspect ${postgresql_id} | grep IPAddress | awk '{ print $2 }' | tr -d ',"')
echo "pg ip: $postgresql_private_ip"
dokku config:set fun.with.co.de PG_HOST=$postgresql_private_ip
dokku config:set scotch.watch PG_HOST=$postgresql_private_ip
@codeincontext
codeincontext / page-element-watcher.rb
Created August 13, 2015 12:54
Check the contents of an element on a remote page and send an SMS if it has changed
# page-element-watcher
#
# Checks the contents of an element on a remote page and sends an SMS if it has changed
require 'nokogiri'
require 'open-uri'
require 'redis'
require 'twilio-ruby'
@codeincontext
codeincontext / gist:15784828067029c27038
Last active August 29, 2015 14:24
Quick and dirty translation helper
currentLocale = 'en';
locales = {
en: {
'common.between': 'less than __ but more than __'
}
};
t = function(key, ...insertions) {
let translatedString = locales[currentLocale][key];
return translatedString.replace(/__/g, () => insertions.shift());
@codeincontext
codeincontext / christmas.js
Last active December 31, 2015 17:39
MERRY CHRISTMAS!
w=console.log.bind(console),t=13,l=0,s=function(b,c){return new Array(b).join(c)};
f=function(){clear();l=!l;w('\u001B[2J\u001B[0;0f');w(s(t-1,' ')+(l?'\\ /':''));w(s(t-3,' ')+(l?'-->*<--':' .'));
for(i=1;i<t;i++){w(s(t-i,' ')+'/'+s(i,'_'+(i%2?'/':'\\'))+'_\\')}w(s(t-2,' ')+'[___]');setTimeout(f,600)};f()
@codeincontext
codeincontext / gist:6710863
Last active December 23, 2015 23:38
The one-electron theory
I think the one-electron theory is my favourite physics theory. It's something I was taught that's come around on Hacker News recently https://en.wikipedia.org/wiki/One-electron_universe
**It involves a thought experiment.**
Imagine making jelly *(jello, if you're in the states)* with a load of string looped around, bundled, and set in it like a big suspended knot. Taking a cross-section of the jello will show a load of identical dots. They're seemingly un-connected, but _we know there's just one string they came from_.
Now extrapolate this out and imagine that the jelly is space-time, and any slice is our 3D world at a given time. Because we're bound by time we can only see one slice at a time. It seems to us that there are always a lot of identical dots - and we naturally assume each is a separate thing.
The one-electron theory asks whether this could be how we're perceiving electrons. Could there be one electron whizzing about space and time. At any given time, it would appear to us in multiple places
@codeincontext
codeincontext / gist:6708684
Created September 26, 2013 01:35
Look how easy it is to build a deck of cards in Elixir! Example shamelessly taken from "Programming Elixir", which you should definitely buy
import Enum
# build a deck of cards
deck = lc rank inlist '23456789TJQKA', suit inlist 'CDHS', do: [suit, rank]
# -> ['C2', 'D2', 'H2', 'S2', 'C3', 'D3', ... ]
# take 5 random cards from the deck
hand = deck |> shuffle |> take(5)
# -> ['D8', 'CQ', 'H2', 'H3', 'HK']