Skip to content

Instantly share code, notes, and snippets.

View oliverswitzer's full-sized avatar
🏠
Working from home

Oliver Switzer oliverswitzer

🏠
Working from home
View GitHub Profile
@oliverswitzer
oliverswitzer / spec_helper.rb
Created December 9, 2013 14:37
rspec helper file
RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :documentation # :progress, :html, :textmate
end
def fibo_finder
if n < 2
n
else
fibo_finder(n-1) + fibo_finder(n-2)
end
end
@oliverswitzer
oliverswitzer / js_practice.js
Created January 20, 2014 21:15
JS Practice
> typeof(3)
'number'
> typeof(3) === typeof(4.32)
true
> 5/0
Infinity
> 3/"bob"
NaN
> NaN === NaN
false
What does the following code evaluate to?
var first_name = function (name) {
return name;
}
first_name("bob");
--> 'bob'
What does the following code evaluate to?
function add(x, y) {
return x + y;
What does the following code print to the console?
var person = {
name: "Joe Camel",
age: 42,
status: "dead"
}
console.log(typeof person);
--> Object {name: "Joe Camel", age: 42, status: "dead"}
@oliverswitzer
oliverswitzer / mixpanel_api.js
Created March 27, 2014 21:14
A node script to get data from mixpanel API and output it to a CSV
// mixpanel_export.js
// node modules
http = require('http');
Mixpanel = require('mixpanel');
md5 = require('MD5');
jsoncsv = require('jsoncsv');
fs = require('fs');
stringify = require('csv-stringify');
# Intro
Writing changeable code: three different skills
- 1. understand OO design. Code that is easy to change IS well designed.
- 2. skilled at refactoring. Quote from Fowler
--> also maybe insert quote from Kent Beck:
"make the change easy (warning: this may be hard), then make the easy change"
- refactoring is how you morph code to accommodate new requirements. Prefactor vs refactor?
- 3. High value tests!
- Good tests don't need to be changed when you refactor.
@oliverswitzer
oliverswitzer / bonus_merge_multiple_arrays.rb
Created May 20, 2020 19:30
Interview Cake Merge Multiple Sorted Arrays question
# In order to win the prize for most cookies sold, my friend Alice and I are going to merge our Girl Scout Cookies orders and enter as one unit.
#
# Each order is represented by an "order id" (an integer).
#
# We have our lists of orders sorted numerically already, in arrays. Write a method to merge our arrays of orders into one sorted array.
#
# For example:
#
# my_array = [3, 4, 6, 10, 11, 15]
# alices_array = [1, 5, 8, 12, 14, 19]
@oliverswitzer
oliverswitzer / nonModuleDirList.js
Created February 24, 2014 19:01
An example of a script that will filter files with certain extensions in Node.js
// asynchDirList.js
var fs = require('fs'); //require node filesystem module
var path = require('path'); //require node path module (a couple of tools for reading path names)
var pathSupplied = process.argv[2];
var extFilter = process.argv[3];
function extension(element) {
var extName = path.extname(element);
def find_duplicate(int_array)
current_position = int_array[-1]
# Step 1: Get our cursor to the end of the int array list, so that we
# are guaranteed to be in a loop when we try to find the loop length
(int_array.length - 1).times do
current_position = int_array[current_position - 1]
end
loop_start_position = current_position