Skip to content

Instantly share code, notes, and snippets.

@waneka
waneka / gist:6051477
Created July 22, 2013 05:30
Why is this printing multiples of 5 instead of just 5 times?
def print_triangle(rows)
top = (1..rows).to_a
i = 1
while i <= rows
top.map { |x| i.times { print "*" } }
puts "\n"
i += 1
end
end
@waneka
waneka / gist:6075634
Created July 24, 2013 23:38
Socrates wants Array#pad! to be destructive and Array#pad to be non-destructive. when i run the code in my console, everything appears to operate just fine. however, socrates is giving me an error for Array#pad operates non-destructively. any help?
class Array
def pad!(min_size, value = nil)
while length < min_size
self << value
end
self
end
def pad(min_size, value = nil)
if min_size > length
class Disasters
attr_reader :name, :yield_destroyed, :probability
def initialize(name, yield_destroyed, probability)
@probability = probability
@name = name
@yield_destroyed = yield_destroyed
end
end
*Solution for Challenge: Research: View and Form Helpers. Started 2013-10-05T19:23:49+00:00*
# link_to
**link_to** is a rails helper that helps generate html link tags in views and controllers. ``link_to`` "relies on" (whatever that means) ``url_for`` - a similar (but different) helper that generates links in views and controllers. From the [ActionView docs] (http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to):
```ruby
link_to(name = nil, options = nil, html_options = nil, &block)
```
*Creates a link tag of the given name using a URL created by the set of options.*
@waneka
waneka / helpers.md
Last active December 24, 2015 22:49

Solution for Challenge: Research: View and Form Helpers. Started 2013-10-05T19:23:49+00:00

link_to

link_to is a rails helper that helps generate html link tags in views and controllers. link_to "relies on" (whatever that means) url_for - a similar (but different) helper that generates links in views and controllers. From the [ActionView docs] (http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to):

link_to(name = nil, options = nil, html_options = nil, &block)

Creates a link tag of the given name using a URL created by the set of options.

@waneka
waneka / Javascript Snippets.js
Last active December 28, 2015 19:59
These snippets are some examples of some javascript that I've written.
Here are two snippets of JavaScript that I am proud of from a project called queued.fm which is a web app
that allows for collaborative DJing at a party. Check the app out here: http://qd-fm.herokuapp.com/
This first snippet handles the upvote process when users click on a song in the queue. We used Firebase to handle
all the backend for the site. The Sync functions you see are just checking Firebase to see if that user has
previously voted on that particular song.
upVote: function(e){
var songItem = $(e.target).closest('li')
var songID = songItem.data('songkey')
@waneka
waneka / Ruby Snippets.rb
Created November 19, 2013 23:15
A selection of Ruby snippets
The following are snippets from the fantasy politics web app that we made. Unfortunately,
it's not currently online for your viewing. :(
This is a snippet from the view for the team page.
<h3><%= @queried_team.name %> <br>Total Score: <%= @queried_team.team_score(1) %></h3>
<p>A team can consist of up to four senators and four congressmen</p>
<div id="team_members">
<h4>Team Members:</h4>
<ul class="sortable">
@waneka
waneka / in_words_tyler_and_nick
Created March 11, 2014 05:10
Phase 1 in_words function TO ZILLIONS! (with TDD)
ONES_PLACE = {
1 => "one",
2 => "two",
3 => "three",
4 => "four",
5 => "five",
6 => "six",
7 => "seven",
8 => "eight",
9 => "nine"
var input = process.argv[2]
var matcher = { 41: 40, 93: 91, 125: 123 }
var tracker = []
input.split('').forEach(function(symbol) {
var code = symbol.charCodeAt(0)
if (code === 40 || code === 91 || code === 123) {
tracker.push(code)
} else if (code === 41 || code === 93 || code === 125) {
var a = process.argv[2],
b = process.argv[3]
var container = []
function sample(members, limit) {
for (var i=0;i<members;i++) {
container.push(~~(Math.random() * limit) + 1)
}
return container
}