Skip to content

Instantly share code, notes, and snippets.

View AMHOL's full-sized avatar

Andy Holland AMHOL

  • Manchester, UK
  • 10:26 (UTC +01:00)
View GitHub Profile
# gem install i18n
require 'i18n'
require 'delegate'
class ErrorPresenter < SimpleDelegator
attr_reader :root_key
private :root_key
def initialize(root_key, model)
@root_key = root_key
@AMHOL
AMHOL / ex.rb
Last active August 29, 2015 14:19
require 'transproc/all'
require 'json'
json = <<-EOS
{
"links": {
"self": "http://example.com/posts",
"next": "http://example.com/posts?page[offset]=2",
"last": "http://example.com/posts?page[offset]=10"
},
@AMHOL
AMHOL / angular_ie_cors.md
Created June 17, 2014 15:59
Angular JS IE CORS fix - if you control the API server

-- CORS FIX - IF YOU CONTROL THE API SERVER

Add the following somewhere in your application config

app.run([
  '$window',
  function($window) {
    if ( !$window.location.origin ) {
 $window.location.origin = $window.location.protocol + "//" + $window.location.hostname + ($window.location.port ? ':' + $window.location.port : '');
@AMHOL
AMHOL / gist:10000063
Created April 6, 2014 01:00
config/templating.php
<?php
return [
'extensions' => [
'functions' => [
'url' => function($app) {
return function($name, $params) use ($app) {
return $app->getContainer()->resolve('\Autarky\Routing\RouterInterface')
->getRouteUrl($name, $params);
};
}
<?php namespace AMH;
use Exception;
use Jeremeamia\SuperClosure\SerializableClosure;
use Symfony\Component\Process\PhpProcess;
class PromiseValueException extends Exception {}
class Promise
{
(function(window, $, undefined) {
'use strict';
$.fn.textWidth = function() {
var $span = $('<span />', {
text: $(this).text() || $(this).val()
}).css({
margin: 0,
padding: 0,
width: 'auto',
font: $(this).css('font'),
@AMHOL
AMHOL / gist:7212979
Created October 29, 2013 11:29
Rails autoloading - Read later
http://urbanautomaton.com/blog/2013/08/27/rails-autoloading-hell/
@AMHOL
AMHOL / sti_polymorphic.rb
Created October 15, 2013 09:04
Rails STI with Polymorphic relationship fix
def self.inherited(subclass)
super(subclass)
subclass.send(:class_eval, <<-eoruby, __FILE__, __LINE__ + 1)
def self.base_class
self
end
eoruby
end
@AMHOL
AMHOL / bashrc.bat
Created August 9, 2013 09:43
Windows bashrc
:: This is my windows bashrc.bat file, I only really use it for doskey commands,
:: To get this to work go to Start > Type "regedit" > "HKEY_LOCAL_MACHINE" > "SOFTWARE" > "Microsoft" > "Command Processor"
:: look for "AutoRun" and change the "Data" field to an absolute path to THIS file. If it doesn't exist right-click and go to
:: "New" > "String Value" > type "AutoRun" and change the "Data" field to an absolute path to THIS file.
:: This file makes "rake" use "bundle exec rake", "s" starts my rails server, "c" for rails console, "m" for database
:: migrations and "mysql" is changed to "mysql -u root", this allows me to import databases easily with
:: "mysql dbname < file.sql"
@echo off
@AMHOL
AMHOL / acts_as_taggable_on.rb
Created August 1, 2013 14:41
Initializer for making rails acts-as-taggable-on v2.1.1 case-insensitive (config/initializers/acts_as_taggable_on.rb)
ActsAsTaggableOn::TagList.delimiter = '|'
# https://github.com/mbleigh/acts-as-taggable-on/blob/v2.1.1/lib/acts_as_taggable_on/utils.rb
# This is a hack to remove case-insensitivity on the acts-as-taggable (v2.1.1)
# RE: Ticket - http://redmine.cirrus-connect.com/issues/249
module ActsAsTaggableOn::Utils::OverallMethods
private
def like_operator
using_postgresql? ? 'LIKE' : 'LIKE BINARY'
end