Skip to content

Instantly share code, notes, and snippets.

View brianium's full-sized avatar
🕊️
Human

Brian Scaturro brianium

🕊️
Human
View GitHub Profile
@brianium
brianium / gist:4436179
Created January 2, 2013 17:10
7 weeks of 7 Langues - Io Day 1 Simple Program
Party := Object clone
Party getRowdy := ("Rabble rabble rabble" println)
Party getRowdy
@brianium
brianium / acts_as_csv_module.rb
Created December 31, 2012 17:01
7 weeks of 7 languages - Ruby Day 3 Metaprogramming
module ActsAsCsv
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def acts_as_csv
include InstanceMethods
end
end
module InstanceMethods
@brianium
brianium / tree.rb
Created December 29, 2012 21:45
Tree solution for Ruby Day 2 HW
class Tree
attr_accessor :children, :node_name
def initialize(node = {})
(node.length == 1) && (@node_name = node.first[0]) || @node_name = 'root'
children = (@node_name == 'root') ? node : node[@node_name]
@children = []
children.each do |k, v|
@children.push(Tree.new({k => v}))
end
@brianium
brianium / guess.rb
Created December 28, 2012 02:38
7 weeks of 7 langues: Ruby Day 1 Bonus Challenge
puts "Guess a number between 1 and 10\n"
goal = rand(10) + 1
until((answer = gets.chomp) == goal.to_s)
puts "Too low\n" if answer.to_i < goal
puts "Too high\n" if answer.to_i > goal
end
puts "Good job! You guessed #{goal} correctly!\n"
@brianium
brianium / grunt.js
Created December 1, 2012 19:15
grunt file
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
concat: {
dist: {
src: [
'vendor/bootstrap.js',
'vendor/underscore.js',
@brianium
brianium / reltypes.scala
Created November 12, 2012 15:31
neo4j relationship types in scala
package com.brianscaturro
import org.neo4j.graphdb.RelationshipType
object RelTypes extends Enumeration {
type RelTypes = Value
val KNOWS = Value
implicit def conversion(rt: RelTypes) = new RelationshipType() { def name = rt.toString }
}
@brianium
brianium / scproj.sh
Created September 3, 2012 22:43
bash script for making a new sbt project
#!/bin/bash
mkdir -p src/main/{resources,scala}
mkdir -p "src/test/"{resources,scala}
mkdir -p src/it/{resources,scala}
mkdir project
#create project files
echo "sbt.version=0.11.3" > project/build.properties
echo -e 'resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"\n' > project/plugins.sbt
echo 'addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0-SNAPSHOT")' >> project/plugins.sbt
@brianium
brianium / repo.get.scala
Created August 30, 2012 02:13
repo get
def get(fbid: String):Option[FacebookObject] = {
val response = graphFetch(fbid)
response().map(jstr => {
val js = jstr.asJson.asJsObject
val obj = js.convertTo[FacebookObject]
val comments = js.getFields("comments")
if (comments.isEmpty) obj else build(obj, comments.head.asJsObject.convertTo[CommentsJson])
})
}
@brianium
brianium / euler1.scala
Created August 28, 2012 19:29
euler problem 1
(for(i <- 1 to 999 if(i % 3 == 0 || i % 5 == 0)) yield i) reduceLeft(_ + _)
@brianium
brianium / gist:3165240
Created July 23, 2012 18:27
is_mobile
function isMobileDevice()
{
var agent = navigator.userAgent.toLowerCase();
var otherBrowser = (agent.indexOf("series60") != -1) || (agent.indexOf("symbian") != -1) || (agent.indexOf("windows ce") != -1) || (agent.indexOf("blackberry") != -1);
var mobileOS = typeof orientation != 'undefined' ? true : false;
var touchOS = ('ontouchstart' in document.documentElement) ? true : false;
var iOS = (navigator.platform.indexOf("iPhone") != -1) ||
(navigator.platform.indexOf("iPad") != -1) ? true : false;
var android = (agent.indexOf("android") != -1) || (!iOS && !otherBrowser && touchOS && mobileOS) ? true : false;