Skip to content

Instantly share code, notes, and snippets.

@jamesduncombe
jamesduncombe / svgripper.rb
Last active March 30, 2016 17:52
Quick and dirty SVG icon spriter
#!/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>
@jamesduncombe
jamesduncombe / jpeg_smash.rb
Created July 1, 2014 20:47
JPEG Smash but in Ruby...
#!/usr/bin/env ruby
require 'optparse'
options = {}
# Markers
JPEG_START = 'ffda'
JPEG_END = 'ffd9'
OptionParser.new do |opts|
@jamesduncombe
jamesduncombe / Working-3D-flip.markdown
Created December 17, 2013 23:38
A Pen by James Duncombe.
class FakerNames
FIRST_NAMES = %w(James Nathan Stew John Ben Adrian Will George)
LAST_NAMES = %w(Smith Goddard Duncombe Harrason Mandela James Boom Johnson)
attr_accessor :used_combos, :used_first_names, :used_last_names
def initialize
@used_combos = []
@used_first_names = []
@jamesduncombe
jamesduncombe / pagination.php
Last active December 20, 2015 17:59
Pagination with MySQL and PHP
<?php
/**
* Handling offsets for articles in series using PHP and MySQL
* pages is the table for articles
*/
$number_of_articles_per_page = 10;
$page = 1;
@jamesduncombe
jamesduncombe / array_operators.rb
Last active December 18, 2015 13:09
Ruby's array operators - Intersection, Union and Difference
# Ruby's Array operators
a = 1,2,3,4
b = 2,3,4,5
# Intersection
a & b # => [2, 3, 4]
# Union
a | b # => [1, 2, 3, 4, 5]
@jamesduncombe
jamesduncombe / mkspin.rb
Created February 23, 2013 14:34
Simple little script to keep my external drive spinning as it likes to go to sleep... lots...
#!/usr/bin/env ruby
#
# Keep the external drive spining!
#
require 'fileutils'
# set the name of the file to write
FILE = '/Volumes/Drive_Name/.stayawake'
@jamesduncombe
jamesduncombe / xml_to_json_array.rb
Created October 4, 2012 17:51
Script to convert a series of XML documents into an Array of Hashes then to a JSON file
#
# Read a series of XML documents into a large Array of Hashes
# export as JSON
#
# assign some constants to handle file names / paths
PATH_TO_XML_FILES, EXPORT_FILE = ARGV.first, ARGV.last
# argument validation
raise ArgumentError, 'You must specify a path from which to read the XML documents' if PATH_TO_XML_FILES.nil?
@jamesduncombe
jamesduncombe / .docker-aliases
Created September 2, 2015 15:26
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 August 29, 2015 14:11
Haversine formula in 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 )) ) )