Skip to content

Instantly share code, notes, and snippets.

Avatar
💀
a momentary diversion on the road to the grave

Murray Steele h-lame

💀
a momentary diversion on the road to the grave
View GitHub Profile
@h-lame
h-lame / benchmark.rb
Created Jul 20, 2017
Benchmarking some alternate implementations for checking if a BOM is present in a string and removing it.
View benchmark.rb
require 'benchmark'
# you'll want this to be a largeish file that is representative of the kinds
# of CSS files you'll be using this on in the real world. I used a compiled
# version of application.css from https://github.com/alphagov/government-frontend
css = File.binread "bom.css"
class BomBench
def remove_bom_force_encoding_slice!(input)
input.force_encoding('UTF-8').slice!(0)
@h-lame
h-lame / bom-removal.rake
Created Jun 30, 2017
Rake task to hook into assets:precompile in a rails app and remove any BOMs that are inserted by sprockets/sass in CSS files (and their gzipped siblings)
View bom-removal.rake
namespace :assets do
task :remove_bom => :environment do
require 'sprockets/utils/gzip'
# object that has enough of the Sprockets::Asset API to be
# used in the Sprockets::Utils::Gzip class without us needing
# to use the real class which needs more data
class DeBOMedCSSAsset < Struct.new(:file_name)
def content_type
'text/css'
@h-lame
h-lame / Slide 11: my first ruby.diff
Last active Nov 8, 2016
My First Ruby - code snippets from slides - see: http://h-lame.com/talks/my-first-ruby/
View Slide 11: my first ruby.diff
@ -24,8 +24,8 @@ class Config < Hash
}
end
- def initialize(name)
- self[Config::Name] = name
+ def initialize(name=nil)
+ self[Config::Name] = name if name != nil
end
@h-lame
h-lame / gist:8fb54e83aa514bb78f77
Last active Aug 29, 2015
*OFFER CLOSED* [LRUG] [GIVEAWAY] Copies of "The Well Grounded Rubyist (2nd Edition)" to give away
View gist:8fb54e83aa514bb78f77
From: Murray Steele <murray.steele@lrug.org>
To: London Ruby Users Group <chat@lrug.org>
Subject: [LRUG] [GIVEAWAY] Copies of "The Well Grounded Rubyist (2nd Edition)" to give away
Hi all,
As announced at the start of the meeting on Monday the nice folks at
Infinitium Global have decided to give a little back to the community in
some way. One thing they were keen for is that they were giving back to
the community in a way that would help it grow and encourage folk just
View after.rb
def find_previous_table_for(element)
find_previous_sibling_of_type(element, 'table')
end
def find_previous_sibling_of_type(element, element_type_to_find)
previous_siblings(element).find do |previous_element|
previous_element.node_name == element_type_to_find
end
end
@h-lame
h-lame / bwt.rb
Last active Aug 29, 2015
Implementation of a Burrows-Wheeler Transform, as guided by https://github.com/zetter/burrows-wheeler-transform
View bwt.rb
class BWT
def encode(string)
chars = "#{string}$".chars
rotations = []
chars.length.times.
inject(chars) do |new_chars, _|
rotations << new_chars
new_chars.rotate
end
View keybase.md

Keybase proof

I hereby claim:

  • I am h-lame on github.
  • I am hlame (https://keybase.io/hlame) on keybase.
  • I have a public key whose fingerprint is 39B4 6B57 2042 0DED F0F4 8D1C 770E BCE3 52EA C8EA

To claim this, I am signing this object:

View showterm-replacement.html
<html>
<head>
<style>
pre.terminal {
display: block;
background-color: black;
color: white;
font-family: monospace;
height: 480px;
width: 640px;
View scrabble_spec.rb
module Scoring
def self.included(base)
base.class_eval do
let(:__score_keeper) { ScoreKeeper.new }
extend ScoreHelpers
include ScoreMatchers
end
end
class ScoreKeeper