Skip to content

Instantly share code, notes, and snippets.

<div class="comment" id=<%=comment.id %>>
<div class="well"><%= comment.body %><br>
<%= comment.user.username %>
<small><%= comment.updated_at.strftime('%b %d, %Y at %I:%M %p') %></small>
<%= link_to "×", comment_path(comment), :method => :delete, :remote => true, :confirm => "Are you sure you want to remove this comment?", :disable_with => "×", :class => 'close' %></div>
</div>
def good_fact(x)
def fact_tail(x,sum)
if x == 0
return sum
else
fact_tail(x-1,x*sum)
end
end
fact_tail(x,1)
end
@mooreniemi
mooreniemi / cli-case.rb
Created May 4, 2016 22:40
case to class
#!/usr/bin/env ruby
case ARGV[0]
when "one"
puts "hi"
when "two"
puts "bye"
else
puts "otherwise"
end
@mooreniemi
mooreniemi / dont_do_this.rb
Last active May 10, 2016 19:52
ruby is evil
class Dog
end
class Cat
def self.new
Dog.new
end
end
#[3] amooreniemi (main) » Cat.new
#=> #<Dog:0x007fa052063c78>
class SatisfactionQuery
def self.execute
query = <<-SQL.strip_heredoc
SELECT pins.id AS pin_id, pins.satisfaction, procedures.name, surgeons.last_name,
dense_rank() OVER (
PARTITION BY procedure_id, surgeon_id
ORDER BY pins.satisfaction DESC
) AS sat_rank
FROM pins
INNER JOIN procedures
Run options: include {:locations=>{"./spec/string_permutations_iterative_spec.rb"=>[13]}}
String
#permutations
op_count: 1
op: + A
current strings: []
current stack: ["A:BC"]
-----------
op_count: 2
require 'spec_helper'
def perms(str)
return [str] if str.length == 1
results = []
str.length.times do |i|
substring = str.dup
c = substring.slice!(i - 1)
perms(substring).map do |s|
results << c + s
# Definition for a binary tree node.
# class TreeNode
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# end
# @param {TreeNode} root
# pair the sublists together
a.zip(b)
=> [[[1], [9]], [[2, 3], [8, 7]], [[4, 5, 6], [6, 5, 4]]]
# collect up the lengths
a.zip(b).collect {|e| e.map(&:length) }
=> [[1, 1], [2, 2], [3, 3]]
# i want each pair of lengths to be the same, so
a.zip(b).collect {|e| e.map(&:length) }.map(&:uniq)
=> [[1], [2], [3]]
# after i made them uniq, are they singular?
/*
* =====================================================================================
*
* Filename: Compose.c
*
* Description: Proc composition
*
* Version: 1.0
* Created: 10/01/2016 16:14:22
* Revision: none