Skip to content

Instantly share code, notes, and snippets.

@mtunjic
mtunjic / to_haml.rb
Created June 21, 2011 10:55
Convert ERb views to Haml
class ToHaml
def initialize(path)
@path = path
end
def convert!
Dir["#{@path}/**/*.erb"].each do |file|
`html2haml -rx #{file} #{file.gsub(/\.erb$/, '.haml')}`
end
end
@mtunjic
mtunjic / application.js
Created July 2, 2011 18:00 — forked from nicalpi/application.js
my default application.js configuration to work with Jquery and Rails
/*
Jquery and Rails powered default application.js
Easy Ajax replacement for remote_functions and ajax_form based on class name
All actions will reply to the .js format
Unostrusive, will only works if Javascript enabled, if not, respond to an HTML as a normal link
respond_to do |format|
format.html
format.js {render :layout => false}
end
*/
@mtunjic
mtunjic / rails.screen
Created July 7, 2011 22:27
Rails screen session (Vim and GNU Screen)
#
# Rails screen session
# Usage: screen -c ~/.rails.screen (add alias)
source ~/.screenrc
screen -t dev 0
split
resize 40
focus down
module Autotest::GnomeNotify
# Time notification will be displayed before disappearing automatically
EXPIRATION_IN_SECONDS = 2
ERROR_STOCK_ICON = "gtk-dialog-error"
SUCCESS_STOCK_ICON = "gtk-dialog-info"
# Convenience method to send an error notification message
#
# [stock_icon] Stock icon name of icon to display
@mtunjic
mtunjic / rails.watchr.rb
Created July 13, 2011 07:51
Watchr Rules
# Run me with:
#
# $ watchr specs.watchr
# --------------------------------------------------
# Watchr Rules
# --------------------------------------------------
#START:SPECS
watch('^spec/(.*)_spec\.rb') { |m| run_test_matching(m[1]) }
@mtunjic
mtunjic / uniq.rb
Created August 4, 2011 07:57
Remove Duplicate Active Record Objects
require 'set'
class Array
def uniq_by
seen = Set.new
select{ |x| seen.add?( yield( x ) ) }
end
end
@mtunjic
mtunjic / to_bytes.rb
Created January 1, 2012 13:53
Numeric#bytes
class Numeric
KILOBYTE = 1024
MEGABYTE = KILOBYTE * 1024
GIGABYTE = MEGABYTE * 1024
def bytes
self
end
alias :byte :bytes
@mtunjic
mtunjic / vim7.3_mac_install.rb
Created February 9, 2012 09:18 — forked from sirupsen/vim7.3_mac_install.rb
Script to install Vim 7.3 with ruby support for Mac OS X Lion
# requires root permissions in /usr/bin/
star = String.new
8.times { star += "*" }
Star = "\n#{star * 3}\n"
def newblock string
puts "\n#{Star}#{string}#{Star}\n"
end
# Author : why the lucky stiff
# include in any project in which metaprogramming is needed
class Object
# The hidden singleton lurks behind everyone
def metaclass; class << self; self; end; end
# The equivalent of class_eval for singleton classes.
# Evaluates the given block in
# the context of the receiver’s singleton class.
@mtunjic
mtunjic / install-ruby.sh
Created February 25, 2014 18:28
install ruby
#!/bin/bash
set -e
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
source ~/.bash_profile
source ~/.zshrc