Skip to content

Instantly share code, notes, and snippets.

View itamar's full-sized avatar

Itamar Yunger itamar

View GitHub Profile
@itamar
itamar / sticky
Created June 2, 2013 18:28
Sticky sidebar
# Sticky Sidebar
$(document).ready () ->
if (!!$('.sticky').offset())
stickyTop = $('.sticky').offset().top
$(window).scroll () ->
windowTop = $(window).scrollTop()
if (stickyTop < windowTop)
$('.sticky').css({ position: 'fixed', top: 0 });
else
@itamar
itamar / gist:5755943
Created June 11, 2013 10:37
Fix "Too many open files" error - Rails / paperclip / Too many open files - identify -format ..
def download_remote_image
if io = do_download_remote_image
self.image = io
self.image_remote_url = image_url
io.close # Already copied to a Tempfile.
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}"
@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
@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 / 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>
=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')
# 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
@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
@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)}}'