Skip to content

Instantly share code, notes, and snippets.

http://guides.rubyonrails.org/getting_started.html

Rails Guides Getting Started Notes

rails new -h see all app builder switches

File/Folder Purpose

app/ Contains the controllers, models, views and assets for your application. You'll focus on this folder for the remainder of this guide.
config/ Configure your application's runtime rules, routes, database, and more. This is covered in more detail in Configuring Rails Applications
config.ru Rack configuration for Rack based servers used to start the application.

@emad-elsaid
emad-elsaid / problem 2.php
Created January 30, 2014 21:06
project euler problem 2 solution
<?php
define('LIMIT', 4000000);
$previous = 1;
$current = 2;
$result = 0;
while($current<LIMIT){ // while we didn't reach the limit
@emad-elsaid
emad-elsaid / problem 2.rb
Created January 30, 2014 23:13
project euler problem 2 solution using ruby
LIMIT = 4000000
previous = 1
current = 2
result = 0
while current<LIMIT # while we didn't reach the limit
# add it if even
@emad-elsaid
emad-elsaid / problem3.rb
Last active August 29, 2015 13:56
project euler problem 3 solution.
factor = 600851475143
for divider in 2...factor # check if number is prime
# divide it and retry of number is divisible
factor /= divider and retry if factor%divider==0
end
puts factor # here is out prime part
# this is my output and timing ;)
# time ruby problem3.rb
@emad-elsaid
emad-elsaid / gist:8939058
Created February 11, 2014 16:59
Facebook Meme pages
Yao Ming’s Bitch please fakss
Yao Ming crying fakss31
Yao ming Forever alone foreverdontcare fakss34
Yao Ming zingy 3leko fakss32
Troll face trollmeme
Adel Imam aho 8lasa kda ahowkda
Are you fucking kidding me? atmz7
Flipped Are you fucking kidding me? atmz77
Are you serious? areyouseriousmeme
Mr. Bean’s If you know what I mean [[ifuknowwhatimean]][[youknowwhatimean]][[mrbeanmeme]]
@emad-elsaid
emad-elsaid / problem70.rb
Created February 14, 2014 03:26
projecteuler 70 solution - tooooo long solution
class Integer
@@permutation_matrices = {}
@@phis = {}
def phi
return @@phis[self] unless @@phis[self].nil?
@@phis[self] = (1...self).select{ |x| gcd(x)==1 }.length
end
def permutation?(other)
permutation_matrix==other.permutation_matrix
end
@emad-elsaid
emad-elsaid / problem4.rb
Created February 15, 2014 18:11
project euler problem 4
class Integer
def palindrom?
"#{self}"=="#{self}".reverse
end
end
largest = 0
for n1 in 100..999
for n2 in n1..999
largest = n1*n2 if (n1*n2).palindrom? and n1*n2>largest
@emad-elsaid
emad-elsaid / permutation.rb
Created February 16, 2014 22:10
check if numbers are permutation of each other
class Integer
def number_matrix
m = Array.new.fill 0,0..9
tmp = self
while tmp>0
digit = tmp%10
tmp = tmp/10
m[digit] = m[digit]+1
end
@emad-elsaid
emad-elsaid / integer2array.rb
Created February 19, 2014 10:50
convert integer to array in ruby
class Integer
def to_a
arr = []
tmp = self
while tmp>0
arr << tmp%10
tmp /= 10
end
arr.reverse
end
@emad-elsaid
emad-elsaid / multi-equal-check.rb
Created February 19, 2014 19:45
multiple equal in ruby
class Array
def same?
uniq.length==1
end
end
x = 1
y = 2
z = 2
l = 2