http://guides.rubyonrails.org/association_basics.html
- belongs_to : TABLE_NAME
- has_one : TABLE_NAME [:through => :TABLE_NAME]
- has_many : TABLE_NAME [:through => :TABLE_NAME]
- has_and_belongs_to_many : TABLE_NAME [:join_table => :TABLE_NAME]
http://guides.rubyonrails.org/association_basics.html
require "test/unit" | |
class ListTester < Test::Unit::TestCase | |
def test_node_integrity | |
node = Node.new(1) | |
assert_equal(1,node.value) | |
assert_equal(nil,node.next_node) | |
assert_equal(nil,node.previous_node) | |
end |
class String | |
# Opens up string class, to allow these methonds to be called directly on the string rather than passed as a variable to a method. | |
def rev_string | |
# Splits the string into an array, for iterative purposes | |
str_arr = self.chars | |
# Builds a temporary array | |
tmp_arr = [] | |
str_arr.length.times do | |
# grabs the end of the str_array, and makes it the first of our new array | |
tmp_arr << str_arr.pop |
def multiples_up_to(multiple, limit) | |
# Rather than calculate every number and evaluate whether that number is a multiple, there's a handy bit of math I found that checks how many multiples are in any number of integers. | |
# We then keep adding up the "multiple", doing basic arithmetic until we reach the limit | |
start = 0 | |
((limit - multiple + 1)/multiple).times do | |
start += multiple | |
p start | |
end | |
end |
This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.
# Add your Python code here. E.g. | |
from microbit import * | |
import radio | |
nodes = ["00","01","02","10","11","12","20","21","22"] | |
board = [ | |
["","",""], | |
["","",""], | |
["","",""] | |
] |
# Add your Python code here. E.g. | |
from microbit import * | |
import random | |
playing = False | |
winner = "-" | |
min_time = 300 | |
max_time = 700 | |
while True: |
from microbit import * | |
while True: | |
moisture = pin0.read_analog() | |
if button_a.is_pressed(): | |
if moisture <= 1023 and moisture > 0: | |
display.scroll(moisture) | |
else: | |
display.show(Image.SAD) | |
sleep(5000) |