Skip to content

Instantly share code, notes, and snippets.

@jennli
jennli / permutation.rb
Created January 13, 2016 00:24
permutation
#permutation exercise
char_array = Array.new
loop do
puts "Enter three characters separated by a space ' ' "
answer = gets.chomp
char_array = answer.split ();
array_words = []
loop do
puts "please enter some book names one at a time, hit exit when you are done"
name = gets.chomp
break if name.upcase == "EXIT"
array_words << name
end
@jennli
jennli / slice.rb
Last active January 14, 2016 17:18
# Given an array of arrays:
# ?
# 1
# array = [[2,3,4], [5,6,7], [6,7,8]]
#
# Write a piece of code that will take that array and
#give back an array of arrays with each element multiplied by itself so you will get back:
# ?
# 1
# [[4, 9, 16], [25, 36, 49], [36, 49, 64]]

computing: not knowing how to solve a specific problem but to create a series of steps

#recursion Uses stack - LIFO - puts a call on stack, which is a part of the memory

def sum(array)
  if array.empty?
    0
  else
def flatten_r(array)
if array.empty?
array
elsif array.size == 1
if array[0].is_a? Array
flatten_r(array[0])
else
array
end
function fizzbuzz(fizz, buzz)
{
if (typeof(fizz) !== "number" || typeof(buzz) !== "number"){
console.error("one of your parameter is not a number!");
return ;
}
for (var i = 1 ; i <=100; i++ ){
if (i % fizz === 0 && i % buzz === 0){
// //lab 1
// Write a function called printMulti that takes an array of arrays, such as:
// var my_array = [[2,3,4], ["Hello CodeCore", 1, true]];
// and prints every element to the console.
var my_array = [[2,3,4], ["Hello CodeCore", 1, true]];
function printArray(arr){
if(arr.length == 0){
  • install postgres
brew install postgresql

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  • install rails
@jennli
jennli / TDD.md
Last active March 16, 2016 17:48

#Test Driven Development

  • Write test cases before you write the code

###Test frameworks

  • UnitTest vs. RSpec
  • three phases: given , when, then

Gems and installation commands

  gem 'rspec-rails'
2.2.3 :006 > a.each do |x|
2.2.3 :007 >     puts x.body
2.2.3 :008?>   end
comment123
+----+------------+------------------------+-------------------------+---------+
| id | body       | created_at             | updated_at              | post_id |
+----+------------+------------------------+-------------------------+---------+
| 1  | comment123 | 2016-02-04 07:00:34... | 2016-02-04 07:47:09 UTC | 221     |
+----+------------+------------------------+-------------------------+---------+