This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inside helper class | |
def render_share_partial | |
class SharePresenter | |
attr_accessor :campaign, :message | |
def campaign_title | |
self.campaign.name | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use: | |
# This is in file config.ru | |
# 1) gem install rack | |
# 2) rackup | |
# 3) visit http://localhost:9292 in browser | |
# 4) Timer info will be in console | |
# 5) when changing code, will have to restart rackup | |
# Include rack | |
require 'rack' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Generator #1 is off. | |
Generator #2 is on, adding 62 MW, for a total of 62 MW! | |
Generator #3 is off. | |
Generator #4 is on, adding 62 MW, for a total of 124 MW! | |
Generator #5 is off. | |
Generator #6 is on, adding 124 MW, for a total of 248 MW! | |
Generator #7 is off. | |
Generator #8 is on, adding 124 MW, for a total of 372 MW! | |
Generator #9 is off. | |
Generator #10 is on, adding 124 MW, for a total of 496 MW! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var userAge = prompt("What's your age, user?"); | |
var ageIsCorrect = false; | |
while (ageIsCorrect == false) { | |
ageIsCorrect = confirm("You entered " + userAge + ". Is this correct?"); | |
if (ageIsCorrect) { | |
alert("Great! Your age is logged as " + userAge + "."); | |
} else { | |
userAge = prompt("What's your age, user?"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
['+', '-', ''].repeated_permutation(8).each do |perm| | |
sumText = ('1'..'8').zip(perm).flatten.join + '9' | |
sum = eval(sumText) | |
if sum == 100 | |
puts "#{sumText} = 100" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 + 2 + 3 - 4 + 5 + 6 + 78 + 9 | |
1 + 2 + 34 - 5 + 67 - 8 + 9 | |
1 + 23 - 4 + 5 + 6 + 78 - 9 | |
1 + 23 - 4 + 56 + 7 + 8 + 9 | |
12 + 3 + 4 + 5 - 6 - 7 + 89 | |
12 + 3 - 4 + 5 + 67 + 8 + 9 | |
12 - 3 - 4 + 5 - 6 + 7 + 89 | |
123 + 4 - 5 + 67 - 89 | |
123 - 4 - 5 - 6 - 7 + 8 - 9 | |
123 + 45 - 67 + 8 - 9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a function that given a list of non negative integers, arranges them such that they form the largest possible number. | |
# For example, given [50, 2, 1, 9], the largest formed number is 95021. | |
def max_num(arr) | |
# find the longest number | |
max_size = arr.map{|n| n.to_s.length}.max | |
# padded num repeats the last number in string up until the max length of a specific number | |
# then we append a number wich will help us get the shorter number first when all else equal | |
# sort by the padded number, reverse it, and then convert it back to integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "start console" | |
task :console do | |
require 'irb' | |
require 'irb/completion' | |
require ::File.expand_path('../config/environment', __FILE__) | |
ARGV.clear | |
IRB.start | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyList do | |
# Takes 2 lists like [1,2] and [3,4] | |
# and produces a single list like [1,3,2,4] | |
def zip_merge([heada | taila], [headb | tailb]) do | |
[heada] ++ [headb] ++ zip_merge(taila, tailb) | |
end | |
def zip_merge([heada | taila], []) do | |
[heada] ++ zip_merge(taila, []) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UnionFind | |
attr_accessor :nodes, :sizes | |
def initialize(num) | |
self.nodes = [] | |
self.sizes = [] | |
num.times do |n| | |
self.nodes[n] = n |
OlderNewer