Skip to content

Instantly share code, notes, and snippets.

View khash's full-sized avatar
😷
Having fun!

Khash Sajadi khash

😷
Having fun!
View GitHub Profile
require "bundler/capistrano"
require 'san_juan'
set :application, "myapp"
set :repository, "git@git.assembla.com:myapp.git"
set :scm, :git
set :user, 'deploy'
set :use_sudo, false
set :deploy_to, "/var/www/#{application}"
@khash
khash / gist:1364171
Created November 14, 2011 15:25
WCF Services Issue
namespace MyApp
{
public class Installer : IWindsorInstaller
{
public static Binding DefaultBinding
{
get
{
return new BasicHttpBinding
{
@khash
khash / check_security.rb
Created December 13, 2011 11:40
Bypass security in controller in unit test
def check_signature
return if request.host == 'test.host'
# check signature
# ...
end
@khash
khash / MixpanelTrackEventJob.rb
Created January 1, 2012 12:41
Mixpanel Resque Job
require 'net/http'
class MixpanelTrackEventJob
@queue = :slow
def self.perform(name, params, user_id, user_ip = nil)
user = User.find(user_id)
params.merge!({ :distinct_id => user.id, :mp_name_tag => user.email }) if !user.nil?
params.merge!({ :ip => user_ip }) if !user_ip.nil?
@khash
khash / layout.html
Created January 1, 2012 12:42
Mixpanel Integration
<script type="text/javascript">var mpq=[];mpq.push(["init","<%= AppSettings.api_keys.mixpanel %>"]);(function(){var b,a,e,d,c;b=document.createElement("script");b.type="text/javascript";b.async=true;b.src=(document.location.protocol==="https:"?"https:":"http:")+"//api.mixpanel.com/site_media/js/api/mixpanel.js";a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(b,a);e=function(f){return function(){mpq.push([f].concat(Array.prototype.slice.call(arguments,0)))}};d=["init","track","track_links","track_forms","register","register_once","identify","name_tag","set_config"];for(c=0;c<d.length;c++){mpq[d[c]]=e(d[c])}})();
</script>
@khash
khash / mixpanelevent.rb
Created January 1, 2012 12:46
Call Mixpanel Event in Resque
Resque.enqueue(MixpanelTrackEventJob, "Added CC Info", {:type => 'AMEX'}, current_user.id)
@khash
khash / quartz.sh
Created January 24, 2012 21:34
CloudQuartz Queue sample
curl -H "api_key: 87c66d340c0f4e938a32e039d0736a0f" https://www.thecloudblocks.com/api/v1/queue/879df17270704e27bbd3a6f4a6c0347c.json
reg = /\${(?<key>.*?)}/
text.gsub(reg) do
key = $~[:key]
"the replacement"
end
@khash
khash / em.rb
Created March 13, 2012 16:50
eventmachine daemon start method
@pid_full = '/tmp/my_daemon.pid'
def run
EM.run{
Signal.trap('INT') { stop }
Signal.trap('TERM'){ stop }
# your daemon code runs here. This will not exit since it is running in EM
}
end
@khash
khash / gist:2594409
Created May 4, 2012 11:59
Changing default Rails 3 confirmation alert behaviour with a click-twice approach
// This goes in application.js
// Using this, the confirmation alerts on Rails 3.1 will be replaced with this behaviour:
// The link text changes to 'Sure?' for 2 seconds. If you click the button again within 2 seconds the action is performed,
// otherwise the text of the link (or button) flips back and nothing happens.
$.rails.confirm = function(message, element)
{
var state = element.data('state');
var txt = element.text();
if (!state)