Skip to content

Instantly share code, notes, and snippets.

View kuahyeow's full-sized avatar

Thong Kuah kuahyeow

View GitHub Profile
@kuahyeow
kuahyeow / name_in_lights.rb
Created May 15, 2018 02:54
A little script to delight the kids - increase the font size in your terminal !
def color(index, text)
normal = "\e[#{index}m#{text}\e[0m"
bold = "\e[#{index}m\e[1m#{text}\e[0m"
"#{normal} #{bold} "
end
if ARGV.empty?
puts "Usage: ruby #{__FILE__} NAME"
exit
end
@kuahyeow
kuahyeow / extract_render_update.rb
Created November 8, 2017 08:11
Extracts `render :update` blocks from controllers
require 'parser/current'
class ExtractRenderUpdate < Parser::Rewriter
attr_reader :current_action
attr_reader :extracted_sources
def on_block(node)
replace_with_render_file(node)
super
end
@kuahyeow
kuahyeow / controller_actions_keyword_args.rb
Last active October 2, 2020 18:03
a rewriter to upgrade to Rails 5.1 style controller test actions
=begin
USAGE: ruby-rewrite -l controller_actions_keyword_args.rb -m <FILE>
This rewriter moves your Rails controller tests from `get action, params, session, flash` to
`get action, params: params, session: session, flash: flash`.
Which is needed if you see the following message in your Rails 5.0 tests :
DEPRECATION WARNING: Using positional arguments in functional tests has been deprecated,
in favor of keyword arguments, and will be removed in Rails 5.1.
@kuahyeow
kuahyeow / b.rb
Last active July 22, 2017 10:01
De-RJS : transpile RJS to jQuery
require_relative 'rewrite_rjs'
require_relative 'jquery_hack_generator'
filenames = ARGV
filenames.each do |filename|
source = File.read filename
erbified_source = rewrite(source)
puts erbified_source if ENV['DEBUG']
generator = JqueryHackScriptGenerator.new(nil) {page| eval(erbified_source)}
class Tree
attr_reader :children, :item
def initialize(item)
@item = item
@children = []
end
def add(child_item)
children << Tree.new(child_item)
@kuahyeow
kuahyeow / git-beetil.sh
Created December 3, 2012 20:39 — forked from ezza/.bashrc
Returns the title of the beetil your branch is on
export beetil_api_key=YOUR_BEETIL_API_KEY_HERE
# extracts the branch name
function plain_git_branch {
git symbolic-ref HEAD 2> /dev/null | sed -e 's/refs\/heads\///'
}
# extracts the part of the branch name that could be a beetil number
function beetil_number_from_git_branch {
plain_git_branch 2> /dev/null | cut -c2-9
https://github.com/bagedevimo/chicken-soup-people
https://github.com/aidancopps/rocket
https://github.com/dillonsue2288/MakeRobot
https://github.com/purederp/robo
https://github.com/fesherman/First-man-on-the-moon
https://github.com/LoveBug/Wellington-Sights
@kuahyeow
kuahyeow / url_validator.rb
Created May 3, 2011 11:31
URL validator for Rails 3 - kuahyeow
# Require this file, or put this in where Rails will auto load it.
class UrlValidator < ActiveModel::EachValidator
def initialize(options)
super
@domain = options[:domain]
@permissible_schemes = options[:schemes] || %w(http https)
@error_message = options[:message] || 'is not a valid url'
end
@kuahyeow
kuahyeow / response_with_attachments.rb
Created April 8, 2011 01:38
Savon SOAP Response monkey patch to parse soap attachments
require 'mail'
module Savon
module SOAP
class Response
def multipart?
http.headers["Content-Type"] =~ /^multipart/
end
def boundary
sudo gem install unicorn
sudo echo "You have been unicorn\'ed"