Skip to content

Instantly share code, notes, and snippets.

@elsapet
elsapet / clean_up_rules.rb
Last active April 6, 2023 09:35
Clean up rules
require 'yaml'
def excluded_dir?(filename)
filename == "." || filename == ".."
end
%w(javascript ruby).each do |lang|
puts "Renaming #{lang} snapshots..."
Dir.foreach(lang+"/") do |subfolder|
class AnimalsController < ApplicationController
inherit_resources
..
protected
def build_resource_params
animal_params = params.fetch(:animal, {}).permit(:name, :age, :family)
[prepare_animal_params(animal_params)]
class PaginatingDecorator < Draper::CollectionDecorator
delegate :current_page, :total_pages, :limit_value
end
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]
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]
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]
[ITEM for ITEM in RANGE if CONDITION]
# 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
<%= 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 %>
<div id="multiple-datasets">
<input class="typeahead" type="text" placeholder="Poets and Philosophers">
</div>