Skip to content

Instantly share code, notes, and snippets.

@latortuga
latortuga / delete_failed_jobs.rb
Created September 15, 2022 18:37 — forked from nisanthchunduru/delete_failed_jobs.rb
Selectively remove/retry failed jobs in Resque 1.x
def delete_failed_job_if
redis = Resque.redis
(0...Resque::Failure.count).each do |i|
string = redis.lindex(:failed, i)
break if string.nil?
job = Resque.decode(string)
should_delete_job = yield job
next unless should_delete_job
@latortuga
latortuga / rails.rb
Created October 18, 2009 17:32
A bunch of handy ruby and rails snippets
# This is used in Rails migrations to update ActiveRecord after adding/removing a column from a table
# so that the column can be used in the migration. Doesn't take any arguments, will update the AR
# model that it is called on.
ActiveRecord#reset_column_information
# Reload rails env while in script/console
reload!
# Rails field types
# :type MySQL type options
@latortuga
latortuga / 1.md
Last active October 29, 2016 14:32
rails-4-2-overview

What's new in Rails 4.2?

ActiveJob

Adapter layer on top of queueing systems like Resque and Delayed Job. Full adapter list: :backburner, :delayed_job, :qu, :que, :queue_classic, :resque, :sidekiq, :sneakers, :sucker_punch

ActiveJob::Base.queue_adapter = :inline # default queue adapter

# Declare a job:
@latortuga
latortuga / gist:4241707
Created December 8, 2012 20:09
Request Signing for Direct Amazon S3 File Upload
# app/controllers/application_controller.rb
class ApplicationController
private
def generate_s3_upload_data
bucket = BUCKET # S3 bucket
access_key = S3_KEY # S3 Access Key
secret = S3_SECRET # S3 Secret Key
key = "uploadify/" # The folder in your bucket that you'd like uploaded files to land in. See note below.
expiration = 10.hours.from_now.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z')
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x0]
goroutine 10 [running]:
runtime.gopanic(0x5a7020, 0xc8200101b0)
/usr/local/go/src/runtime/panic.go:461 +0x3e6
runtime.panicmem()
/usr/local/go/src/runtime/panic.go:42 +0x49
runtime.sigpanic()
/usr/local/go/src/runtime/sigpanic_unix.go:24 +0x2ba
@latortuga
latortuga / gist:4241729
Created December 8, 2012 20:13
Setup Uploadify to upload directly to S3
var uploadify_data = {
'AWSAccessKeyId': '<%= @uploadify_data[:access_key] %>',
'bucket': '<%= @uploadify_data[:bucket] %>',
'acl': 'private',
'key': '<%= @uploadify_data[:key] %>${filename}',
'signature': '<%= @uploadify_data[:signature] %>',
'policy': '<%= @uploadify_data[:policy] %>',
'success_action_status': '<%= @uploadify_data[:sas] %>',
'folder': '',
'Filename': ''
@latortuga
latortuga / crossdomain.xml
Created December 8, 2012 20:07
Amazon S3 crossdomain.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" secure="false" />
</cross-domain-policy>
@latortuga
latortuga / paniclog.log
Last active October 11, 2015 18:36
vagrant-panic
drew:~/projects/prj$ zeus start
Starting Zeus server v0.15.5.rc1
[ready] [crashed] [running] [connecting] [waiting]
boot
└── default_bundle
├── development_environment
│  └── prerake
└── test_environment
└── test_helper
@latortuga
latortuga / registration.rb
Created October 11, 2012 14:43
ActiveModel validations without persistence
# Adapted from http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/
#
# app/models/registration.rb
class Registration
extend ActiveModel::Naming
include ActiveModel::Conversion
include ActiveModel::Validations
# Other ActiveModel modules:
# AttributeMethods: Makes it easy to add attributes that are set like table_name :foo
@latortuga
latortuga / .tmux.conf
Created September 14, 2012 14:51
tmux conf
# use bash
set-option -g default-shell /bin/bash
# set 256 colors!
set -g default-terminal "screen-256color"
# change default command sequence
unbind C-b
set-option -g prefix C-a