Skip to content

Instantly share code, notes, and snippets.

View pootsbook's full-sized avatar

Philip Poots pootsbook

  • ClubCollect
  • Alphen aan den Rijn, NL
View GitHub Profile
@pootsbook
pootsbook / gist:1583368
Created January 9, 2012 15:18
Ever wanted Array#penultimate? How about Array#penpenultimate
class Array
def method_missing(method_sym, *arguments, &block)
if method_sym.to_s =~ /^((pen)+)ultimate$/
pen_index = 1 + ($1.length/3)
self[-pen_index]
else
super
end
end
end
@pootsbook
pootsbook / isbn.rb
Created July 26, 2012 13:04
Solutions to ISBN cleaning and validation
Paste solutions in the comments below. Don't forget to make it code using GitHub markdown.
@pootsbook
pootsbook / directory_listing.php
Created November 1, 2012 17:57
PHP -> Ruby: Listing Directory
// Removed the HTML for readability
<?php
$Directory = opendir("../");
while($entryName = readdir($Directory)) {
$dirArray[] = $entryName;
}
closedir($Directory);
@pootsbook
pootsbook / tilt.rb
Created November 3, 2012 18:48
Iterate through an array while rescuing exceptions
# https://github.com/rtomayko/tilt/blob/master/lib/tilt.rb
# Try each of the classes until one succeeds. If all of them fails,
# we'll raise the error of the first class.
first_failure = nil
klasses.each do |klass|
begin
klass.new { '' }
rescue Exception => ex
@pootsbook
pootsbook / emberwatch_ordering.txt
Created November 24, 2012 19:31
Ordering of Links on EmberWatch as of November 2012
Hey Tom (and others),
At the moment ordering of links on EmberWatch is strictly
chronological, and for the different content types chronological is
defined thus:
- Talks: date of delivery
(when the talk was given, not when it was posted online)
- Tutorials, Screencasts: date of publication
@pootsbook
pootsbook / habtm_not_null.php
Created December 2, 2012 20:21
Ignore records with no attached records
$options['joins'] = array(
array('table' => 'images_news_articles',
'alias' => 'ImagesNewsArticle',
'type' => 'left outer',
'conditions' => array(
'NewsArticle.id = ImagesNewsArticle.news_article_id'
)
),
array('table' => 'images',
'alias' => 'Image',
@pootsbook
pootsbook / Gemfile
Last active December 16, 2015 19:29
Ember.js with dependencies, 83K minified and gzipped, +18K if you're using ember-data.
source 'https://rubygems.org'
gem 'rake-pipeline', github: 'livingsocial/rake-pipeline'
gem 'rake-pipeline-web-filters', github: 'wycats/rake-pipeline-web-filters'
gem 'uglifier'
@pootsbook
pootsbook / facebook.rb
Last active December 16, 2015 19:59
Get a Facebook or Twitter Profile Image
require 'koala'
client = Koala::Facebook::API.new(user_access_token)
picture_response = client.get_object('me', fields: "picture.width(200).height(200)")
# { "id"=>"37100599",
# "picture" => {
# "data"=> {
# "url"=>"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/c205.44.551.551/s200x200/314850_740167411782_1416727952_n.jpg",
# "width"=>200,
# "height"=>200,
@pootsbook
pootsbook / references
Last active December 18, 2015 04:29
Precompiling Handlebars Templates with Rake::Pipeline
Issue about better documentation:
https://github.com/emberjs/ember.js/issues/2319
Handlebars PreCompiler, Barber:
https://github.com/tchak/barber
SO Question about PreCompilation with Rake::Pipeline:
http://stackoverflow.com/questions/8558062/setting-up-rake-pipeline-for-use-with-handlebars-alongside-google-app-engine
Blog Post about Barber Handlebars precompilation:
# Rake Pipeline with MiniSpade
http://www.javascriptturnsmeon.com/javascript-build-process-rake-pipeline-with-minispade/
# Minispade
https://github.com/wycats/minispade