Skip to content

Instantly share code, notes, and snippets.

View thehenster's full-sized avatar

Henry thehenster

  • https://char.gy
  • London
View GitHub Profile
@thehenster
thehenster / gist:2215231
Created March 27, 2012 11:44
How to remove/disable the automatic XSS protection helper html escaping for Rails 3
# dirty way to completely remove the automatic escaping of html in rails helpers
# useful to get your Rails 2 -> 3 upgrade running to the point where the raw/.html_safe additions can be delegated
module CustomHtmlSafe
def html_safe?
true
end
end
class ActionView::OutputBuffer
@thehenster
thehenster / to_string
Created October 26, 2012 09:08
to_string
########
# Author: Henry Turner
# Project: to_string
# Description: A speedy algorithm to convert a string to a string
# License: MIT
########
def to_string
# process the string
 self.to_s
end
# As root user
sudo su
# Update the OS
apt-get update -y
# Setup Hostname & TimeZone
echo "{{HOSTNAME}}" > /etc/hostname
hostname -F /etc/hostname
@thehenster
thehenster / gist:7861351
Created December 8, 2013 18:08
An example of the proof of work concept in Bitcoin.
package main
import (
"fmt"
"strconv"
"crypto/sha256"
"encoding/base64"
)
func main(){
@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
@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
" 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'
➜ tmp cat no_way.rb
def ☃
puts "Oh look, it's a ☃"
end
➜ tmp ruby no_way.rb
Oh look, it's a ☃
➜ tmp
@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'
@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