Skip to content

Instantly share code, notes, and snippets.

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

Malachai malachaifrazier

🏠
Working from home
View GitHub Profile
@malachaifrazier
malachaifrazier / Array confusion 2
Created June 14, 2012 05:00
undefined when checking array in Chrome?
//The USER
function User(name, role){
this.beats = []; //num of beats goes here
this.name = name;
this.role = role;
this.addBeats = function(numbeats){
return this.beats.push(numbeats);
@malachaifrazier
malachaifrazier / sinatra_jquery_test.rb
Created June 28, 2012 19:58 — forked from mr-rock/sinatra_jquery_test.rb
An example of Sinatra working with Ajaxified JQuery based on some pieces of code published by Rafael George on the Sinatra Google Group.
require 'sinatra'
require 'dm-core'
require 'haml'
DataMapper.setup(:default, 'sqlite3::memory:')
class Message
include DataMapper::Resource
property :id, Serial
@malachaifrazier
malachaifrazier / ThugNotes PUT block Edit
Created June 29, 2012 18:38
Is this unless block really needed? n.attribute?
# Are the 'n.attribute' and 'unless' blocks really needed here?
put '/:id' do
n = Note.get params[:id]
n.content = params[:content]
n.complete = params[:complete] ? 1 : 0
n.updated_at = Time.now
if n.save
redirect '/', :notice => "Note updated thuggishly."
else
@malachaifrazier
malachaifrazier / juggernaut.rb
Created July 2, 2012 19:32 — forked from maccman/juggernaut.rb
Sinatra Server Side Event streaming.
# Usage: redis-cli publish message hello
require 'sinatra'
require 'redis'
conns = []
get '/' do
erb :index
end
require "rubygems"
require "httparty"
require "sinatra"
require "omniauth-singly"
SINGLY_API_BASE = "https://api.singly.com"
enable :sessions
use OmniAuth::Builder do
@malachaifrazier
malachaifrazier / home.erb
Created August 6, 2012 02:50
Singly API JSON Parsing
<p> Works! Whats up <%= @display_name %> </p>
@malachaifrazier
malachaifrazier / login.erb
Created August 8, 2012 05:23
Sinatra, Datamapper, PostgreSQL, ruby 1.9.3p194. Horrid Error "NoMethodError at /undefined method `each' for "MyNameHere":String"
<form action="/" method="post">
<p>
<label>Name</label>
<input type="text/plain" name="name" >
</p>
<p>
<input type="submit">
</p>
@malachaifrazier
malachaifrazier / LICENSE.txt
Created August 17, 2012 04:54 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@malachaifrazier
malachaifrazier / loops_iterators.rb
Created August 28, 2012 21:02
Loops & Iterators in Ruby Examples (Tested with Ruby 1.9.3)
#!/usr/bin/ruby
## Count to 50
1.upto(50) {|n| puts n}
## Count Down to 1
50.downto(1) {|n| puts n}
## Count to 20
(1..20).each {|n| puts n}
@malachaifrazier
malachaifrazier / authinabox.rb
Created September 3, 2012 04:01 — forked from nbrew/authinabox.rb
Single File Data Mapper Authentication for Sinatra
# NAME: authinabox
# VERSION: 1.01 (Dec 27, 2008)
# AUTHOR: Peter Cooper [ http://www.rubyinside.com/ github:peterc twitter:peterc ]
# DESCRIPTION: An "all in one" Sinatra library containing a User model and authentication
# system for both session-based logins OR HTTP Basic auth (for APIs, etc).
# This is an "all in one" system so you will probably need to heavily tailor
# it to your own ideas, but it will work "out of the box" as-is.
# COMPATIBILITY: - Tested on 0.3.2 AND the latest rtomayko Hoboken build! (recommended for the latter though)
# - NEEDS DataMapper!
# - Less work needed if you use initializer library -- http://gist.github.com/40238