Skip to content

Instantly share code, notes, and snippets.

#http://stackoverflow.com/questions/373731/override-activerecord-attribute-methods
def price(option = nil)
if option == :nice
("%.2f" % price).gsub('.00', '.--').gsub('.', ',')
else
read_attribute(:price) # No test for nil?
end
end
@ionas
ionas / application.js
Created December 28, 2010 18:24
reduced functionality of: https://gist.github.com/755139
$(function() {
$('#products_search input').keyup(function() {
$.bbq.pushState($('#products_search').serialize() + '&page=1');
}, 250);
});
$('#products th a, #products .pagination a').live('click', function(e) {
e.preventDefault();
$.bbq.pushState($.param.querystring(this.href));
});
$(window).bind('hashchange', function() {
@ionas
ionas / fuse_wait.c
Created December 27, 2011 15:25 — forked from bfleischer/build.sh
Workaround for NTFS-3G and Lion's CoreFoundation bug
/*-
* fuse_wait - Light wrapper around a FUSE mount program that waits
* for the "mounted" notification before exiting.
*
* Copyright (C) 2007-2009 Erik Larsson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@ionas
ionas / google_art_project.rb
Created January 13, 2012 01:41 — forked from henrik/google_art_project.rb
Google Art Project fullsize image downloader. Specify the page URL and the tiles are downloaded, stitched and trimmed.
# Google Art Project fullsize image downloader.
# By Henrik Nyh <http://henrik.nyh.se> 2011-02-05 under the MIT license.
# Requires Ruby and ImageMagick.
#
# Usage e.g.:
# ruby google_art_project.rb http://www.googleartproject.com/museums/tate/portrait-of-william-style-of-langley-174
#
# You can specify multiple URLs on the command line, separated by space.
# Or you can specify no URLs on the command line and instead list them at the end of this file, one on each line,
# with "__END__" before the list.
@ionas
ionas / POSTGRESQL_ON_OS_X.md
Created June 4, 2012 16:45 — forked from mbbx6spp/POSTGRESQL_ON_OS_X.md
Homebrew Postgresql on OS X though only tested myself on Lion (10.7.4)

PostgreSQL on Lion

Much to my dismay, PostgreSQL on OS X is not as trouble-free to install and configure as my experiences with it on a variety of Linux distributions. This Gist documents how to overcome these issues using the Homebrew installation of postgresql.

This is an effort to document how to get setup to a coworker who was having troubles with Postgres on Lion recently.

Installation

This is usually the easy part:

jonas@server:/var/www/Foo$ bin/cake bake model all --force; echo $?cle
Welcome to CakePHP v3.0.0-beta2 Console
---------------------------------------------------------------
App : src
Path: /var/www/Foo/src/
---------------------------------------------------------------
One moment while associations are detected.
Baking table class for Nations...
@ionas
ionas / dereuromark DS cakephp-sandbox DS build.sh
Created August 31, 2015 13:03
dereuromark DS cakephp-sandbox DS build.sh
#!/bin/bash
# Warning: This is NOT a productive script, but for local dev envs only!
echo "### INSTALL/UPDATE ###";
php composer.phar selfupdate
git pull
php composer.phar install --prefer-dist --no-dev --optimize-autoloader --no-interaction
@ionas
ionas / gist:01151238f7bd55fd3750
Created November 29, 2015 17:46 — forked from saetia/gist:1623487
Clean Install – OS X 10.11 El Capitan

OS X Preferences


most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Set a shorter Delay until key repeat
@ionas
ionas / CakePHP3 friendsofcake search autosearch behavior.php
Last active January 11, 2016 15:39
An CakePHP3 autosearch behavior for the friendsofcake/search plugin
<?php
namespace App\Model\Behavior;
use Cake\ORM\Behavior;
/**
* AutoSearch behavior
*/
class AutoSearchBehavior extends Behavior
{
@ionas
ionas / ServiceUnavailableException.php
Last active December 29, 2015 15:39
CakePHP 3 Service Unavailable Exception HTTP 503
<?php
namespace App\Network\Exception;
use Cake\Network\Exception\HttpException;
/**
* Represents an HTTP 503 error.
*
*/