Skip to content

Instantly share code, notes, and snippets.


Martyn Loughran mloughran

View GitHub Profile
mloughran / pwned.rb
Created Dec 4, 2020
Interactive tool to check passwords against the HIBP API
View pwned.rb
require 'digest/sha1'
require 'net/http'
def split_sha(password)
sha = Digest::SHA1.hexdigest(password).upcase
[sha[0...5], sha[5..]]
mloughran /
Last active May 24, 2019
Suggestions for getting started with Elm

Learning Elm

Start by following the guide from start to finish. It's really clear and written by Evan, Elm's author. Do the exercises!

I found this example helpful as an example of piecing everything together after reading the guide

Don't worry about modules or splitting stuff into separate files. This advice is oft repeated in the Elm community and it's absolutely correct. The patterns that work in Elm aren't the patterns that work in other languages, and if you split modules out too early you'll make it harder to get a sense of the right module abstractions. Refacting is a breeze so you can modularise later. (See /The life of a file/ below).


Keybase proof

I hereby claim:

  • I am mloughran on github.
  • I am mloughran ( on keybase.
  • I have a public key ASCoOglpsX51BeVmxe0-db0fDe6iBgqtYlN2KKCtMcg_sgo

To claim this, I am signing this object:

mloughran / .gitignore
Last active Jan 1, 2016
Comparison of using run time & memory usage to run a ruby script that requires a single gem (which does nothing) then exits.
View .gitignore
mloughran / Gemfile
Created Aug 15, 2012
em-http-request not closing connections (v 1.0.2)
View Gemfile
source :rubygems
gem 'eventmachine', '1.0.0.rc.4'
gem 'em-http-request', '1.0.2'
gem 'sinatra'
gem 'thin'
mloughran / gist:2837064
Created May 30, 2012
Two state deferrable synchronisation primitive, in need of a name
View gist:2837064
require 'eventmachine'
# Allows calling set/clear at will, and ensures that only a single on_set or
# on_clear deferrable is running concurrently. It also ensures that
# un-necessary callbacks are not run, i.e. set-unset-set in sequency only
# requires the on_set callback to run once
# The blocks/procs supplied for on_set and on_clear must return deferrables
class Thing
mloughran / page.html
Created Mar 16, 2012
Mobile Safari crash when returning to WebSocket page
View page.html
function debug(string) {
var element = document.getElementById("debug");
var p = document.createElement("p");
mloughran / gist:1382605
Created Nov 21, 2011
Potential async transaction api for em-hiredis
View gist:1382605
require 'em-hiredis'
class EM::Hiredis::Client
class Transaction
include EM::Deferrable
def initialize(redis)
@redis = redis
mloughran / fiber_cache.rb
Created Nov 4, 2011
Proof of concept Redis cache, which blocks fiber if required on access
View fiber_cache.rb
require 'eventmachine'
require 'em-hiredis'
require 'fiber'
class Cache
include EM::Deferrable
def initialize(key)
$redis.get(key) { |v|
@value = v
mloughran / Gemfile
Last active Sep 27, 2015
Firefox orphaned WebSocket connection testcase
View Gemfile
source :rubygems
gem 'em-websocket'
gem 'sinatra'