Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Daniel Puglisi danielpuglisi

🏠
Working from home
View GitHub Profile
@danielpuglisi
danielpuglisi / crontab
Last active Oct 9, 2015
Heroku keep alive
View crontab
*/5 * * * * root /etc/cron.custom/keep-alive.sh
View keep-alive.sh
#!/bin/bash
apps=( app1-demo app1-staging app2-draft )
for app in ${apps[@]}; do
host="http://$app.herokuapp.com"
curl --silent --output /var/log/keep-alive.txt -L $host
done
View locations.rb
# Convert a locations response to an Array of Location Objects
#
# response - The Hash object from an API response
#
# Returns an array of Location objects, returns nil if the Hash is empty
def self.objectify(response)
response.empty? ? nil : response.map {|station| Rtransport::Location.new(station)}
end
View rspec: save_failed_features.rb
# Hook to save the html page of every failed features into the temp
# # file directory taht it can be checked after cucumber has finished running.
require 'fileutils'
FAILED_FEATURES_PAGES_PATH = File.join Rails.root, 'tmp', 'failed_features'
FAILED_FEATURES_IMAGES_PATH = File.join Rails.root, 'tmp', 'failed_features_images'
FileUtils.rm_rf FAILED_FEATURES_PAGES_PATH
FileUtils.rm_rf FAILED_FEATURES_IMAGES_PATH
@danielpuglisi
danielpuglisi / migrate_from_jekyll_to_rails.rb
Last active Apr 29, 2016
A Rake Task which I wrote to migrate my Jekyll posts and categories to a custom Rails application I've built.
View migrate_from_jekyll_to_rails.rb
# 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 / spec_helper.rb
Created May 8, 2013
Configure rspec or test/unit to autoreload factories with spring after they have changed.
View spec_helper.rb
RSpec.configure do |config|
config.before(:all) do
FactoryGirl.reload
end
end
@danielpuglisi
danielpuglisi / helpers.rb
Created Jul 23, 2013
Seiten application controller helper methods, inspired by devise
View helpers.rb
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 / .gitignore
Last active Dec 21, 2015
Rails ENV variables: heroku development setup
View .gitignore
# other stuff
config/env.rb
# other stuff
@danielpuglisi
danielpuglisi / build_pandoc_for_heroku.sh
Last active May 24, 2016 — forked from minrk/build_pandoc_for_heroku.sh
doing some magic for making pandoc work on heroku
View build_pandoc_for_heroku.sh
# 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 / users_controller.rb
Last active Aug 9, 2021
Rails examples: Single Table Inheritance (STI), strong parameters, single controller.
View users_controller.rb
# 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)