Skip to content

Instantly share code, notes, and snippets.

@warp
warp / paperclip_migrations.rb
Created July 22, 2011 08:13 — forked from jystewart/paperclip_migrations.rb
Migration from attachment_fu database storage to paperclip
module PaperclipMigrations
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def add_paperclip_fields(table, prefix)
add_column table, "#{prefix}_file_name", :string
add_column table, "#{prefix}_content_type", :string
@warp
warp / psd2txt
Created August 6, 2011 07:14
Dump text layers from photoshop psd files
#!/usr/bin/env ruby
content = File.open(ARGV[0], 'rb') {|io| io.read }
File.open(ARGV[0] + '.txt', 'w') do |file|
content.scan /Txt TEXT[\W]*([^\x0C]*)\x0C/ do |match|
s = $1.gsub(/\x00/, '').force_encoding('UTF-8')
file << s
puts s
end
module ActiveModel
class Serializer
class Adapter
class JsonFieldsets < Adapter
def initialize(serializer, options = {})
super
if fields = options.delete(:fields)
@fieldset = fields.split(',').map(&:to_sym)
else
@warp
warp / gist:84b4f5295d93da115698
Created January 21, 2015 20:41
database cleaner
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
@warp
warp / config.ru
Created March 15, 2017 02:09 — forked from Aupajo/config.ru
ITTT trigger responder
require_relative 'environment'
app = Server.new do
trigger :turn_on_lightbulb do
# Make an API request...
Net::HTTP.post_form(URI('http://lightbulb.local'), 'status' => 'on')
# Response (any JSON-like data)
{ light_bulb: "on" }
end
@warp
warp / restore
Created May 13, 2019 00:12 — forked from mru2/restore
pg_restore a local db dump into Docker
# Create and download backup
heroku pg:backups:capture
heroku pg:backups:download
# Assumes the database container is named 'db'
DOCKER_DB_NAME="$(docker-compose ps -q db)"
DB_HOSTNAME=db
DB_USER=postgres
LOCAL_DUMP_PATH="path/to/local.dump"

Keybase proof

I hereby claim:

  • I am warp on github.
  • I am altwarp (https://keybase.io/altwarp) on keybase.
  • I have a public key ASD8yF1S8Va-UgQAWFdILJDMRQ92veQZYB6haa-somUlbgo

To claim this, I am signing this object: