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 / 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 / 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 / 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 / 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 / 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 / gist:3921919
Created October 20, 2012 03:37 — forked from iwasrobbed/gist:1032395
Amazon S3 Query String Authentication for Ruby on Rails
def generate_secure_s3_url(s3_key)
#
# s3_key would be a path (including filename) to the file like: "folder/subfolder/filename.jpg"
# but it should NOT contain the bucket name or a leading forward-slash
#
# this was built using these instructions:
# http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?S3_QSAuth.html
# http://aws.amazon.com/code/199?_encoding=UTF8&jiveRedirect=1
s3_base_url = MyApp::Application::S3_BASE_URL # i.e. https://mybucket.s3.amazonaws.com
# Copy and paste this to the rails console to test your email settings
class MyMailer < ActionMailer::Base
def test_email
@recipients = "malachaifrazier@gmail.com"
@from = "malachaifrazier@gmail.com"
@subject = "test from the Rails Console"
@body = "This is a test email"
end
end
@malachaifrazier
malachaifrazier / Gemfile
Created November 23, 2012 22:59
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
## Rails App Template
## Updated for Rails 3.2.8
## Updated on 9/24/12
## Run using $ rails new [appname] -JT -m https://raw.github.com/gist/960988/template.rb
## Gems
# General
gem 'rake', '0.9.2.2'
# Warden and Devise for security
class Metric
include MongoMapper::Document
key :timestamps, Array
key :action, String
def self.track(action)
collection.update(
{ :action => action },
{ "$push" => { :timestamps => Time.now }},