Skip to content

Instantly share code, notes, and snippets.

View mloughran's full-sized avatar

Martyn Loughran mloughran

View GitHub Profile
@mloughran
mloughran / pwned.rb
Created December 4, 2020 17:37
Interactive tool to check passwords against the HIBP API
require 'digest/sha1'
require 'net/http'
API_ROOT = "https://api.pwnedpasswords.com/range/"
def split_sha(password)
sha = Digest::SHA1.hexdigest(password).upcase
[sha[0...5], sha[5..]]
end
@mloughran
mloughran / getting-started.md
Last active May 24, 2019 12:40
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!
https://guide.elm-lang.org

I found this example helpful as an example of piecing everything together after reading the guide
http://elm-bootstrap.info/getting-started

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 (https://keybase.io/mloughran) on keybase.
  • I have a public key ASCoOglpsX51BeVmxe0-db0fDe6iBgqtYlN2KKCtMcg_sgo

To claim this, I am signing this object:

@mloughran
mloughran / .gitignore
Last active January 1, 2016 05:49
Comparison of using run time & memory usage to run a ruby script that requires a single gem (which does nothing) then exits.
.bundle
bundle
vendor
@mloughran
mloughran / Gemfile
Created August 15, 2012 19:33
em-http-request not closing connections (v 1.0.2)
source :rubygems
gem 'eventmachine', '1.0.0.rc.4'
gem 'em-http-request', '1.0.2'
gem 'sinatra'
gem 'thin'
@mloughran
mloughran / gist:2837064
Created May 30, 2012 15:39
Two state deferrable synchronisation primitive, in need of a name
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
mloughran / page.html
Created March 16, 2012 19:27
Mobile Safari crash when returning to WebSocket page
<html>
<head>
<script>
function debug(string) {
var element = document.getElementById("debug");
var p = document.createElement("p");
p.appendChild(document.createTextNode(string));
element.appendChild(p);
}
@mloughran
mloughran / gist:1382605
Created November 21, 2011 13:21
Potential async transaction api for em-hiredis
require 'em-hiredis'
class EM::Hiredis::Client
class Transaction
include EM::Deferrable
def initialize(redis)
@redis = redis
end
@mloughran
mloughran / fiber_cache.rb
Created November 4, 2011 19:36
Proof of concept Redis cache, which blocks fiber if required on access
require 'eventmachine'
require 'em-hiredis'
require 'fiber'
class Cache
include EM::Deferrable
def initialize(key)
$redis.get(key) { |v|
@value = v
@mloughran
mloughran / Gemfile
Last active September 27, 2015 17:48
Firefox orphaned WebSocket connection testcase
source :rubygems
gem 'em-websocket'
gem 'sinatra'