Skip to content

Instantly share code, notes, and snippets.

View fadhlirahim's full-sized avatar
💭
Most happiest building code that make sense.

Fadhli Rahim fadhlirahim

💭
Most happiest building code that make sense.
View GitHub Profile
/**
* An extension that always calls success when a spy is called.
*
* @example
* spyOn(foo, 'bar').andCallSuccessWith("baz");
* var options = {
* success: jasmine.createSpy();
* }
* foo.bar(options);
* expect(options.success).toBeCalledWith("baz");
#controller
@start_date = Date.civil(params[:range][:"start_date(1i)"].to_i,params[:range][:"start_date(2i)"].to_i,params[:range][:"start_date(3i)"].to_i)
#view
<%= date_select('range', 'start_date', :order => [:month, :day, :year])%>
@fadhlirahim
fadhlirahim / gist:5412518
Last active December 16, 2015 09:19
Show current git branch with color
GREEN="\[\033[0;32m\]"
WHITE="\[\033[1;37m\]"
# Get the name of the current git branch
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# Update the command prompt to be <current_directory>(git_branch) >
# Note that the git branch is given a special color
@fadhlirahim
fadhlirahim / Facebook FQL Share Count
Last active December 17, 2015 02:39
FQL Share count for a url
SELECT url, normalized_url, share_count, like_count, comment_count, total_count,commentsbox_count, comments_fbid, click_count FROM link_stat WHERE url='http://www.booom.com/’
@fadhlirahim
fadhlirahim / gist:5596545
Created May 17, 2013 02:30
run varnish in local machine with local varnish conf
/usr/local/opt/varnish/sbin/varnishd -f /usr/local/etc/varnish/default.vcl -a 0.0.0.0:3001
@fadhlirahim
fadhlirahim / gist:5596849
Created May 17, 2013 03:59
simple load page time test using curl | grep | awk
for i in {0..10}; do curl -w "time %{time_total}\n" -o /dev/null -L http://viki.com 2>&1; done | grep time | awk '{sum+=$2}END{print sum/10}'
@fadhlirahim
fadhlirahim / zombies.rb
Created October 8, 2013 07:32
Hint: Zombies can only be killed with -9
while true
begin
sleep 5
puts 'ping'
rescue Exception => ex
puts "Urghh.. brains"
end
end
@fadhlirahim
fadhlirahim / installing_supervisor_macosx.md
Last active December 31, 2023 14:45
Setting up supervisord in Mac OS X

Installation

Installing Supervisor on OS X is simple:

sudo pip install supervisor

This assumes you have pip. If you don't:

@fadhlirahim
fadhlirahim / dirty_associations.rb
Last active January 31, 2024 09:16
Awesome simple solution for Rails ActiveRecord dirty tracking associations
# Credit Brandon Weiss of http://anti-pattern.com/dirty-associations-with-activerecord
# app/models/dirty_associations.rb
module DirtyAssociations
attr_accessor :dirty
attr_accessor :_record_changes
def make_dirty(record)
self.dirty = true
self._record_changes = record
@fadhlirahim
fadhlirahim / notes.md
Last active August 29, 2015 14:06 — forked from DavidWittman/notes.md

A Brief Introduction to Fabric

Fabric is a deployment management framework written in Python which makes remotely managing multiple servers incredibly easy. If you've ever had to issue a change to a group servers, this should look pretty familiar:

for s in $(cat servers.txt); do ssh $s service httpd graceful; done

Fabric improves on this process by providing a suite of functions to run commands on the servers, as well as a number of other features which just aren't possible in a simple for loop. While a working knowledge of Python is helpful when using Fabric, it certainly isn't necessary. This tutorial will cover the steps necessary to get started with the framework and introduce how it can be used to improve on administering groups of servers.