Skip to content

Instantly share code, notes, and snippets.

View agius's full-sized avatar
🐐
goat rodeo

Andrew Evans agius

🐐
goat rodeo
View GitHub Profile
@agius
agius / bookmarklet_toolbar.js
Last active December 17, 2015 23:58
Prose Bookmarklet
s = document.createElement('script');
s.setAttribute('src','http://prose.atevans.com/bookmarklet.js');
document.head.appendChild(s);
@agius
agius / hamlconvert.rb
Created August 20, 2013 04:53
Recursively browse directory and convert all .haml files to .erb via Herbalizer (https://github.com/danchoi/herbalizer)
#!/usr/bin/env ruby
require 'open3'
# things herbalizer hates:
# nested hashes: %div{data: {href: src }} -> %div{data: Hash[href: src] }
# comments in the first line
# blank first line
# ruby-style interpolation: Message to #{person} -> Message to \ = person
# ternary operators inside blocks: %div{href: one ? two : three } -> put on separate line
@agius
agius / blunder.rb
Created October 12, 2013 00:11
Centralized error reporting module - control what services you use and how you log errors in one place.
module Blunder
# Centralizes error reporting, so we don't get custom
# library names like BugSnag or Errplane all over our code
def self.oops(exception, custom_data = {})
raise if Rails.env == 'test'
exception = Exception.new(exception) unless exception.is_a?(Exception)
custom_data = custom_data.with_indifferent_access
Rails.logger.error("\n\nBlunder Exception: #{exception}")
Rails.logger.error("backtrace:#{exception.backtrace.take(20).join("\n")}\n\n") if exception.backtrace.present?
env = custom_data.delete(:env)
@agius
agius / jekyll.rake
Created October 18, 2013 05:48
Generate static error pages and upload to S3
namespace :static do
desc "Generate and upload static pages"
task :generate do
`jekyll build -s jekyll -d jekyll/_site`
`cp -r jekyll/_site/* public/`
config = YAML.load(File.read(File.join(File.dirname(__FILE__), '..', '..', 'config', 'keys.yml')))
config = config['production']['amazon']
AWS.config(:access_key_id => config['key'], :secret_access_key => config['secret'])
s3 = AWS::S3.new
@agius
agius / find.rake
Created November 1, 2013 04:32
Find and replace rake task
namespace :find do
desc "Find and replace"
task :replace, :find, :replace do |t, args|
find = args[:find]
replace = args[:replace]
`egrep -lRZ "#{find}" --exclude-dir='.git' --exclude-dir='db' --exclude-dir='tmp' --exclude-dir='images' --exclude-dir='fonts' --exclude-dir='vendor' . | xargs -I {} sed -i '' -e 's/#{find}/#{replace}/g' {}`
end
end
@agius
agius / get_abbr.js
Last active August 29, 2015 14:03
Output timezone select in Rails with some data attrs for JS
var d = new Date();
var tz_offset = d.getTimezoneOffset(); // seconds, not ms, because Javascript
var tz_select = $('#tz-select');
var abbr = tz_select.find("option[data-offset='" + tz_offset + "']").data('abbreviation');
@agius
agius / deploy.log
Created August 27, 2014 23:02
Strange heroku deploy failure
This file has been truncated, but you can view the full file.
Fetching repository, done.
-----> Node.js app detected
PRO TIP: Specify a node version in package.json
See https://devcenter.heroku.com/articles/nodejs-support
-----> Defaulting to latest stable node: 0.10.31
-----> Downloading and installing node
-----> Exporting config vars to environment
@agius
agius / Cheffile
Last active August 29, 2015 14:06 — forked from jkarmel/Cheffile
#!/usr/bin/env ruby
site 'http://community.opscode.com/api/v1'
cookbook 'sprout-rbenv',
:github => 'pivotal-sprout/sprout-rbenv'
cookbook 'sprout-ruby',
:github => 'pivotal-sprout/sprout-ruby'
@agius
agius / my_controller.rb
Created April 18, 2015 01:32
Sometimes, controllers just suck. Time to extract.
class MyController < ApplicationController
def create
@model = Model.new(model_params)
# we have to call this here, to populate
# errors on any other fields that might
# be invalid
@model.valid?
if @model.model_attr == 'invalid' && !@model.in_state(:dont_care)
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->