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
@benshimmin
benshimmin / gist:2820024
Last active October 5, 2015 14:18
Custom labels for Google Maps
class Label extends google.maps.OverlayView
constructor : (options) ->
@setValues options
@span = document.createElement "span"
@div = document.createElement "div"
@div.appendChild @span
# helpful for styling later
$(@div).addClass "label"
@benshimmin
benshimmin / gist:2948804
Created June 18, 2012 15:04
Plotting a line of best fit using linear regression in CoffeeScript with Raphael JS
$ ->
new ScatterGraph "scattergraph"
class ScatterGraph
constructor : (target) ->
@paper = Raphael target
bg = @paper.rect 0, 0, 500, 500
bg.attr
@benshimmin
benshimmin / gist:3238456
Created August 2, 2012 16:36
How to extract all links and link text from a Markdown file using pandoc
-- adapted from <http://johnmacfarlane.net/pandoc/scripting.html>
import Text.Pandoc
import Text.Pandoc.Shared (stringify)
extractURL :: Inline -> [String]
extractURL (Link txt (u,_)) = [stringify txt ++ " : <" ++ u ++ ">"]
extractURL (Image _ (u,_)) = [u]
extractURL _ = []
extractURLs :: Pandoc -> [String]
@benshimmin
benshimmin / base.coffee
Created August 13, 2012 16:09
CoffeeScript classes and Node.js
class ApplicationBase
constructor : (arg1, arg2) ->
# do something with arg1, arg2
@init()
init : => # override this
@benshimmin
benshimmin / gist:3380146
Created August 17, 2012 16:00
Search for a process called {searchterm} and kill it if it exists
#!/bin/bash
# The secret is to use the word boundary in the regex so it doesn't
# return the grep process too.
# Then use awk to extricate the second column of the match.
# Capture that as $PID and kill -9 it (if it exists).
PID=`ps auxww | grep -E "\\bsearchterm" | awk '{ print $2 }'`
if [ $PID ]; then
@benshimmin
benshimmin / gist:3477662
Created August 26, 2012 11:16
How to create an HTML character entity in CSS generated content
// Because I always forget...
//
// In general:
//
// 1) Search for "<symbol you want> html unicode" or similar.
// 2) Replace u+ with a \
// 3) Profit.
//
// Example (a &middot; before a link):
@benshimmin
benshimmin / accordion.coffee
Created August 26, 2012 14:08
A definition list accordion in three lines of CoffeeScript with jQuery
$("dl.mini-accordion dt").on "click", ->
$(@).parent().find("dt, dd").removeClass("is-open")
$.each [ $(@), $(@).next() ], (i, e) -> $(e).addClass("is-open")
@benshimmin
benshimmin / carousel.coffee
Last active October 9, 2015 10:27
Ridiculous jQuery carousel, in CoffeeScript - supports "blobs" and a timer
@benshimmin
benshimmin / gist:3496915
Created August 28, 2012 10:16
Normalize.css v2 in Sass (quick and dirty and without comments)
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
nav,
section,
@benshimmin
benshimmin / gist:3617435
Created September 4, 2012 06:01
How to read a drag-and-dropped file line by line (works in Chrome at least)
# I needed to handle CSV files exported from Excel. The following madness ensued.
# (I actually thought this would be easier than handling it on the server.
# How wrong I was.)
#
# Summary:
# Most of the FileReader.read* methods will - in Chrome at least - give you a string
# without line-breaks. This is basically useless when you're working with a CSV file.
# However, if you read the data as an ArrayBuffer, you can actually see the line-breaks
# and create lines that way.
#