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
// In our DOM ready | |
var poets = new Bloodhound({ | |
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'), | |
queryTokenizer: Bloodhound.tokenizers.whitespace, | |
limit:10, | |
prefetch: { | |
// url points to a json file that contains an array of author names | |
// e.g. ['Baudelaire', 'Beckett'] | |
url: './poets.json', |
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
<div id="multiple-datasets"> | |
<input class="typeahead" type="text" placeholder="Poets and Philosophers"> | |
</div> |
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
<%= semantic_nested_form_for [:admin, @user], :html => {:multipart => true} do |f| %> | |
<%= f.inputs 'User Information' do %> | |
<%= f.input :name %> | |
<%= f.input :age %> | |
<% end %> | |
<%= f.inputs 'User's Pet' for: [:pet, f.object.pet || Pet.new] do |pet| %> | |
<%= pet.input :name %> | |
<% 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
# collect the even numbers in a given range | |
# 1. using regular py | |
evens = [] | |
for i in range(1, 10): | |
if i % 2 == 0: | |
evens.append(i) | |
# 2. using list comprehension |
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
[ITEM for ITEM in RANGE if CONDITION] |
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
n = 100 | |
whole_factors = [i for i in range(1, n) if 0 == len([j for j in range(2, i-1) if i%j == 0])] | |
print whole_factors # => [1, 2, 3, 5, 7, ..., 97] |
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
n = 100 | |
primes = (1..n).map{ |i| i if (2..i-1).map{ |j| j if i%j == 0}.compact.count == 0}.compact | |
puts primes.inspect # => [1, 2, 3, 5, 7, ..., 97] |
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
n = 100000 | |
primes = (0..n).select{ |i| i if (2..i-1).select{ |j| j if i%j == 0}.count == 0} | |
puts primes.inspect # => [1, 2, 3, 5, 7, ..., 9973] |
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 PaginatingDecorator < Draper::CollectionDecorator | |
delegate :current_page, :total_pages, :limit_value | |
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 AnimalsController < ApplicationController | |
inherit_resources | |
.. | |
protected | |
def build_resource_params | |
animal_params = params.fetch(:animal, {}).permit(:name, :age, :family) | |
[prepare_animal_params(animal_params)] |
OlderNewer