Skip to content

Instantly share code, notes, and snippets.

View benshimmin's full-sized avatar
🇪🇺
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 (https://keybase.io/benshimmin) on keybase.
  • I have a public key ASBE3mlv4vBeRu2K3_PP63iNCM1RyV2Xx9pwCUI4QT0xSwo

To claim this, I am signing this object:

@benshimmin
benshimmin / pdf.coffee
Last active December 23, 2021 01:19
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
benshimmin / enums.rb
Last active April 18, 2016 07:36
Enums with Rails Admin
# 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
benshimmin / nyt.js
Created August 23, 2015 19:44
Defeat the New York Times paywall
javascript:(function(){Backbone.$("#supercontainer").hide();Backbone.$("body").attr("style", "overflow : visible !important");})();
@benshimmin
benshimmin / rails_admin_dsl.rb
Last active August 29, 2015 14:25
Code reuse in the Rails Admin DSL
class Foo < ActiveRecord::Base
def self.fields(something = false)
-> (model) {
field :bar
field :baz
field :woof
if something
field :something_else
@benshimmin
benshimmin / pathformer.js
Last active January 24, 2024 06:54
Turn Vivus' pathformer into a tiny CLI utility

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

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

@benshimmin
benshimmin / spelling_corrector.coffee
Last active August 29, 2015 14:11
Peter Norvig's famous spelling corrector, in CoffeeScript (with Underscore)
# A CoffeeScript version of http://norvig.com/spell-correct.html
[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
model
@benshimmin
benshimmin / gist:4f5a984b5dd09ff7ca29
Created December 18, 2014 11:44
Remove overlay on duedil.com
$(".modal-backdrop, .modal").hide();$("body").css("overflow","auto");
@benshimmin
benshimmin / solver.js
Last active August 29, 2015 14:10
How to solve The Times 2 "Polygon" puzzle
#!/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"),
@benshimmin
benshimmin / gist:8da42a687eae6e47f30d
Last active August 29, 2015 14:09
"Look at love" - Rumi
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