Skip to content

Instantly share code, notes, and snippets.

@jamesduncombe
jamesduncombe / svgripper.rb
Last active Mar 30, 2016
Quick and dirty SVG icon spriter
View svgripper.rb
#!/usr/bin/env ruby
#
# Sprites SVG icons into a single output
#
# Sample output which you'd put in the page:
#
# <svg version="1.1" xmlns="http://www.w3.org/2000/svg" style="display: none;">
# <symbol id="icon-name" viewBox="0 0 76.7 89.6">
# <path d="M71.2,28.1c-3,0-5.5,2.5-5.5" />
# </symbol>
View .docker-aliases
alias dc="docker"
alias dr="dc run"
alias ds="dc stop"
alias di="dc images"
alias drmi="dc rmi"
alias drm="dc rm"
alias dip="dc inspect -f '{{ .NetworkSettings.IPAddress }}'"
@jamesduncombe
jamesduncombe / haversine.sql
Last active Aug 29, 2015
Haversine formula in SQL
View haversine.sql
/*
6371 for Kms
3956 for Miles
$lat, $lng are passed in
*/
SELECT *,
( 3956 * acos( cos(radians($lat)) * cos(radians( lat.field_latitude_value )) *
cos(radians( lng.field_longitude_value ) - radians($lng)) + sin(radians($lat))
* sin(radians( lat.field_latitude_value )) ) )
@jamesduncombe
jamesduncombe / base64.go
Last active Aug 29, 2015
Quick base64 convertor in Go
View base64.go
package main
import (
"encoding/base64"
"flag"
"fmt"
"io/ioutil"
"mime"
"path/filepath"
"strings"
View silly
SELECT users.username,
((CASE WHEN quizzes.quiz_type = 1 THEN 'M' ELSE 'B' END) ||
(CASE WHEN user_answers.practical_id IS NULL THEN '' ELSE 'P' END) ||
quizzes.challenge_number || 'Q' || questions.question_number)
AS quest,
SUM(result) As score
FROM "user_answers"
INNER JOIN "users" ON "users"."id" = "user_answers"."user_id"
@jamesduncombe
jamesduncombe / vocab_parser.js
Last active Aug 29, 2015
Duolingo vocab parser for Words page
View vocab_parser.js
/* Pulling out vocab from Duolingo's Words page */
var raw,
cleaned,
filtered,
xhr = new XMLHttpRequest;
var parser = function(data) {
raw = JSON.parse(data);
cleaned = raw.vocab_overview.filter(function(word) {
@jamesduncombe
jamesduncombe / rename.sh
Last active Aug 29, 2015
How to batch rename...
View rename.sh
# rename all scss files...
find *.scss | xargs -I file sh -c 'mv file $(basename file | sed 's/scss/sass/')'
@jamesduncombe
jamesduncombe / erb2slim.sh
Last active Aug 29, 2015
ERB to Slim command
View erb2slim.sh
gem install html2haml && gem install haml2slim
# then... convert and remove original erb files:
find ./app/views -name '*.erb' | xargs -I file sh -c \
'html2haml --erb file | haml2slim > $(echo file | sed 's/erb/slim/') && \
rm file'
@jamesduncombe
jamesduncombe / jpeg_smash.rb
Created Jul 1, 2014
JPEG Smash but in Ruby...
View jpeg_smash.rb
#!/usr/bin/env ruby
require 'optparse'
options = {}
# Markers
JPEG_START = 'ffda'
JPEG_END = 'ffd9'
OptionParser.new do |opts|
@jamesduncombe
jamesduncombe / testing_erlang.erl
Last active Aug 29, 2015
Playing with Erlang
View testing_erlang.erl
#!/usr/bin/env escript
main(_) ->
List = [1,2,3,4,5,6,7,8,9],
NewList = reverse(List),
io:format(NewList),
shifter("This should not pass correctly"),
%% list comprehension, because they are cool in Erlang
Comprehended = [ N bsl 4 || N <- List, N =/= 1 ],