Skip to content

Instantly share code, notes, and snippets.

if request.xhr?
render "search", layout: false
else
render :index
end
# 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
// application.js
function youtubeResults() {
var youtube_url = $("#youtube_url").text();
...
// Fake "moving forward" to a new URL
History.pushState({main:$("#main").html(), search_term:search_term}, '', search_url);
// 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',
<div id="multiple-datasets">
<input class="typeahead" type="text" placeholder="Poets and Philosophers">
</div>
<%= 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 %>
# 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
[ITEM for ITEM in RANGE if CONDITION]
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]