Skip to content

Instantly share code, notes, and snippets.

View mosdevly's full-sized avatar

Mosdev mosdevly

  • San Francisco, CA
View GitHub Profile
@mosdevly
mosdevly / gist:36a18c48992e77d0cf85
Last active August 29, 2015 14:27 — forked from learncodeacademy/gist:5f84705f2229f14d758d
Getting Started with Vagrant, SSH & Linux Server Administration
ORIGINAL: From Wayback Machine http://bit.ly/1Ghmzap
In this post lets talk about, making lives easier while testing django models and forms. This is the fourth article in our Test Driven Development Series. Until now, we have already talked about intro to TDD, basic testing django views and models and functional testing with selenium.
Testing Django Models
=====================
By default when django runs against sqlite backend it creates a new in memory database for a test, based on the fixtures which you have kept. Application fixtures are a great way to test, but these are limited to the cases where you have a constant data model. But the projects we deal with are much more complicated than just having simple models, and manually managed fixtures are an inflexible solution for providing the test case data. Test fixtures are hard to maintain, when trying to reproduce complex referential associations. Doing it manually or monkey patching gets us into more trouble as we fail, more often than not in mainta
@mosdevly
mosdevly / fibonacci.py
Last active August 29, 2015 14:17
Fibonacci Sequence
def fibonacci(i):
a, b = 0, 1
while a < i:
print a,
a, b = b, a+b
Provider Singleton Instantiable Configurable
Constant Yes No No
Value Yes No No
Service Yes No No
Factory Yes Yes No
Decorator Yes No? No
Provider Yes Yes Yes

Constant

def ftoc (fah)
cel = ((fah - 32.0) * 5) / 9
end
def ctof (cel)
fah = (cel * 9 / 5) + 32.0
end
@mosdevly
mosdevly / Reverse Classic
Created January 7, 2015 01:30
Reverse a string in place (no new strings!).
def rev(str)
a = 0
current = str.length - 1
while a < str.length / 2
current -= a
char_one = str[a]
char_two = str[current]
def num_square(max)
i = 0
squares = []
while i < max
product = i * i
if product < max
squares.push(product)
end
i+= 1
def merge(arr1, arr2)
arr1.each do |number|
arr2.push(number)
end
puts arr2.sort
end
def most_common(word)
letters = {}
word.each_char do |letter|
if letters.has_key?(letter)
letters[letter] += 1
else
letters[letter] = 1
end
end
def class_list
students = []
p "Would you like to add a student? (y/n)"
add_student = gets.chomp
if add_student == "y"
p "You may begin adding names at any time. Press Enter after each name."
p "Type QUIT at anytime to stop adding students."