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 / 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 ->
^([^:]+:\/\/)([^@]+\@)?([^:\/]+)(:\d+)?(\/[^\s\?\#]+)+(\?([^\n\#]+)(\#\S+)?|(\#\S+))?$
@agius
agius / hash_extension.rb
Created October 6, 2011 00:17
Useful methods for ruby hashes
class Hash
# gets hash-nested values, returns nil if any key is missing
def dig(*path)
path.inject(self) do |location, key|
location.respond_to?(:keys) ? location[key] : nil
end
end
# Deletes key from self and returns self
def kill(key)
@agius
agius / gist:1468681
Created December 12, 2011 19:26 — forked from danielgwood/gist:1244903
MongoDB shell cheatsheet
// A bunch of functions you can use in the MongoDB shell
// taken from http://api.mongodb.org/js/1.8.2/index.html
// amongst other sources
// Used in place of print() to view the contents of objects
printjson(x);
printjsononeline(x);
// File system interaction
ls(...);
@agius
agius / added thumbnail generation with RMagick
Created March 14, 2012 23:55
Script to create & edit new jekyll post
#!/usr/bin/env ruby
# Script to quickly generate a new post for Jekyll
# 2012 Andrew Evans - http://atevans.com
require "net/http"
require "uri"
require 'RMagick'
def titleize(str)
@agius
agius / dwolla_error.txt
Created December 2, 2012 01:41
Dwolla API fault
<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none"><Code><Value>Receiver</Valu... xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalSer... xml:lang="en-US">The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the &lt;serviceDebug&gt; configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.</Text></Reason></Fault>