Skip to content

Instantly share code, notes, and snippets.

Chris Parsons chrismdp

Block or report user

Report or block chrismdp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:bba955ce15777516f185a92a87dd2e4b
def assert_equal(expected, actual)
print expected == actual ? "." : "Expected #{expected}, but got #{actual}\n"
class PriceRule
def initialize(code, price)
@code = code
@price = price
chrismdp / plus.rb
Created Oct 3, 2018
Plus / Sandwich solution
View plus.rb
def plus(num)
(1..num) {|x| yield(x) }.join
p plus(3) { "ding" }
p plus(3) { |x| "...#{x}" }
p plus(5) { |x| (x + 2).to_s }
def sandwich(layers = 1, &block)
View -
def assert_equal(expected, actual)
print expected == actual ? "." : "Expected #{expected.inspect} but got #{actual.inspect}\n"
Discount =, :value) do
def apply(basket, item)
(basket.count(item)/amount) * value
chrismdp /
Last active Jun 7, 2017
ImagicMagick + Shell script to generate my Kickstarter reward chart on this campaign:
# A colon-seperated rewards list.
# First column is the type of reward:
# <text> - a text number.
# Columns are alpha divisor (eg 4 is 25%), percentage complete, big number, smaller label and text description.
View checkout.rb
def assert_equal(expected, actual)
print expected == actual ? "." : "Expected #{expected.inspect} but got #{actual.inspect}\n"
class SummingRule
def initialize(item, price)
@item = item
@price = price
View t.rb
class Checkout
def initialize
@total = 0
PRICES = { "Apple" => 30, "Banana" => 50 }
def scan(item)
@total += PRICES[item]
chrismdp /
Last active Jan 22, 2020
Uploading to S3 in 18 lines of Shell (used to upload builds for
# You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
# This is how I upload my new Sol Trader builds (
# Based on a modified script from here:
S3KEY="my aws key"
S3SECRET="my aws secret" # pass these in
function putS3
chrismdp /
Last active Dec 28, 2015
Script to grab one of the 10 more recent images from Unsplash, and tint and blur it for use as an iTerm background using Solarized Dark
# NOTE: requires ImageMagick
# NOTE: will tint to the Solarized Dark default background scheme, as the iTerm background blend option didn't lower the contrast enough for me
# NOTE: Optimised for a 1280x800 point screen (my 13" Retina MBP)
set -e
index=$[ 1 + $[ RANDOM % 10 ]]
img=`curl | xmllint --xpath '/rss/channel/item['$index']/image/url/text()' -`
curl "$img" > ~/unsplash-latest.jpg &&
chrismdp / Blob.cpp
Created Sep 3, 2014
A reasonably naïve Blob implementation in C++, complete with Array and Hash packed data types.
View Blob.cpp
#include "Blob.h"
namespace sol {
unsigned Object::used() const {
BlobType type = (BlobType)_blob.getByte(0);
switch (type) {
case BL_INT:
return Integer(_blob).used();
case BL_ARRAY:
return Array::wrap(_blob).used();
chrismdp / Jenkins build script
Created Aug 5, 2014
Jenkins script to force push Jekyll to Github Pages each day, for scheduled blog posts. Run this as a Jenkins Job on your blog git repository, and set to 'build periodically'. My cron job reads 'H 7 * * *'.
View Jenkins build script
git ci --amend -m "`git show -s --format=%s`
Force updated by Jenkins build $BUILD_ID"
git push -f origin HEAD:master
You can’t perform that action at this time.