Skip to content

Instantly share code, notes, and snippets.

View eoinkelly's full-sized avatar

Eoin Kelly eoinkelly

View GitHub Profile
@eoinkelly
eoinkelly / allib-get-image-info.php
Created April 13, 2012 06:40
A simple wrapper function to make retrieving information about a WordPress attachment nicer.
<?php
/* Retrieve information about WordPress images without the chaos.
You have to remember a bunch of different functions to get info about images in the
Media Library so I collected their functionality under one wrapper with a (hopefully)
nice interface. This function tries to avoid fetching unnecessary info whenever it can.
I have limited the granularity of the API to not allow fetching different info
about each available image size. I think that would make using this function
more fiddly without any great benefit.
@eoinkelly
eoinkelly / allib-menu-sorted-query.php
Created April 16, 2012 11:49
Get all posts included in a WordPress Menu, sorted in the order they appear in the menu
<?php
/*
* This is a convenient wrapper that allows you to retrieve the list of posts
* mentioned in a Menu. The posts are returned in the order they are in the menu.
* Args: An array containing these keys:
* theme_location: (required) the name of the theme location you have defined
* for the menu with register_nav_menu()
@eoinkelly
eoinkelly / rubies-on-windows-compared.md
Created October 14, 2012 23:31
Comparing Windows MRI 1.9.3, jRuby 1.7.0 RC, Linux MRI 1.9.3

Test Setup

  • All tests run on same machine: Dell Studio XPS 16 Laptop running Windows 7 x64
  • Same codebase except jRuby does use different sqlite adaptor (you cannot use the standard one with jRuby)
  • Code has 4 unit tests (incl. 21 assertions) that all pass.
  • Code is the example app from Agile Web Development with Rails

Goals

  • I wanted to find the fastest way to run my rails tests on my laptop.

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@eoinkelly
eoinkelly / getting_started.md
Last active February 1, 2016 21:50
Getting started with requirejs-rails

Usage

  1. Add this to your Rails app's Gemfile:

    gem 'requirejs-rails'
    

    and then run bundle install on the command line.

@eoinkelly
eoinkelly / Problem.rb
Last active December 18, 2015 16:29 — forked from ootoovak/Problem.rb
# Want to pass in a hash or instance of object. Was hoping to avoid is_a? or creating a new object but
# think that can only be done with is_a? or overriding new. Also, I might be missing the point as
# avoiding is_a? should mean I am using Duck Typing but if I'm using Duck Typing then I shouldn't be
# checking object equality anyway. See RSpec test for details.
class MyClass
attr_accessor :name
attr_accessor :description
def initialize(args = {})
@eoinkelly
eoinkelly / each-with-index-in-ember.md
Last active August 29, 2015 13:59
Iterating over a collection with access to the index in Ember

Iterating over a collection with access to the index in Ember

// within your view/component
collectionWithIndices: function () {
  return this.get('collection').map(function (item, idx) {
    item.index = String(idx); // we need 0 to be "0" or Handlebars will consider it falsy
    return item;
  });
}.property('collection.@each'),
@eoinkelly
eoinkelly / css-animation-specs.js
Last active March 9, 2024 13:37
Test CSS Animations in Ember with Mocha & Chai
// TODO:
// * work with all browser prefixes for event names
// * make error message more helpful
it('tests that a CSS animation ran correctly', function (done) { // <-- notice the done param
// Visit whatever route we are going to test
visit('/unique_testing_route')
.then(function () {
@eoinkelly
eoinkelly / ember-inspector-promises-tab-test.js
Last active August 29, 2015 14:01
A test-drive of the Ember Inspector promises tab
// # How to use this:
//
// 1. Open the Ember Inspector on an Ember app (so Ember is loaded)
// 2. Hit the 'clear' button on the Promises tab to remove any promises from the app itself
// 3. Paste this code into the console and watch how the promises inspector displays it
// 4. Twiddle, Rinse & repeat
// 5. More info at
// * https://github.com/kriskowal/q/blob/v1/design/README.js (great for understanding promises)
// * http://emberjs.com/api/classes/Ember.RSVP.Promise.html (Ember promise implementation specifics)
@eoinkelly
eoinkelly / visualize-stacking-contexts.js
Last active February 7, 2021 08:04
Some console output to help you visualise stacking contexts on a page
/*
Usage:
* Paste this into your dev tools console (or even better as a snippet)
* It will parse the page and find all the things that create a new stacking context
and dump some info about them to the console. It will also outline them on the page.
* This is pretty rough and probably misses heaps of bugs and edge cases.
*/