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 / 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 / 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 / test_helper.rb
Created September 27, 2012 03:21
ActionView::Template::Error: undefined method `authenticate?' for nil:NilClass
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
@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 = "[email protected]"
@from = "[email protected]"
@subject = "test from the Rails Console"
@body = "This is a test email"
end
end
@malachaifrazier
malachaifrazier / development.rb
Created November 21, 2012 03:39
Rails 3 ActionMailer w/GMail fail
# ( Using Rail 3.2.8 )
# I have my development.rb file :
ButterApp::Application.configure do
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
@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
@malachaifrazier
malachaifrazier / index.html.erb
Created December 13, 2012 04:59
audio_tag fun in Rails 3.2.9 '<p>Your browser does not support the audio element. Use Chrome. </p>'
# If I have one of these
<%=audio_tag track.audio,:type =>"mp3/audio",:controls =>true,:autoplay =>false,:preload =>:auto%>
# Where do I put this?
<p>Your browser does not support the audio element. Use Chrome. </p>
class Metric
include MongoMapper::Document
key :timestamps, Array
key :action, String
def self.track(action)
collection.update(
{ :action => action },
{ "$push" => { :timestamps => Time.now }},