Skip to content

Instantly share code, notes, and snippets.

View dalibor's full-sized avatar

Dalibor Nasevic dalibor

View GitHub Profile
@dalibor
dalibor / gist:1533943
Created December 29, 2011 12:53
Ruby simple HTML parser
class HtmlParser
attr_accessor :url, :selector
def initialize(url, selector)
@url = url
@selector = selector
end
def content
doc = Nokogiri::HTML(open(url))
@dalibor
dalibor / gist:1529203
Created December 28, 2011 19:06
Rubygems Redis
# rubygems.org / config / initializers / redis.rb
if Rails.env.test? || Rails.env.cucumber?
$redis = Redis.new(:db => 1)
else
$redis = Redis.connect(:url => ENV['REDISTOGO_URL'])
end
# rubygems.org / app / models / download.rb
class Download
def self.incr(name)
@dalibor
dalibor / gist:1528343
Created December 28, 2011 15:28
Redis Ubuntu
# install Redis on Ubuntu
sudo apt-get install redis-server
# Start Redis server
sudo service redis-server start
# Stop Redis server
sudo service redis-server stop
@dalibor
dalibor / gist:1528278
Created December 28, 2011 15:12
Redis Ruby example
# gem install redis
ruby-1.8.7-p299 :001 > require 'rubygems'
=> false
ruby-1.8.7-p299 :002 > require 'redis'
=> true
ruby-1.8.7-p299 :003 > r = Redis.new
=> #<Redis client v2.2.2 connected to redis://127.0.0.1:6379/0 (Redis v2.2.11)>
ruby-1.8.7-p299 :004 > r.get('visits')
=> "2"
@dalibor
dalibor / Redis console
Created December 28, 2011 15:09
Redis console example
# redis-cli -p 6379
redis 127.0.0.1:6379> SET visits 1
OK
redis 127.0.0.1:6379> GET visits
"1"
redis 127.0.0.1:6379> INCR visits
(integer) 2
redis 127.0.0.1:6379> exit
@dalibor
dalibor / rails_3_1_beta_1_changes.md
Created May 24, 2011 07:46 — forked from ryanb/rails_3_1_rc4_changes.md
The Changelogs for Rails 3.1 Beta 1

Railties 3.1 Beta 1

  • The -j option of the application generator accepts an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". As of this writing "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. Default is "jquery". [fxn]

  • jQuery is no longer vendored, it is provided from now on by the jquery-rails gem. [fxn]

  • Prototype and Scriptaculous are no longer vendored, they are provided from now on by the prototype-rails gem. [fxn]

  • The scaffold controller will now produce SCSS file if Sass is available [Prem Sichanugrist]

Then /^(.+) and I confirm dialog box$/ do |step|
bypass_confirm_dialog
Then step
end
var currentMedia = false;
// Get photo
Ti.Media.showCamera({
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
success: function(event) {
var cropRect = event.cropRect;
currentMedia = event.media;
},
error:function(error) {
@dalibor
dalibor / ip_array_search.rb
Created April 23, 2010 06:53
IP array search
ip = 12
arr = [1, 3, 5, 7, 9, 10, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 34, 35, 36]
index = arr.length
min = 0; max = arr.length
while (min + 1 != max) do
index = (min + max) / 2
if ip < arr[index]
max = index
else
@dalibor
dalibor / perform_action_without_rescue hack.rb
Created April 17, 2010 16:37 — forked from soey/perform_action_without_rescue hack.rb
restful_authentication features webrat fix
#Change this:
ActionController::Base.class_eval do
def perform_action
perform_action_without_rescue
end
end
#to: