Skip to content

Instantly share code, notes, and snippets.

View AMHOL's full-sized avatar

Andy Holland AMHOL

  • Manchester, UK
  • 00:11 (UTC +01:00)
View GitHub Profile
<?php namespace AMH;
use Exception;
use Jeremeamia\SuperClosure\SerializableClosure;
use Symfony\Component\Process\PhpProcess;
class PromiseValueException extends Exception {}
class Promise
{
@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);
};
}
@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 / 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 / Category drop-down
Created November 8, 2012 15:09
Create recursive category drop-down navigation by assigning data('children') to navigation li and calling elem.createDropdownFromChildren
(($) ->
$.fn.createDropdownFromChildren = ($level) ->
$elem = $(@)
# if element has children data
unless @data("children") is "undefined"
@bind
# MOUSE ENTER
mouseenter: ->
clearTimeout $(document).data("dd-timeout")
Date::DATE_FORMATS[:default] = '%d/%m/%Y'
# if you want to change the format of Time display then add the line below
Time::DATE_FORMATS[:default]= '%d/%m/%Y %H:%M:%S'
# if you want to change the DB date format.
Time::DATE_FORMATS[:db]= '%d/%m/%Y %H:%M:%S'
# 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 / jquery.placeholder-fallback.js
Created December 18, 2012 11:11
HTML5 placeholder fallback for browsers that don't support it, implemented in jQuery. NOTE: This will not work for elements added to the DOM after initial load
// Function to test for attribute support
function elSupportsAttr(el, attr) {
return attr in document.createElement(el);
}
// does input support placeholder? if not, add fallback
if ( !elSupportsAttr('input', 'placeholder') ) {
$(document).ready(function() {
// everything with placeholder attr
$('[placeholder]').each(function() {
$(this).val($(this).attr('placeholder'));
@AMHOL
AMHOL / gist:4633484
Created January 25, 2013 10:53
Javascript get host
window.location.protocol + '//' + window.location.hostname + (!!window.location.port ? ':' + window.location.port : '')
@AMHOL
AMHOL / gist:5327827
Created April 6, 2013 22:07
Library for building dependencies with ActiveResource
module ResourceHas
def self.included base
unless base.ancestors.include? InheritedResources::Base
raise '%s must inherit from InheritedResources::Base to implement ResourceHas' % base.name
end
base.extend(ClassMethods)
base.append_before_filter :__build_relations
end
## Class methods
module ClassMethods