Skip to content

Instantly share code, notes, and snippets.

View prakashmurthy's full-sized avatar

Prakash Murthy prakashmurthy

View GitHub Profile
#!/usr/bin/env ruby
# Solution for a Quick Ruby Kata by Noel Rappin -
# http://railsrx.com/2010/09/27/a-quick-ruby-kata/
# Modification of the Solution for Problem number 76 on Project Euler
# http://projecteuler.net/index.php?section=problems&id=76
class Array
def meets_criteria?
meets_criteria = false
count_hash = Hash.new(0)
<p>
<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 5,
interval: 6000,
width: 'auto',
height: 300,
token : <token_string>
secret : <secret_string>
atoken : <access_token_string>
asecret : <access_secret_string>
@prakashmurthy
prakashmurthy / gist:642266
Created October 23, 2010 14:22
Why are these two different? The numbers are the same; just re-arranged.
ruby-1.9.2-rc1 > 707106783028.0 * 1 / 1000000002604.0 * 707106783027.0 / 1000000002603.0
=> 0.49999999999999994
ruby-1.9.2-rc1 > 1 / 1000000002604.0 * 707106783027.0 / 1000000002603.0 * 707106783028.0
=> 0.5
@prakashmurthy
prakashmurthy / output
Created October 28, 2010 15:11
Returns NaN when dealing with large numbers
Percentage of combinations with only one defect per chip = NaN.
@prakashmurthy
prakashmurthy / gist:661447
Created November 3, 2010 18:11
nokogiri - rails 3.0.0 / rails 3.0.1 - ruby 1.9.2-p0 / ruby - doesn't work on my macbook
prakash-murthys-macbook-air:xmltoy prakashmurthy$ rails g scaffold Feed name:string url:string
/Users/prakashmurthy/.rvm/gems/ruby-1.9.2-p0@xmltoy/gems/nokogiri-1.4.3.1/lib/nokogiri/nokogiri.bundle: [BUG] Segmentation fault
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
-- control frame ----------
c:0022 p:-541184440 s:0064 b:0064 l:000063 d:000063 TOP
c:0021 p:---- s:0062 b:0062 l:000061 d:000061 CFUNC :require
c:0020 p:0186 s:0058 b:0058 l:000057 d:000057 TOP /Users/prakashmurthy/.rvm/gems/ruby-1.9.2-p0@xmltoy/gems/nokogiri-1.4.3.1/lib/nokogiri.rb:13
c:0019 p:---- s:0056 b:0056 l:000055 d:000055 FINISH
c:0018 p:---- s:0054 b:0054 l:000053 d:000053 CFUNC :require
@prakashmurthy
prakashmurthy / heroku.log
Created November 30, 2010 00:49
output of heroku rake db:migrate on #PPP
$ heroku logs
/home/app/9493b3e5-40a4-4860-bd6c-da4e8664e69e/vendor/require-profiler/lib/require-profiler.rb:90:in `rescue in <top (required)>': (RuntimeError)
You need to install the term-ansicolor gem to see colorized reports.
from /home/app/9493b3e5-40a4-4860-bd6c-da4e8664e69e/vendor/require-profiler/lib/require-profiler.rb:87:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /home/app/9493b3e5-40a4-4860-bd6c-da4e8664e69e/config/environment.rb:1:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
@prakashmurthy
prakashmurthy / My attempt at repeating this exercise
Created December 13, 2010 03:16
First code example in section 7.2.4 of Rails Tutorial
$ rails console --sandbox
ruby-1.9.2-rc1 > User.create( :name => "Prakash Murthy", :email => "prakblr@yahoo.com", :password => "abcdefgh", :password_confirmation => "abcdefgh" )
=> #<User id: nil, name: "Prakash Murthy", email: "prakblr@yahoo.com", created_at: nil, updated_at: nil, encrypted_password: nil, salt: nil>
ruby-1.9.2-rc1 > user = User.find_by_email("prakblr@yahoo.com")
=> #<User id: 1, name: "Prakash Murthy", email: "prakblr@yahoo.com", created_at: "2010-12-12 01:42:44", updated_at: "2010-12-12 01:42:44", encrypted_password: nil, salt: nil>
ruby-1.9.2-rc1 > user.has_password?('abcdefgh')
=> false
@prakashmurthy
prakashmurthy / guanggun.rb
Created August 15, 2012 04:26
runtime_error?
## Why would the following code give run time error?
## Inputs to the program:
## up to 100 entries from STDIN, values range : 1 ≤ n ≤ 10**18
##
inputs = []
while true
input = $stdin.gets.chomp
break if input.empty?
inputs << input.to_i
end
@prakashmurthy
prakashmurthy / gist:9086679
Created February 19, 2014 05:46
Tried generating the rails guides and validating them for the first time. The validation step throws up a bunch of errors messages. Wonder if these error messages are significant? And how do I fix them?
/Users/prakash/.rvm/rubies/ruby-1.9.3-p327/bin/ruby w3c_validator.rb
EEE
Could not validate ./output/3_1_release_notes.html because of 502 "Proxy Error"
EEE
Could not validate ./output/_license.html because of 502 "Proxy Error"
EE
Could not validate ./output/action_mailer_basics.html because of 502 "Proxy Error"
EEEE
Could not validate ./output/active_record_querying.html because of 502 "Proxy Error"