Skip to content

Instantly share code, notes, and snippets.

View airblade's full-sized avatar

Andy Stewart airblade

View GitHub Profile
@ahoward
ahoward / presenter.rb
Created February 22, 2012 23:09
worlds simplest presenter pattern. drop in replacement for ActiveRecord/Mongoid models in your controller
# the worlds lightest weight presenter pattern. to use simply
#
# file app/presenters/post_presenter.rb
#
# PostPresenter =
# Presenter.for(Post) do
# validates_presence_of :custom_field_for_this_form
#
# end
#
@mislav
mislav / aprompt.png
Last active February 11, 2024 06:40
My zsh prompt. No oh-my-zsh needed
aprompt.png
@olegch
olegch / README.md
Created January 24, 2012 16:46
These scripts are used for simple management of hostnames for several VirtualBox VMs comprising a test or sandbox environment on your local machine.

These scripts are used for simple management of hostnames for several VirtualBox VMs comprising a test or sandbox environment on your local machine.

Architecture:

  1. each VM is configured to use bridged network adapter, so all VMs and the host can see each other

  2. a script is installed in each VM to run on post-ifup, which grabs VM's IP, puts "$IP $desired-hostname $desired-fully-qualified-hostname" into /etc/hosts, changes hostname correspondingly, and puts VM's hostname and fq-hostname into VM's properties

  3. a script is used on the host machine, which loops through running VMs, and updates /etc/hosts on the host machine and on the VMs

@mislav
mislav / stupid-json.rb
Created December 21, 2011 12:31
Stupid simple JSON parser & generator
# encoding: utf-8
#
## Stupid small pure Ruby JSON parser & generator.
#
# Copyright © 2013 Mislav Marohnić
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the “Software”), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
@ahoward
ahoward / init-all-ruby-apps.rb
Created December 20, 2011 16:01
/usr/bin/ruby # using rbenv to manage a system ruby that's available during init.d
#! /usr/bin/ruby
# file: /etc/init.d/rubyapps
#
#
globs = %w(
/ebs/apps/*/init.rb

Fibur

Fibur is a library that allows concurrency during Ruby I/O operations without needing to make use of callback systems. Traditionally in Ruby, to achieve concurrency during blocking I/O operations, programmers would make use of Fibers and callbacks. Fibur eliminates the need for wrapping your I/O calls with Fibers and a callback. It allows you to write your blocking I/O calls the way you normally would, and still have concurrent execution during those I/O calls.

Example

Say you have a method that fetches data from a network resource:

@ryanb
ryanb / index.js.erb
Created December 16, 2011 23:22
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
@ahoward
ahoward / version.rb
Created December 8, 2011 03:49
a nice and simple version class
class Version < ::String
class Error < ::StandardError; end
attr :major
attr :minor
attr :teeny
def Version.default
Version.for('0.0.0')
end

Since Obie Fernandez posted his demands as a consultant I thought I would post mine too.

  • I will be paid $10,000 per day, in $50 bills, in a titanium briefcase that you will purchase for the sole purpose of providing a container for my money. You may not re-use the briefcase for the next day's payment.
  • The $50 bills must have been printed in the last three months and handled by no more than 2 people.
  • Anybody handling the money must do so with clean white gloves that must be placed on the hand immediately before touching the briefcase. If the hand leaves the briefcase, the white gloves must be replaced with new ones before the briefcase is touched again.
  • I will arrive in your city by a private jet. Fuel and any other costs incurred by this trip will be paid by you, and is not included in the $10k/day fee.
  • Transportation from my jet to your workplace must be performed by a driver who is between the ages of 50
@ahoward
ahoward / gist:1338691
Created November 4, 2011 04:58
how dojo4 is running apache -> unicorn | file ./script/unicorn
#! /usr/bin/env ruby
# file: RAILS_ROOT/script/unicorn
#
# this script has a runs a rails app under a specific rails_env and ruby
# version based on a local cap configuration. it has a few goals:
#
# - a single script is used to run servers for all of
# - local development
# - init.id on the remote server