Skip to content

Instantly share code, notes, and snippets.

@defunkt
defunkt / connection_fix.rb
Created November 19, 2009 20:00
MySQL server has gone away fix
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
@karmi
karmi / workers.rake
Created July 22, 2010 15:58
Rake taks to launch multiple Resque workers in development/production with simple management included
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
@agladysh
agladysh / with_coroutines.lua
Created April 18, 2011 20:59
Example for using coroutine-based workarounds for blocking callbacks in Lua Alchemy (issue #121)
-- See http://code.google.com/p/lua-alchemy/issues/detail?id=121
-- Example. Actual implementation should reuse as much resources as possible.
-- Code is not tested.
local sleep = function(interval)
local timer = as3.class.flash.utils.Timer.new(interval)
local function callback()
if timer then
timer.stop()
timer.removeEventListener(
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
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
@tkyowa
tkyowa / gist:1378694
Last active May 23, 2017 08:15
ruby-debugを使ったRuby・Railsアプリケーションのデバッグ方法

ruby-debugを使ったRuby・Railsアプリケーションのデバッグ方法

インストール

# Ruby 1.8系の場合
gem install ruby-debug

# Ruby 1.9系の場合
gem install debugger
@terut
terut / spec_helper.rb
Created November 21, 2011 13:33
Clean up carrierwave's files for rspec.
RSpec.configure do |config|
# ...
config.after(:all) do
if Rails.env.test?
FileUtils.rm_rf(Dir["#{Rails.root}/spec/support/uploads"])
end
end
end
# put logic in this file or initalizer/carrierwave.rb
@carlosrocha
carlosrocha / .tmux.conf
Last active July 8, 2017 01:11
My vimrc file
unbind C-b
set -g prefix C-a
set -g default-terminal "screen-256color"
set -g default-command "reattach-to-user-namespace -l $SHELL"
set-window-option -g mode-keys vi
# Setup 'v' to begin selection as in Vim
#bind-key -t vi-copy v begin-selection
@arton
arton / gist:2429713
Created April 20, 2012 15:38
Using Kuromoji with RJB
#coding: utf-8
require 'rjb'
module JavaIterator
def each
i = self.iterator
while i.has_next
yield i.next
end
end
end
@teppeis
teppeis / tenkaichi-git.md
Last active April 29, 2023 14:58
天下一gitconfig大会

天下一gitconfig大会(サイボウズ社内git勉強会@2012/11/20)の@teppeisの資料です。

ぎっとぎとにしてやんよ

DojoCat

  • gistでmarkdown書いたらbookmarkletでプレゼンになるよ。