Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# A simply utility to show character counts for each line of input and
# highlight lines longer than 80 characters.
#
# Written as an example for http://jstorimer.com/2011/12/12/writing-ruby-scripts-that-respect-pipelines.html
#
# Examples:
#
# $ hilong Gemfile

Follow these steps to install Graphite on a fresh Ubuntu 12.04 instance. Make sure you read and understand the commands because by the time you read this, things could be outdated.

Graphite

Installing dependencies

# apt-get install libpq-dev
# apt-get install python-dev python-pip python-cairo python-psycopg2
# apt-get install python-django python-django-tagging
@toddlers
toddlers / remote_diff
Created May 6, 2013 12:39
remote_diff: grab a path from 2 websites and diff them a naive implementation, diffs the md5's if the files are not text
#!/bin/bash
path1=`echo $1 | awk -F, '{print $1}'`/$2
path2=`echo $1 | awk -F, '{print $2}'`/$2
if `curl -Ss $path1 | file - | grep text`; then
diff <(curl -Ss $path1) <(curl -Ss $path2)
else
diff <(curl -Ss $path1 | md5) <(curl -Ss $path2 | md5)
fi
@toddlers
toddlers / test_config.sh
Created May 28, 2013 07:26
Simple YAML fine validation for syntax
#! /bin/bash
file=$1
set -a
if [ -z "$file" ]; then
echo "need YAML file as first arg"
exit 2
fi
if [ -f $file ]; then
#!/usr/bin/perl
use strict ;
use warnings ;
use constant DEBUG => 0 ;
my ($adjtimex) = grep { -f $_ } qw(/sbin/adjtimex ./adjtimex);
die "Need adjtimex - install or download from http://linux.brong.fastmail.fm/2012-06-30/adjtimex and put into current dir\n"
@toddlers
toddlers / ruby_calculator.rb
Created June 2, 2013 07:12
simple ruby calculator
class Calculator
def initialize
@cal={
add: ->(a,b) { a + b },
subtract: ->(a,b) { a - b },
divide: ->(a,b) { a / b },
multiply: ->(a,b) { a * b },
power: ->(a,b) { a ** b }
}
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
And every time you need to see your log, just type in
git lg
Or, if you want to see the lines that changed
git lg -p
@toddlers
toddlers / poweroftwo.rb
Last active December 18, 2015 20:28
Write A Function To Determine If A Number Is A Power Of 2
def power_of_2?(number)
return false if number == 0
while(number % 2 == 0)
number = number / 2
end
return false if number > 1
true
end

Backend Architectures

ARCHITECTURES

ror, scala, jetty, erlang, thrift, mongrel, comet server, my-sql, memchached, varnish, kestrel(mq), starling, gizzard, cassandra, hadoop, vertica, munin, nagios, awstats

@toddlers
toddlers / password.rb
Last active December 18, 2015 21:39
passwd file parsing
# On a system the /etc/passwd has entries with duplicate uids, can you write a python program to print
# the users with duplicate uids.
# User x,y,z duplicate uid 10001 on line 4,7,8
# User x,x duplicate uid 10001 on line 4,10
# This is the initial need to update this
#!/usr/bin/ruby
require 'pp'
z = {}