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
if request.xhr? | |
render "search", layout: false | |
else | |
render :index | |
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
# home_controller.rb | |
if request.xhr? | |
search = params[:search] | |
numberYouTube = '10' | |
@youtube_url = 'http://gdata.youtube.com/feeds/api/videos?q='+search.inspect+'&format=5&max- results='+numberYouTube+'&v=2&alt=jsonc' | |
render "search", layout: false |
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
// application.js | |
function youtubeResults() { | |
var youtube_url = $("#youtube_url").text(); | |
... |
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
// Fake "moving forward" to a new URL | |
History.pushState({main:$("#main").html(), search_term:search_term}, '', search_url); |
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] |
OlderNewer