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 / application.html.erb
Created September 25, 2012 15:16
current_user.full_name shows method error because there is no user yet. Toss a conditional in there to fix all the things. if user_signed_in?
<!DOCTYPE html>
<html>
<head>
<title>Treebook</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div class="navbar navbar-fixed-top">
@malachaifrazier
malachaifrazier / gist:3606774
Created September 3, 2012 04:50 — forked from peterc/gist:40238
DM-oriented initializer for Sinatra apps
# NAME: initializer
# VERSION: 1.0
# AUTHOR: Peter Cooper [ http://www.rubyinside.com/ github:peterc twitter:peterc ]
# DESCRIPTION: Sinatra library to perform initialization functions - oriented around DataMapper use
# COMPATIBILITY: All, in theory - tested on Hoboken
# LICENSE: Use for what you want
#
# INSTRUCTIONS:
# 1. Ensure _this_ file is lib/initializer.rb within your app's directory structure
# 2. Read through and customize this file to your taste and your app's requirements
@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
@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 / 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 / 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 / home.erb
Created August 6, 2012 02:50
Singly API JSON Parsing
<p> Works! Whats up <%= @display_name %> </p>
require "rubygems"
require "httparty"
require "sinatra"
require "omniauth-singly"
SINGLY_API_BASE = "https://api.singly.com"
enable :sessions
use OmniAuth::Builder do
@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
@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