Skip to content

Instantly share code, notes, and snippets.

View adamzaninovich's full-sized avatar

Adam Zaninovich adamzaninovich

View GitHub Profile
@adamzaninovich
adamzaninovich / CucumberSteps.rb
Created December 4, 2010 19:33
I just started using cucumber. So far, I've tried to write my steps so that they are very reusable. These were written for mongoid, but they should work with ActiveRecord as well.
# I only have recipes named Steak, Lobster
# I have a recipe named Pizza
Given /^I(\sonly)? have a?n?\s?(.+) named (.+)$/ do |only,table,names|
table.singularize.capitalize.constantize.destroy_all if only
names.split(', ').each do |name|
table.singularize.capitalize.constantize.create(:name => name)
end
end
# I have no recipes
@adamzaninovich
adamzaninovich / mongoid-no-rails.rb
Created December 6, 2010 21:50
Using Mongoid without Rails
require 'mongoid'
Mongoid::Config.instance.from_hash({"database" => "oid"})
class Tweeter
include Mongoid::Document
field :user
embeds_many :tweets
end
@adamzaninovich
adamzaninovich / int.cpp
Created May 3, 2012 02:54
shows the program with and without using an interrupt
/*
This program just toggles an led when you press a button
*/
// without interrupt
#define LED 13
#define BUTTON 2
boolean last = LOW;
@adamzaninovich
adamzaninovich / combinators.hs
Created September 21, 2012 11:25
Striving for combination in Haskell
-- Recursive definition of factorial
fact :: (Num a, Ord a) => a -> a
fact n
| n == 0 = 1
| otherwise = n * fact (n-1)
-- ----------------------------------------------------------------------
-- Improver
fact_improver :: (Int -> Int) -> Int -> Int
@adamzaninovich
adamzaninovich / QuadEncoder.cpp
Created September 25, 2012 18:33
Code used on demo project shown at (http://www.youtube.com/watch?v=a1M5kirA2_8) and (http://www.youtube.com/watch?v=epJ3aSzrsXQ) Includes climate sensing, logging to SD card, HTTP server with JSON output, LCD display with settings menus.
/**
* QuadEncoder.cpp - Library for reading moves from a quadrature rotary encoder
* Created by Pedro Rodrigues (medecau@gmail.com) 9, January of 2010
* Released into the public domain.
*/
#include "Arduino.h"
#include "QuadEncoder.h"
QuadEncoder::QuadEncoder(int pin1, int pin2)
@adamzaninovich
adamzaninovich / gematria.rb
Last active December 14, 2015 03:39
A ruby class to calculate English Gematria. This example uses a mispar hechrachi style correspondence table, but that can easily be swapped out for another table. Class supports raw conversion to number, mapping (breakdown of numbers), and reduction to a single digit (mispar katan mispari). ***Scroll down to see it in action.
# Ruby class to calculate English Gematria
class Gematria < Struct.new(:text)
CORRESPONDENCE_TABLE = { # applies `mispar hechrachi` method to English alphabet (http://www.inner.org/gematria/fourways.php)
a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9,
j: 10, k: 20, l: 30, m: 40, n: 50, o: 60, p: 70, q: 80, r: 90,
s: 100, t: 200, u: 300, v: 400, w: 500, x: 600, y: 700, z: 800
}
def mapped
text.each_char.map { |c| lookup_char c }

Installing Oracle oci8 gem on Mac OS X 10.8

Install Oracle Instant Client Packages

Download Instant Client Packages

Download the following packages from Oracle Technology Network.

You have to sign up for an Oracle Technology Network account, which is lame, Oracle, c'mon.

  • Instant Client Package - Basic or Basic Lite
  • Instant Client Package - SDK
@adamzaninovich
adamzaninovich / git.sh
Last active December 20, 2015 16:09
Some helpful git functions
# g: with no args: runs short status
# with args: acts as `git`
function g () {
if [[ $# > 0 ]]
then
git $@
else
git status -sb
fi
}
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
bool is_vowel(char arg) {
int i;
char vowels[] = "aeiou";
if(arg < 91) arg += 32;
for (i = 0; i < strlen(vowels); ++i) {
if (arg == vowels[i]) return true;
Hello from vim!!!