Skip to content

Instantly share code, notes, and snippets.

View zoras's full-sized avatar
🏠
Working remotely 🌏 Available for Hire

Saroj Maharjan zoras

🏠
Working remotely 🌏 Available for Hire
View GitHub Profile
@zoras
zoras / main.rb
Created October 26, 2011 17:08 — forked from daz4126/main.rb
Short, Long and Pretty Urls - Using Sinatra & DataMapper to demonstrate different types of urls
require 'sinatra'
require 'data_mapper'
require 'slim'
require 'digest/sha1'
DataMapper.setup(:default, ENV['DATABASE_URL'] || File.join("sqlite3://",settings.root, "development.db"))
class Note
include DataMapper::Resource
property :id, Serial
@zoras
zoras / fixes.md
Created November 7, 2011 06:34 — forked from thbar/fixes.md
Getting rid of nokogiri segfaults

This readme is a mixture of everything I read on SO+nokogiri wiki, which ultimately worked out for me.

Here are the steps which worked for me to get rid of segfaults with Nokogiri 1.4.4, on both Lion and Snow Leopard, with Ruby 1.8.7 (patchlevel 334 and +).

First diagnose which version of libxml2 you're using:

bundle exec nokogiri -v

If you have 2.7.3 listed somewhere, you're in bad waters (known to segfault). Install this:

@zoras
zoras / ruby_mac.sh
Created February 9, 2012 04:52 — forked from bonjourmauko/ruby_mac.sh
ruby mac
#!/bin/bash
# MacPorts
# hdiutil attach Downloads/MacPorts-2.0.3-10.6-SnowLeopard.dmg
# sudo installer -verbose -pkg /Volumes/MacPorts-2.0.3/MacPorts-2.0.3.pkg -target /
# sudo port install coreutils lesspipe
# Homebrew
ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
brew install wget git bash-completion node mysql postgresql
@zoras
zoras / rspec-syntax-cheat-sheet.rb
Created February 15, 2012 09:13 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
Gem::Specification.new do |s|
s.name = 'bang'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'Jeff Kreeftmeijer'
s.email = 'jeff@kreeftmeijer.nl'
s.summary = 'Bang!'
s.description = 'Bangs existing model methods'
s.files = ['bang.rb']
@zoras
zoras / _README.md
Created February 24, 2012 04:54 — forked from tjh/_README.md
acts_as_boolean

Acts As Boolean

A quick way to create an attribute on your ActiveRecord models that always responds with a boolean value, similar to the Boolean attributes from a table that have the ? method for syntactic sugar.

class SomeObject < ActiveRecord::Base
  acts_as_boolean :is_active
end

o = SomeObject.new

o.is_active? # => false

@zoras
zoras / 0-readme.md
Created March 13, 2012 16:16 — forked from burke/0-readme.md
ruby-1.9.3-p125 cumulative performance patch.

Patched ruby 1.9.3-p125 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p125 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Huge thanks to funny-falcon for the performance patches.

set :asset_precompile_locations, ["config/application.rb", "app/assets"] # We check the git log for these locations to determine if recompilation necessary
# ...
namespace :assets do
task :recompile, :roles => :web do
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} GROUP=assets assets:precompile}
end
@zoras
zoras / launch_sublime_from_terminal.markdown
Created June 21, 2012 04:29 — forked from artero/launch_sublime_from_terminal.markdown
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

@zoras
zoras / raskell.rb
Created August 15, 2012 11:55 — forked from andkerosine/raskell.rb
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@