Skip to content

Instantly share code, notes, and snippets.

View thehenster's full-sized avatar

Henry thehenster

  • https://char.gy
  • London
View GitHub Profile
#!/usr/bin/env ruby
# Give me two arguments.
# 1) the path of the pwsafe xml file to import
# 2) the path of the csv to export
# format of lastpass data
# url,username,password,extra,name,grouping,fav
require 'nokogiri'
@thehenster
thehenster / gist:183c3efefa6343895452
Created May 19, 2014 16:18
Delegation of class methods through an association..
class Event < ActiveRecord::Base
has_many :artists
end
class Artist < ActiveRecord::Base
def self.make_me_an_artist
create! do |artist|
@thehenster
thehenster / gist:9555660
Created March 14, 2014 20:03
An /etc/fstab to stop mounting a partition automatically on osx
UUID=1229D978-XXXX-XXXX-827E-0DE28E523720 none hfs rw,noauto
@thehenster
thehenster / gist:9409371
Created March 7, 2014 10:48
Me git tips
# Stash only specific files
# Stage the files you want to keep and run..
git stash --keep-index
@thehenster
thehenster / colours.rb
Last active August 29, 2015 13:57
A ruby version of the Haskell colour problem in seven languages in seven weeks
def colour_combinations(colours=[])
colours.flat_map{|x| colours.flat_map{|y| x <= y ? [[x, y]] : [] } }
end
require 'minitest/autorun'
require 'minitest/unit'
class TestColours < MiniTest::Unit::TestCase
def test_colour_combinations
@thehenster
thehenster / proof_of_work.rb
Last active August 29, 2015 13:57
An example of Bitcoin's proof of work concept in Ruby
# https://en.bitcoin.it/wiki/Proof_of_work
# usage: ProofOfWork.new("Hello World!", 3).nonce_and_hash
# In this example think of the "Hello World!" as a a collection of Bitcoin transactions waiting to be verified.
# 3 is the arbitary number that makes it harder to verify the transactions. Over time 3 goes up and up and the
# difficulty is exponential.
require 'digest'
➜ tmp cat no_way.rb
def ☃
puts "Oh look, it's a ☃"
end
➜ tmp ruby no_way.rb
Oh look, it's a ☃
➜ tmp
" Vundle Setup
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
@thehenster
thehenster / crapistrano.sh
Created December 15, 2013 22:26
Crapistrano
project_path='~/apps/'$app'/current'
frontend_path=$project_path$subdir
cmd=''
cmd+='. ~/.bash_profile;'
cmd+='cd '$project_path';'
cmd+='git pull;'
cmd+='kill `cat '$frontend_path'/tmp/pids/unicorn.pid`;'
sleep 5
@thehenster
thehenster / gist:7975956
Last active December 31, 2015 10:49
Setup Mysql backups in one fell swoop
# install by getting the raw url from the github interface and run something like..
# curl -L https//gist.github.com/blahblah | bash
mkdir -p ~/backups
mkdir -p ~/bin
# a backup for each day of the month overwritting old days
echo "mysqldump -u root --all-databases > ~/backups/all-`date +20XX-XX-%d`.sql" > ~/bin/backup_all_mysql_databases
chmod 777 ~/bin/backup_all_mysql_databases