Skip to content

Instantly share code, notes, and snippets.

@samsalisbury
samsalisbury / si.go
Created March 4, 2014 17:55
Easier navigation of JSON unmarshalled to interface{}
package main
/*
Allows <d>easier</d> inelegant navigation of JSON unmarshalled to interface{}
*/
type si struct {
value interface{}
REM Start the RepositoryHosting.com backup download script
C:
"\Program Files (x86)\Git\bin\sh.exe" -login -c /c/Users/Sam/backup.sh
@samsalisbury
samsalisbury / linear-gradient.less
Created November 4, 2011 17:03
dotLess CSS gradient mixin...
/*
Based on output from http://www.colorzilla.com/gradient-editor/
*/
.linear-gradient(@r1, @g1, @b1, @a1, @p1, @r2, @g2, @b2, @a2, @p2, @r3, @g3, @b3, @a3, @p3, @r4, @g4, @b4, @a4, @p4) {
background: rgb(@r1,@g1,@b1);
background: -moz-linear-gradient(top,
rgba(@r1,@g1,@b1,@a1) @p1,
@samsalisbury
samsalisbury / monadicTimeout.js
Created June 13, 2012 16:31
JavaScript monadic timeout (jQuery plugin)
// Provides safe way to ensure that you only have a single timeout
// set for a particular event, in the face of browsers not always
// firing the expected events...
// Usage example:
//
// var myTimeout = $.monadicTimeout(function() { doSomething(); }, 500);
//
// $(".some-class").mouseenter(myTimeout.clear);
// $(".some-class").mouseleave(myTimeout.set);
@samsalisbury
samsalisbury / django-crate.sh
Last active December 16, 2015 14:19
Create new django project including south, psychopg2, django-facebook
# Django settings for hidjango project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
@samsalisbury
samsalisbury / UserInputAnonymiser.cs
Created December 19, 2013 17:29
Anonymise certain fields in a blob of JSON using Json.Net + JToken
using System.Linq;
using Newtonsoft.Json.Linq;
namespace ExternalApi.Logging
{
public static class UserInputAnonymiser
{
public static JToken Anonymise(JToken data)
{
foreach (var prop in data.Children<JProperty>())
@samsalisbury
samsalisbury / connect
Last active January 19, 2016 12:00
connect: My SSH interactive session connection script
#!/bin/sh
# I keep scripts like this in $HOME/bin and add that dir to my
# path, so I can call e.g. `connect some.host.com` from anywhere.
[ -z "$1" ] && {
echo "usage: $0 <hostname>"; exit 3
}
REMOTE_TMUX_SESSION_NAME=Sam
@samsalisbury
samsalisbury / resize_mesos_stats_whisperdb.sh
Last active July 20, 2017 18:34
Resize graphite whisperdb mesos_stats output
#!/bin/sh
# This script can be executed on a graphite node to resize output from https://github.com/samsalisbury/mesos_stats
DIR=/opt/graphite/storage/whisper/mesos_stats
RULE="1m:14d 5m:60d 10m:120d 1h:2y"
# First set the retention for all, leaving the existing default aggregation (which in our config was avg, xfilesfactor=0.5)
find $DIR -name *.wsp | while read f; do whisper-resize.py $f $RULE; done
# Now override the aggregations for the following special cases that need summing (using xfilesfactor=0.1 as is common for summing in our config)
find $DIR -name *_time_secs.wsp -or -name failed.wsp -or -name lost.wsp -or -name finished.wsp | while read f; do
@samsalisbury
samsalisbury / vim-go-build-tags.vim
Created May 8, 2018 16:52
Getting vim-go and syntastic playing nicely with go build tags.
# First update vim-go and syntastic to latest versions.
# Then install/update go tools using :GoInstallBinaries and :GoUpdateBinaries
# Set default go build tags... Update ad-hoc with :GoBuildTags <new list>
let g:go_build_tags = "smoke integration"
# Get Syntastic to use build tags...
let g:syntastic_go_go_test_args = '-tags="smoke integration"'
let g:syntastic_go_go_build_args = '-tags="smoke integration"'
@samsalisbury
samsalisbury / repositoryhosting-download-template.sh
Created April 24, 2011 12:57
RepositoryHosting.com backup download script
#!/bin/sh
# RepositoryHosting.com backup download script
#
# This script downloads your daily RepositoryHosting.com backups.
##################################################################
##
### Configuration
##