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 / simple_rdoc.rb
Last active April 2, 2020 13:29
A very simple custom RDoc generator
# RDoc can use a custom generator but it isn't that well documentated. Here is a
# sample custom generator to get you going.
#
# Ruby comes with an `rdoc` executable but most of us generate our docs via Rake. To
# use your custom generator with Rake do something like the following in your Rakefile..
#
# require 'rdoc/task'
# require 'simple_rdoc'
#
# RDoc::Task.new('simple_doc') do |i|
@thehenster
thehenster / config.ru
Created October 30, 2019 22:39
Rackup file for dynamic requests, then static files, then not found
require 'rack'
require 'rack/static'
class App
def initialize(app)
@app = app
end
def call(env)
req = Rack::Request.new(env)
@thehenster
thehenster / time_travel_in_console.rb
Created November 28, 2017 17:55
Time travel in console
[1] pry(main)> require "active_support/testing/time_helpers"
=> true
[2] pry(main)> include ActiveSupport::Testing::TimeHelpers
=> Object
[3] pry(main)> travel_to("1969-01-01".to_time){ puts Time.current }
1969-01-01 00:00:00 +0100
@charset "utf-8";
@import "normalize";
html {
font-size: 62.5%;
}
body {
font-family: -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
➜ 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
@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(){