Skip to content

Instantly share code, notes, and snippets.

Bare ruin'd choirs, where late the sweet birds sang

Ben Shimmin benshimmin

Bare ruin'd choirs, where late the sweet birds sang
View GitHub Profile

Keybase proof

I hereby claim:

  • I am benshimmin on github.
  • I am benshimmin ( on keybase.
  • I have a public key ASBE3mlv4vBeRu2K3_PP63iNCM1RyV2Xx9pwCUI4QT0xSwo

To claim this, I am signing this object:

benshimmin /
Last active Dec 23, 2021
How to render a web page into a multi-page PDF with html2canvas and jsPDF
# Assumptions:
# 1. $("#pdf-download") is something you can click on (not really required).
# 2. $(".result-page") is something in your existing page that you want to turn into a PDF.
# 3. You want to add a class of `pdf-rendered` to it and then specify some CSS which applies when that class is added.
# 4. Your CSS for `.pdf-rendered` specifies a useful width for a PDF (795px is pretty good) and anything else you like
# (this is for portrait ("p") PDFs; obviously you'll need to make a few modifications for landscape PDFs!).
# How it works:
# 1. Take the requested element in your existing page, clone it, add a "pdf-rendered" class to it, and append to
# the body.
benshimmin / enums.rb
Last active Apr 18, 2016
Enums with Rails Admin
View enums.rb
# This might not be the best way, it might be improved in more
# recent versions of Rails Admin, but this seems to work okay
# for me.
class SomeModel < ActiveRecord::Base
enum :some_enum => {
:some_key => 0
benshimmin / nyt.js
Created Aug 23, 2015
Defeat the New York Times paywall
View nyt.js
javascript:(function(){Backbone.$("#supercontainer").hide();Backbone.$("body").attr("style", "overflow : visible !important");})();
benshimmin / rails_admin_dsl.rb
Last active Aug 29, 2015
Code reuse in the Rails Admin DSL
View rails_admin_dsl.rb
class Foo < ActiveRecord::Base
def self.fields(something = false)
-> (model) {
field :bar
field :baz
field :woof
if something
field :something_else
benshimmin / pathformer.js
Last active Mar 19, 2018
Turn Vivus' pathformer into a tiny CLI utility
View pathformer.js

You need Node, obviously, and JSDom. Then use it like this:

$ ./pathformer.js test.svg > test.out.svg

benshimmin /
Last active Aug 29, 2015
Peter Norvig's famous spelling corrector, in CoffeeScript (with Underscore)
# A CoffeeScript version of
[fs, _] = [require("fs"), require("underscore")]
words = (text) -> text.toLowerCase().match /[a-z]+/g
train = (features) ->
model = {}
_.each features, (f) -> if model[f] then model[f] += 1 else model[f] = 1
benshimmin / gist:4f5a984b5dd09ff7ca29
Created Dec 18, 2014
Remove overlay on
View gist:4f5a984b5dd09ff7ca29
$(".modal-backdrop, .modal").hide();$("body").css("overflow","auto");
benshimmin / solver.js
Last active Aug 29, 2015
How to solve The Times 2 "Polygon" puzzle
View solver.js
#!/usr/bin/env node
// This should solve the "Polygon" puzzle in The Times 2 "MindGames".
// Assumes a *nix system with the usual dictionary of words in the usual
// place.
// A few of the rules for what words count are a bit complicated... you could
// probably extend this with a Porter Stemmer, if you cared enough.
var fs = require("fs"),
readline = require("readline"),
View gist:8da42a687eae6e47f30d
look at love
how it tangles
with the one fallen in love
look at spirit
how it fuses with earth
giving it new life
why are you so busy
with this or that or good or bad