Skip to content

Instantly share code, notes, and snippets.

View MilanGrubnic70's full-sized avatar

Milan Grubnic MilanGrubnic70

View GitHub Profile
@MilanGrubnic70
MilanGrubnic70 / database_relationships.md
Created April 20, 2014 13:57
Database Relationships

###One to One

###One to Many

###Many to Many

@MilanGrubnic70
MilanGrubnic70 / sqlite3.md
Last active August 29, 2015 14:00
SQLite3

#SQLite3

CREATE TABLE tablename (id PRIMARY KEY AUTOINCREMENT, name string, age integer)

INSERT INTO tablename VALUES(Milan, 43)

@MilanGrubnic70
MilanGrubnic70 / pig_latin.txt
Last active August 29, 2015 14:00
Pig Latin
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) == []
@MilanGrubnic70
MilanGrubnic70 / yield.md
Last active August 29, 2015 14:00
Yield

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
@MilanGrubnic70
MilanGrubnic70 / fibonacci.rb
Last active August 29, 2015 14:00
Fibonacci
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)
@MilanGrubnic70
MilanGrubnic70 / sublime_shortcuts.md
Last active July 12, 2017 03:02
Sublime Text shortcuts

#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