Skip to content

Instantly share code, notes, and snippets.

@chrise86
chrise86 / application.rb
Created May 26, 2012 08:53
A rails log silencer for specific calls / actions
# config/application.rb
require File.dirname(__FILE__) + '/../lib/custom_logger.rb'
module MyApp
class Application < Rails::Application
# Middlewares
config.middleware.swap Rails::Rack::Logger, CustomLogger, :silenced => ["/noisy/action.json"]
end
end
# Drop this file in config/initializers to run your Rails project on Ruby 1.9.
# This is three separate monkey patches -- see comments in code below for the source of each.
# None of them are original to me, I just put them in one file for easily dropping into my Rails projects.
# Also see original sources for pros and cons of each patch. Most notably, the MySQL patch just assumes
# that everything in your database is stored as UTF-8. This was true for me, and there's a good chance it's
# true for you too, in which case this is a quick, practical solution to get you up and running on Ruby 1.9.
#
# Andre Lewis 1/2010
# encoding: utf-8
@chrise86
chrise86 / will_paginate_bootstrap.rb
Created June 11, 2012 14:29 — forked from corny/will_paginate_bootstrap.rb
WillPaginate renderer for will_paginate 2.3.16 to generate HTML code for Twitter Bootstrap
#
# WillPaginate renderer for will_paginate 2.3.16 to generate HTML code for Twitter Bootstrap
# Put this content in in your config/initializers/will_paginate.rb
module WillPaginate
module ViewHelpers
class BootstrapLinkRenderer < LinkRenderer
def to_html
@chrise86
chrise86 / registrations_controller.rb
Created December 10, 2012 11:20 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@chrise86
chrise86 / curl.md
Created January 31, 2013 14:29 — forked from btoone/curl.md

Introduction

An introduction to curl using GitHub's API

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
@chrise86
chrise86 / gist:4683272
Last active December 12, 2015 00:19 — forked from aaronvb/gist:1087368
if Rails.env == "development"
Dir.foreach("#{Rails.root}/app/models") do |model_name|
require_dependency model_name unless model_name == "." || model_name == ".."
end
end
# or for nested models
if Rails.env == "development"
Dir.glob("#{Rails.root}/app/models/**/*.rb") do |model_name|
require 'gollum/frontend/app'
require 'digest/sha1'
class App < Precious::App
User = Struct.new(:name, :email, :password_hash, :can_write)
before { authenticate! }
before /^\/(edit|create|delete|livepreview|revert)/ do authorize_write! ; end
helpers do
function color_meter(cwith, ccolor) {
if (!cwith && !ccolor) return;
var _cwith = (cwith.charAt(0)=="#") ? cwith.substring(1,7) : cwith;
var _ccolor = (ccolor.charAt(0)=="#") ? ccolor.substring(1,7) : ccolor;
var _r = parseInt(_cwith.substring(0,2), 16);
var _g = parseInt(_cwith.substring(2,4), 16);
var _b = parseInt(_cwith.substring(4,6), 16);
#!/bin/bash
#
# /etc/init.d/remote_syslog
#
# Starts the remote_syslog daemon
#
# chkconfig: 345 90 5
# description: Runs remote_syslog
#
# processname: remote_syslog
# Configure whenever
set :whenever_environment, rails_env
set :whenever_output, '/var/www/apps/alt12/current/log/crontab.log'
set :whenever_update_flags, "--update-crontab #{whenever_identifier} --set environment=#{whenever_environment}\\&output=#{whenever_output}" # notice the escaping \& passed to the shell