Skip to content

Instantly share code, notes, and snippets.

View danielpuglisi's full-sized avatar
💭
🤘

Daniel Puglisi danielpuglisi

💭
🤘
View GitHub Profile
@danielpuglisi
danielpuglisi / users_controller.rb
Last active August 9, 2021 12:33
Rails examples: Single Table Inheritance (STI), strong parameters, single controller.
# Variant 1
def user_params(type)
params.require(type.to_sym).permit(attributes)
end
# Variant 2
def user_params(type)
case type
when "user"
params.require(:user).permit(user_attributes)
class AddFieldsToDelayedJobs < ActiveRecord::Migration
def change
add_column :delayed_jobs, :signature, :string
add_index :delayed_jobs, :signature
end
end
@danielpuglisi
danielpuglisi / test_helper.rb
Last active July 29, 2019 09:40 — forked from abarrak/test_helper.rb
Perform Enqueued Mail Job in Rails 6 Tests
# Extend in your test_helper.rb or any other `/support` setup you have.
class ActiveSupport::TestCase
# === NOTICE:
# Ensure you have included `ActionMailer::TestHelper` in the test class ..
#
# This method performs any enqueued job during tests manually,
# Helpful when testing the queueing of your jobs and then the result of their execution.
#
# === Author: (abarrak, danielpuglisi)
@danielpuglisi
danielpuglisi / fuck-you-postgres.sh
Created November 11, 2014 09:06
Fuck You Postgres
#!/bin/bash
#
# Fix postgres after OSX crashed
pg_resetxlog /usr/local/var/postgres
rm /usr/local/var/postgres/postmaster.pid
pg_resetxlog /usr/local/var/postgres
pg_resetxlog -f /usr/local/var/postgres
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
@danielpuglisi
danielpuglisi / static_map_helper.rb
Last active January 27, 2017 14:54 — forked from mcasimir/static_map_helper.rb
Google Maps Static map helper for Ruby on Rails
module StaticMapHelper
def static_map_for(location, options = {})
params = {
center: [location.latitude, location.longitude].join(","),
zoom: 15,
size: "300x300",
scale: 2,
markers: [location.latitude, location.longitude].join(","),
sensor: true,
@danielpuglisi
danielpuglisi / build_pandoc_for_heroku.sh
Last active May 24, 2016 16:33 — forked from minrk/build_pandoc_for_heroku.sh
doing some magic for making pandoc work on heroku
# bring up the vagrant VM
sudo apt-get install vagrant
git clone https://bitbucket.org/puffnfresh/vagrant-haskell-heroku.git
cd vagrant-haskell-heroku
vagrant up
vagrant ssh
# run this in vagrant shell
cabal update
cabal install cabal-install
@danielpuglisi
danielpuglisi / migrate_from_jekyll_to_rails.rb
Last active April 29, 2016 17:51
A Rake Task which I wrote to migrate my Jekyll posts and categories to a custom Rails application I've built.
# A Ruby script to migrate Jekyll Posts to a custom Database
DIRECTORIES = ["tmp/blog/articles/_posts/*", "tmp/blog/startup/_posts/*",
"tmp/blog/productivity/_posts/*", "tmp/blog/music/_posts/*",
"tmp/blog/programming/_posts/*"]
def export(content, key)
match = content.match( /^---.*\n#{key}: ([^\n]*).*---$/m )
if match
match[1].gsub("\"", "")
@danielpuglisi
danielpuglisi / .gitignore
Last active December 21, 2015 04:18
Rails ENV variables: heroku development setup
# other stuff
config/env.rb
# other stuff
@danielpuglisi
danielpuglisi / helpers.rb
Created July 23, 2013 12:42
Seiten application controller helper methods, inspired by devise
module Seiten
module Controllers
# Those helpers are convenience methods added to ApplicationController.
module Helpers
extend ActiveSupport::Concern
def current_page
@current_page ||= Seiten::Page.find_by_slug(request.fullpath)
end
end
@danielpuglisi
danielpuglisi / spec_helper.rb
Created May 8, 2013 20:41
Configure rspec or test/unit to autoreload factories with spring after they have changed.
RSpec.configure do |config|
config.before(:all) do
FactoryGirl.reload
end
end