Skip to content

Instantly share code, notes, and snippets.

View ngty's full-sized avatar

Ng Tze Yang ngty

  • RankAbove Ltd
  • Singapore
View GitHub Profile
@ngty
ngty / pptp_startup_script
Last active August 29, 2015 14:02
VyperVPN
#!/bin/sh
ISP_FALLBACK=no
STARTUP_LAPSE=120
# PPTP settings
# Remote Subnet: 0.0.0.0
# Remote Subnet Mask: 255.255.255.0
# MPPE Encryption (note the space is not typo): mppe required,no40,no56,stateless
# MTU (use default): 1450
# MRU (use default): 1450
@ngty
ngty / battery-stats
Last active December 17, 2015 04:48
Generating battery status
#!/bin/bash
if [ "$(acpi -a | awk '{print $3}' | tr [a-z] [A-Z])" == "ON-LINE" ]; then
if [ "$(acpi -b | awk '{print $4}')" == "100%" ]; then
echo -n "100%"
else
echo -n "$(
acpi -b | \
awk '{gsub(",",""); print $4 "(+" $5}' | \
awk -F: '{print $1 ":" $2 ")"}'
@ngty
ngty / rvmrc-local
Created February 8, 2012 07:24
Enjoy a faster rails boot up :D
gemset=mayday
old_ruby=ruby-1.9.3-p0
new_ruby=ruby-1.9.3-p0-perf
# Get 30% boast for rails boot, see https://gist.github.com/1688857
export RUBY_HEAP_MIN_SLOTS=1000000
export RUBY_HEAP_SLOTS_INCREMENT=1000000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=1000000000
export RUBY_HEAP_FREE_MIN=500000
@ngty
ngty / gist:1229514
Created September 20, 2011 16:04
Module#attr_accessor & friends
# Have u ever found urself doing this:
class Thing
def size=(size)
@size = size
end
def size
@size
end
end
# features/support/cucumber_fuubar_patch.rb
module Cucumber::Cli::Configuration::Patch
def self.included(base)
base.class_eval do
alias_method :_orig_formatter_class, :formatter_class
def formatter_class(format)
if format == 'Cucumber::Formatter::Fuubar'
require 'cucumber/formatter/fuubar'
@ngty
ngty / showoff-scraper.rb
Created June 4, 2011 17:49
Showoff's (https://github.com/schacon/showoff) builtin pdf conversion doesn't work well for me, so i hacked up my own version ... & it works !!
#!/usr/bin/env ruby
require 'rubygems'
require 'RMagick'
require 'capybara'
require 'capybara/dsl'
# ================================================================
# Collect input args
# ================================================================
begin
if Rails.env.test?
ActionDispatch::Callbacks.before do
CrossStub.refresh :file => Rails.root.join('tmp', 'crossstub.cache')
end
end
@ngty
ngty / rvm_error.dump
Created October 16, 2010 01:44
Need extra stripping of trailing double-quote char to prevent yaml-related error
/home/ty.archlinux/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:133:in `load': syntax error on line 23, col -1: ` ' :cd': "\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:ct=\E[3g:\" (ArgumentError)
' :do': "^J:nd=\E[C:pt:rc=\E8:rs=\Ec:sc=\E7:st=\EH:up=\EM:\"
' :le': "^H:bl=^G:cr=^M:it#8:ho=\E[H:nw=\EE:ta=^I:is=\E)0:\"
' :li#33:co#127:am:xn:xv:LP:sr': "\EM:al=\E[L:AL=\E[%dL:\"
' :cs': "\E[%i%d;%dr:dl=\E[M:DL=\E[%dM:im=\E[4h:ei=\E[4l:mi:\"
' :IC': "\E[%d@:ks=\E[?1h\E=:ke=\E[?1l\E>:vi=\E[?25l:\"
' :ve': "\E[34h\E[?25h:vs=\E[34l:ti=\E[?1049h:te=\E[?1049l:\"
' :us': "\E[4m:ue=\E[24m:so=\E[3m:se=\E[23m:mb=\E[5m:\"
' :md': "\E[1m:mr=\E[7m:me=\E[m:ms:\"
' :Co#8:pa#64:AF': "\E[3%dm:AB=\E[4%dm:op=\E[39;49m:AX:\"
class TweetObserver < ActiveRecord::Observer
observe :post, :implementation, :question
def after_create(model)
tweet(model.tweet_title, model.tweet_path)
end
private
def tweet(title, path)
# Usages:
#
# 1. Obtain benchmark results by repeating :spec by running the default number (5) of times
# $ rake benchmark[spec]
#
# 2. Obtain benchmark results by repeating :spec by running it 2 times
# $ rake benchmark[spec,2]
#
task :benchmark, :task, :times do |t, args|
times, task = (args.times || 5).to_i.method(:times), args.task