Skip to content

Instantly share code, notes, and snippets.

View sirmxanot's full-sized avatar

Andrew Frank sirmxanot

  • Seattle, Washington
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script type="text/javascript" src="js/d3.v3.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
@sirmxanot
sirmxanot / gist:7a3620525ed8d4528d72
Last active August 29, 2015 14:08
Rails: What is the best way to display an index with a specific list of records specified through an array of IDs?
**Background**
I am trying to create links that redirect to an index page listing an arbitrary set of records. I believe that the best way to accomplish this is to pass an array of the IDs of the objects that I would like to be included to the index controller method.
**Method**
I have a working solution where I look for params[:ids] in my index method and if it exists, I find those records and display them. If that params[:ids] doesn't exists, I default to the default index behavior.
**Problem**
# Ruby Code
def fun
a = 1
add1(a) == 2
sub2(a) == -1
end
def add1(num)
num += 1
sirmxanot@sirmxanot-CT15:~/Sites/hw2_rottenpotatoes$ rbenv local
1.9.2-p290
sirmxanot@sirmxanot-CT15:~/Sites/hw2_rottenpotatoes$ ber db:migrate --trace
rake aborted!
/var/lib/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so: undefined symbol: ruby_threadptr_data_type - /var/lib/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so
/var/lib/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `require'
/var/lib/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `<top (required)>'
/var/lib/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug.rb:5:in `require'
/var/lib/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug.rb:5:in `<top (required)>'
/var/lib/gems/1.9.1/gems/bundler-1.2.2/lib/bundler/runtime.rb:68:in `require'
sirmxanot@sirmxanot-CT15:~/Sites/hw2_rottenpotatoes$ ber db:migrate --trace
rake aborted!
/var/lib/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so: undefined symbol: ruby_current_thread - /var/lib/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so
/var/lib/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `require'
/var/lib/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `<top (required)>'
/var/lib/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug.rb:5:in `require'
/var/lib/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug.rb:5:in `<top (required)>'
/var/lib/gems/1.9.1/gems/bundler-1.2.2/lib/bundler/runtime.rb:68:in `require'
/var/lib/gems/1.9.1/gems/bundler-1.2.2/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/var/lib/gems/1.9.1/gems/bundler-1.2.2/lib/bundler/runtime.rb:66:in `each'
@sirmxanot
sirmxanot / gist:4112293
Created November 19, 2012 17:52
currency converter with symbols, singular, plural
class Numeric
@@currencies = {'yen' => 0.013, 'euro' => 1.292, 'rupee' => 0.019}
@@currencies['dollar']=1
def method_missing(method_id)
singular_currency = method_id.to_s.gsub( /s$/, '')
if @@currencies.has_key?(singular_currency)
self * @@currencies[singular_currency]
else
super
end
#this is preferable
graph[vertex_delete].each do |edge|
graph[edge].map! do |vertex|
vertex == vertex_delete ? vertex_keep : vertex
end
end
#to this?
graph[vertex_delete].each {|edge| graph[edge].map! {|vertex| vertex == vertex_delete ? vertex_keep : vertex}}
@sirmxanot
sirmxanot / gist:3956326
Created October 26, 2012 00:31
weird error
ArgumentError: comparison of Fixnum with nil failed
from mergesort3.rb:34:in `<'
from mergesort3.rb:34:in `block in merge'
from mergesort3.rb:31:in `each'
from mergesort3.rb:31:in `merge'
from mergesort3.rb:17:in `merge_sort'
from mergesort3.rb:14:in `merge_sort'
from (irb):4
from /usr/bin/irb:12:in `<main>'
@sirmxanot
sirmxanot / gist:3956132
Created October 25, 2012 23:32
merge sort ruby - the ruby way?
def merge_sort(m)
#base case
if m.length <= 1
m
#all other cases
else
#intialize variables
left = Array.new
right = Array.new
middle = m.length/2
@sirmxanot
sirmxanot / gist:3955719
Created October 25, 2012 22:00
merge sort ruby
def merge_sort(m)
#base case
if m.length <= 1
return m
else
#intialize variables
left = Array.new
right = Array.new
middle = m.length/2