Skip to content

Instantly share code, notes, and snippets.

View tacitphoenix's full-sized avatar

Samson Ondiek tacitphoenix

View GitHub Profile
// Exercise 1 - OO || !OO
// Define a data structure for cars (make and color), and a function
// that logs a string like "I'm a red Mercedes" to the console.
// Make two versions: a functional version, and a object-oriented version.
// Example call for functional version(Couldn't Figure out):
var logCar = (function(funcCar){
return function(){
console.log("I'm a " + funcCar.color + " " + funcCar.make);
}
@tacitphoenix
tacitphoenix / Mac Bottle Quickstart
Created September 29, 2011 01:47
Quick, Fun and Painless way to setup Bottle on a Mac. Enjoy the minimalistic Python Micro Framework goodness!
Bottle -> The minimalistic Python Mirco Framework
Prequisites:
1) Python 2.7 (This comes with the mac)
2) pip - python package manager (replacement for easy_install) think gems for Ruby
3) virtualenv - manage dependencies created by having multiple projects think rvm for Ruby
4) Bottle Module
Setup
- python -V (check python version should be 2.7.x)
@tacitphoenix
tacitphoenix / gist:1525239
Created December 27, 2011 21:37
Quick intro to Ruby development tools
Install RVM
Run in terminal: bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
Add to end profile: echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
OR
edit and use utilities/rvm_install.sh: ./utilities/rvm_intstall.sh
Basic RVM Commands
http://beginrescueend.com/rvm/best-practices/
rvm -v #what version?
rvm help
@tacitphoenix
tacitphoenix / JavaScalaIO
Created February 1, 2012 19:45
Java|Scala IO
Java
Write serialized object to a file
public static void writeFile(File dest) throws IOException{
FileOutputStream fileStream = new FileOutputStream(dest);
ObjectOutputStream os = new ObjectOutputStream(fileStream);
os.writeObject(obj);
os.close();
}
@tacitphoenix
tacitphoenix / ruby grep
Created January 15, 2014 23:51
Simple file manipulation Ruby snippets
File.open(fname).read.match(/\"accepted_fields\":\s+\[((\d(,)?)+)\]/)
@tacitphoenix
tacitphoenix / loaded rake task
Created January 15, 2014 23:55
A Ruby rake task snippet that has arguments where on is a space delimited array while pulling in the environment
desc 'create basic template e.g. kms:create_template["my template", blog fragment]'
task :create, [:name, :content_type_names] => :environment do |t,args|
unless args[:name] && args[:content_type_names]
puts "Usage: kms:create_template[<name>, <space seperated list of content types>]
exit
end
end
Ruby
start - irb
help - help, then String, String#<TAB>, String.chop
clear - CTRL+L, system(‘clear’)
load file - require “./name.rb” (run keep functions), source “./name.rb” (run keep functions and variables)
exit - exit
Elixir
start - iex
help - h e.g h String, h String.<TAB>, String.chop
defmodule Prime do
def run(n), do: Stream.iterate(1, &(&1 + 1)) |> Stream.filter(&(filter(&1))) |> Enum.take(n)
def filter(n) when n < 4, do: true
def filter(n), do: Enum.map(2..div(n,2), &(not(rem(n,&1) == 0))) |> Enum.all?
end
@tacitphoenix
tacitphoenix / Elixir Keyword Lists
Created August 27, 2016 09:48
Elixir Keyword Lists
Elixir Keyword Lists are a list of two item tuples where the first element of a tuple is an atom
iex(2)> k1 = [{:a, 1}, {:b, 2}, {:c, 3}, {:d, 4}]
[a: 1, b: 2, c: 3, d: 4]
iex(4)> k1 = [a: 1, b: 2, c: 3, d: 4] #a spoonful of sugar
[a: 1, b: 2, c: 3, d: 4]
iex(5)> k1 ++ {:b, 1} #not what we want
[{:a, 1}, {:b, 2}, {:c, 3}, {:d, 4} | {:b, 1}]
@tacitphoenix
tacitphoenix / erlang_mooc_week_one_tests
Last active February 27, 2017 18:23
Unit Test for the first week assignment of the Erlang MOOC
-module(assignment_one_tests).
-include_lib("eunit/include/eunit.hrl").
perimeter_test() -> ?assert(assignment_one:perimeter({triangle, {3,4,5}}) == 12),
?assert(assignment_one:perimeter({right_triangle, {3,4}}) == 12),
?assert(assignment_one:perimeter({square, {4,4}}) == 16),
?assert(assignment_one:perimeter({rectangle, {4,5}}) == 18).
area_test() -> ?assert(assignment_one:area({right_triangle, {3,4}}) == 6),
?assert(assignment_one:area({square, {5,5}}) =:= 25),