Skip to content

Instantly share code, notes, and snippets.

View leobessa's full-sized avatar

Leonardo Bessa leobessa

View GitHub Profile
@ckgagan
ckgagan / Rails Date Formats
Created April 3, 2012 06:01
Rails Date Formats
Rails Date Formats – strftime
StrFTime Format Codes for Ruby on Rails
Year
%Y year with century 2007
%y year without century 07
%C century number (year divided by 100) 20
Month
%B full month name January
@hito-asa
hito-asa / agent_fluentd.conf
Created March 29, 2012 06:45
fluentd agent
<source>
type tail
path path_to_file1
pos_file path_to_pos_file1
tag app.file1
format /^(?<ip>[^ ]+) [^ ]+ [^ ]+ \[(?<time>[^\]]+)\] "(?<method>\S+) /(?<country>[A-Z0-9]{0,3})_(?<domain>[^/]+)/(?<module>[^/]+)/(?<controller>[^/]+)/(?<action>[^/]+)/(?<record>\S*)" (?<code>\d+) (?<res_time>\d+) "(?<referer>[^\"]*)" "(?<old_device>[^_\" ]*)_(?<device>[^_\" ]*)_(?<browser>[^_\" ]*) ?(?<guid>[^\"]*)" "(?<vuid>\d*) ?(?<option>[^\"]*)"$/
time_format %d/%b/%Y:%H:%M:%S %z
rotate_wait = 5s
</source>
@bernardeli
bernardeli / .zshrc
Created October 20, 2011 17:03
highlighting code for keynote with highlight
first: brew install highlight
second: add to your .zshrc (or .bashrc)
function hlr {
filename=`echo $1 | cut -d . -f 1`
highlight --syntax ruby -k Menlo -K 20 -O rtf -s edit-xcode $1 > $filename.rtf
}
third: it will generate a .rtf file. just open and copy the highlighted code and add to your Keynote talk.
@jswanner
jswanner / .gitignore.diff
Created October 7, 2011 17:50
Differences between Rails 3.1.0.beta1 & Rails 3.1.1 generated apps
diff -U 0 -r rails-3.1.0.beta1/.gitignore rails-3.1.1/.gitignore
--- rails-3.1.0.beta1/.gitignore 2011-10-07 11:56:15.000000000 -0400
+++ rails-3.1.1/.gitignore 2011-10-07 12:59:12.000000000 -0400
@@ -4,0 +5 @@
+.sass-cache/
@testcollab
testcollab / an_example_usage.rb
Created September 22, 2011 23:31
Editing a File via the GitHub API v3
require 'editor.rb'
ed = Editor.new('testcollab/rails-test')
if ed.update_file('README.txt', 'my message', 'my new content')
ed.set_author('Scott', '[email protected]')
ed.update_file('README.2.txt', 'my message', 'my new content')
end
@gertig
gertig / peepcode.rb
Created August 18, 2011 20:40 — forked from jmazzi/peepcode.rb
A script to download all Peepcode screencasts with ruby & wget (supports resume)
require 'mechanize'
@username = '[email protected]'
@password = 'hi2u'
@download_path = File.expand_path 'downloads'
@wget_cookie = File.expand_path(File.dirname(__FILE__)) + '/wget-cookies.txt'
unless File.directory? @download_path
puts "@{download_path} doesn't exist!"
exit
@chetan
chetan / skel.rb
Created August 15, 2011 17:42
Ruby command-line skeleton
#!/usr/bin/env ruby
# == Synopsis
# This is a sample description of the application.
# Blah blah blah.
#
# == Examples
# This command does blah blah blah.
# ruby_cl_skeleton foo.txt
#
@jraines
jraines / confident-code.md
Created May 17, 2011 19:05
Notes on Avdi Grimm's "Confident Code"

Confident Code

timid code

  • Randomly mixes input gathering, error handling, and business logic
  • imposes cognitive load on the reader

confident code

  • no digressions
@sevos
sevos / authentications_controller.rb
Created February 10, 2011 20:40
Spec file for authentications controller used in OmniAuth integration
class AuthenticationsController < ApplicationController
before_filter :authenticate_user!, :only => :destroy
def create
omniauth = request.env['omniauth.auth']
authentication = Authentication.find_by_provider_and_uid(omniauth["provider"], omniauth["uid"])
if current_user
if authentication && authentication.try(:user) != current_user
flash[:error] = I18n.t("This %{provider} account is already connected to another account in our service", :provider => authentication.provider)
elsif authentication.nil?
@jittuu
jittuu / gist:792715
Created January 24, 2011 02:19
Test Omniauth Facebook Callback Controllers in Devise with rspec
require 'spec_helper'
describe Users::OauthCallbacksController, "handle facebook authentication callback" do
describe "#annonymous user" do
context "when facebook email doesn't exist in the system" do
before(:each) do
stub_env_for_omniauth
get :facebook