Skip to content

Instantly share code, notes, and snippets.

@eric1234
eric1234 / README.md
Last active March 22, 2024 12:54
Generic Ruby Proxy Module

Purpose

A generic proxy module.

Since it's a module it can be mixed into any class. This differs from Ruby's Delegator class which require the inheritance chain to include the Delegator module. Since it implements it's magic via method_missing, it will only proxy the method if the method doesn't exist on the base class or any of it's parent classes.

Example

@eric1234
eric1234 / README.md
Last active August 29, 2015 13:58
Automatically translated snake_case method calls into their CamelCase equal

A module to automatically translate snake_case method calls into CamelCase method calls. For example:

class MyObject
  include Snakeable
  
  def FooBar
    "baz"
  end

end

@eric1234
eric1234 / null_pattern.php
Created December 16, 2013 18:23
A null object pattern implemented in PHP
<?php
# Implements a recursive null object pattern.
#
# Implemented as a trait so any object can make it's properties use
# the null pattern without resorting to inheritance.
#
# The goal is so you can pull data off a partially populated object
# without excessive existance checks.
trait NullPattern {
@eric1234
eric1234 / install_git_ftp.sh
Last active February 24, 2017 16:43
Install git-ftp on Ubuntu with sftp support and git ftp fetch support
# Rebuild curl with sftp support
apt-get install -y build-essential debhelper libssh2-1-dev
apt-get source curl
apt-get build-dep -y curl
cd curl-*
DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage
cd ..
dpkg -i curl*.deb libcurl3-nss*.deb libcurl4-doc*.deb libcurl4-openssl*.deb libcurl3_*.deb
# Use "drench" version which support `git ftp fetch`
@eric1234
eric1234 / toggle.js
Created November 21, 2013 17:17
Will toggle a hidden element. Depends on jQuery. Will slide the toggled content down and back up. Can optionally replace the label on the toggling link.
jQuery(document).ready(function($) {
$('a.toggle[href^="#"]').click(function(event) {
event.preventDefault();
var label;
var me = $(this);
var element = $(me.attr('href'));
if( element.is(':visible') ) {
element.slideUp();
if(label = me.attr('data-inactive-label')) me.html(label);
} else {
@eric1234
eric1234 / vagrant_mailcatcher.sh
Created November 20, 2013 15:30
Installs Mailcatcher. Assumes Ruby (https://gist.github.com/eric1234/6642819) already installed.
sudo apt-get install -y libsqlite3-dev
gem install mailcatcher
rbenv rehash
cat <<EOF | sudo tee /etc/init/mailcatcher.conf
description "Test mail server"
start on runlevel [2345]
stop on runlevel [016]
respawn
@eric1234
eric1234 / w.php
Created November 14, 2013 20:48
Easy array literals in PHP
<?php
# https://gist.github.com/eric1234/7474074
# Operates like Ruby's %w() operator. So
#
# w('foo bar baz') => array('foo', 'bar', 'baz')
function w($input) {
return preg_split('/\s+/', trim($input));
}
@eric1234
eric1234 / vagrant_php_asset_pipeline.sh
Last active December 27, 2015 15:09
A Vagrant shell provisioning script that will set the machine to serve /vagrant on port 9292. If the directory contains PHP it will be executed (CGI also but you may need to install additional support depending on language). Most importantly the Rails asset pipeline will be set-up allowing for automatical translation of sass and coffeescript.
# Install node for CoffeeScript
curl -s https://gist.github.com/eric1234/6642735/raw | sudo bash
# Install Ruby and libs for asset pipeline and Sass
curl -s https://gist.github.com/eric1234/6642819/raw/install_ruby_system.sh | sudo bash
curl -s https://gist.github.com/eric1234/6642819/raw/install_ruby_user.sh | bash /dev/stdin '2.0.0-p353'
bash -l -c "gem install rack-legacy sprockets sass coffee-script bourbon uglifier"
# Install PHP so we can serve PHP content
sudo apt-get install -y php5-cgi php5-cli php5-json
@eric1234
eric1234 / install_phpsh.sh
Created November 5, 2013 19:34
Install phpsh on Ubuntu
# https://gist.github.com/eric1234/7324795
# Make sure git is installed
apt-get install -y git
# Remove functions that phpsh needs from config.
sed -i 's/pcntl_signal,//g' /etc/php5/cli/php.ini
sed -i 's/pcntl_fork,//g' /etc/php5/cli/php.ini
sed -i 's/pcntl_wait,//g' /etc/php5/cli/php.ini
@eric1234
eric1234 / README.md
Last active December 24, 2015 16:39
Force unconnected boxes to have the same height

Usage

Assuming you have several boxes that form columns where they all need to be even height. Each column has the class "col". Then":

jQuery(window).load -> new EvenHeight $('.col')...

Note that we instantiated the object in the window load event. This allows any images that may affect the height to be loaded before the adjustment is done. If you don't have images or they all have inline sizes then you can trigger of the content loaded event to allow the page to adjust earlier:

jQuery(document).ready -> new EvenHeight $('.col')...