###One to One
###One to Many
###Many to Many
###One to One
###One to Many
###Many to Many
#SQLite3
CREATE TABLE tablename (id PRIMARY KEY AUTOINCREMENT, name string, age integer)
INSERT INTO tablename VALUES(Milan, 43)
md = "cheese".match([^aeiou]*)(.*) | |
md == <MatchDate "cheese" 1: "ch" 2: "eese"> | |
md[1] => "ch" | |
md[2] => "eese" |
(?<=a)b #=> positive lookbehind: matches a "b" that IS preceded by an "a", using negative lookbehind. | |
(?<!a)b #=> negative lookbehind: matches a "b" that IS NOT preceded by an "a", using negative lookbehind. |
def binary_search(target, array, low=0, high = (array.length-1)) | |
return -1 if low > high | |
mid_point = (low + high)/2 | |
return mid_point if array[mid_point] == target | |
if target < array[mid_point] | |
high = mid_point - 1 | |
else | |
low = mid_point + 1 |
def prime_factors(num) | |
return [] if num == 1 | |
first_factor = (2..num).find{|x| num % x == 0} | |
factors = prime_factors(num/first_factor) | |
factors.unshift(first_factor) | |
end | |
#Test Driver Code: | |
puts prime_factors(1) == [] |
The yield Statement: Let's look at an example of the yield statement:
def test
puts "You are in the method"
yield
puts "You are again back to the method"
yield
end
def fibonacci_iterative(n) | |
return 0 if n == 0 | |
prime = 0 | |
omega = 1 | |
(n-1).times do | |
alpha = omega + prime | |
prime = omega | |
omega = alpha | |
end | |
return omega |
# Implement an iterative version of the factorial function | |
def factorial_iterative(n) | |
return 1 if n <= 1 | |
(1..n).inject {|product, num| product * num} | |
end | |
# Implement a recursive version of the factorial function | |
def factorial_recursive(n) | |
return 1 if n <= 1 | |
n * factorial_recursive(n - 1) |
#Sublime Text Shortcuts
CTRL-SHIFT-UP/DOWN => multiple cursors
CMD-D => select next occurences
CMD-CTRL-G => select all occurences of a word you can edit
OPT/ALT-ENTER = > find all
CTRL/TAB or CTRL/SHIFT/TAB => toggle tabs
FUNC-DELETE => delete forward