Skip to content

Instantly share code, notes, and snippets.

View itamar's full-sized avatar

Itamar Yunger itamar

View GitHub Profile
@itamar
itamar / gist:9522496
Created March 13, 2014 05:49
application_controller - capture_referral method
before_filter :capture_referral
private
def capture_referral
session[:referral] = params[:referral] if params[:referral]
end
@itamar
itamar / css_bp
Created February 20, 2014 00:28
CSS Best Practices
/* instead of this: */
.row#categories .block-list li#mixing {
background: white url(/assets/home/mixing.jpg) top center no-repeat;
background-size: cover;
}
.row#categories .block-list li#mastering {
background: white url(/assets/home/mastering.jpg) top center no-repeat;
background-size: cover;
}
@itamar
itamar / moon_animation
Created February 18, 2014 21:34
#moon animation
ruby -e'a=0x1F311;loop{8.times{|i|print(("\b"*6)+[a+i].pack("U")+(" "*5));sleep(0.1)}}'
@itamar
itamar / ruby_install.sh
Created November 18, 2013 15:32
Ruby install
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.fu-berlin.de/unix/languages/ruby/1.9/ruby-1.9.3-p448.tar.gz
tar -xvzf ruby-1.9.3-p448.tar.gz
cd ruby-1.9.3-p448/
./configure --prefix=/usr/local
make
make install
# Copyright Camptocamp SA 2012
# License: AGPL (GNU Affero General Public License)[http://www.gnu.org/licenses/agpl-3.0.txt]
# Author Guewen Baconnier
require "xmlrpc/client"
require 'pp'
XMLRPC::Config::ENABLE_NIL_PARSER = true
XMLRPC::Config::ENABLE_NIL_CREATE = true
class MagentoAPI
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@itamar
itamar / starter
Created September 23, 2013 14:48
HTML5 Starter Template
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My title is here</title>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
@itamar
itamar / gist:6097882
Created July 28, 2013 08:00
Convert XML to JSON
require 'json'
Hash.from_xml('<variable type="product_code">5</variable>').to_json # => "{\"variable\":\"5\"}"
require 'net/http'
s = Net::HTTP.get_response(URI.parse('http://stackoverflow.com/feeds/tag/ruby/')).body
Hash.from_xml(s).to_json
# for pretty output
JSON.pretty_generate(Hash.from_xml('<variable type="product_code">5</variable>'))
@itamar
itamar / tail log
Created July 7, 2013 09:33
Tail production log file.
desc "tail production log files"
task :tail_p, :roles => :app do
run "tail -f #{shared_path}/log/production.log" do |channel, stream, data|
puts # for an extra line break before the host name
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"