Skip to content

Instantly share code, notes, and snippets.

###
# This is a demonstration of using SQLite3's Virtual File System API in Ruby.
#
# == Synopsis
#
# This program will store its SQLite database after the __END__ line.
#
# === In Detail
#
# SQLite3 uses the DATABase class as a proxy for our IO object. Upon
@indirect
indirect / gist:631628
Created October 18, 2010 02:49
improved git prompt yay
# [andre ~/.bash](master)$ # clean working directory
# [andre ~/.bash](master⚡)$ # dirty working directory
# [andre ~/.bash](master~2)$ # checked out revision not a branch
# [andre ~/.bash](branch)$ # checked out branch with same commits as master
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "⚡"
}
function parse_git_branch {
@al3xandru
al3xandru / gist:1156476
Created August 19, 2011 09:48
Open iTerm in Current Folder
on run {input, parameters}
tell application "Finder"
set sel to selection
if (count sel) > 0 then
set myTarget to item 1 of sel
else if (count window) > 0 then
set myTarget to target of window 1
else
set myTarget to path to home folder
end if
@zetter
zetter / deconstruct.markdown
Created January 31, 2012 21:10
therubygame deconstruct by @czetter

therubygame deconstruct by @czetter

This is a deconstuction of matematikaadit's submission to therubygame challenge 5; 'Roman numerals. What are they good IV?'. The goal of the challenge is to take a string representing a roman numeral as input and return the integer that the numeral represents.

matematikaadit currently has the honour of the shortest (by character count) submission for this challenge. At first glance I didn't understand how it worked so I re-wrote and analyzed it until I did.

Making it readable

matematikaadit's original submission:

@joshsusser
joshsusser / silence_assets.rb
Created April 17, 2012 22:34
put in config/initializers to silence asset logging in Rails development mode
if Rails.env.development?
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'] =~ %r{^/assets/}
call_without_quiet_assets(env)
ensure
@flomotlik
flomotlik / Gemfile
Created May 6, 2012 09:46 — forked from leshill/Procfile
Unicorn config for cedar stack on Heroku.
gem 'unicorn'
@dakatsuka
dakatsuka / amqp.rb
Created May 14, 2012 09:02
Rails3 + unicorn + RabbitMQ
# config/initializers/amqp.rb
require 'amqp/utilities/event_loop_helper'
require 'amqp/integration/rails'
module AMQPManager
def self.start
AMQP::Utilities::EventLoopHelper.run
AMQP::Integration::Rails.start do |connection|
connection.on_error do |ch, connection_close|
raise connection_close.reply_text
@camertron
camertron / ruby-cldr-export.rb
Created May 24, 2012 23:48
Exporting base CLDR data using Sven Fuch's ruby-cldr gem
require 'rubygems'
require 'ruby-cldr'
require 'cldr'
require 'cldr/data'
require 'cldr/download'
require 'yaml'
# NOTE: nb = no (norwegian)
locales = ["he", "en", "fr", "it", "de", "es", "ja", "ko", "ru", "tr", "pt", "fil", "hi", "ms", "id", "nl", "da", "sv", "pl", "hu", "fi", "nb", "zh", "zh-Hant", "ar", "fa", "ur", "th", "uk", "ca", "el", "af", "cs", "eu"]
components = ["calendars", "currencies", "delimiters", "languages", "numbers", "Plurals", "territories", "timezones", "units"]
@nathany
nathany / ruby2.md
Last active December 20, 2015 00:59
Ruby 2.0 backwards incompatible changes

Ruby 2.0 backwards incompatible changes

From Peter Cooper's Walkthrough:

  • lines, bytes, chars, codepoints returned an Enumerator in 1.9 -> use each_lines, each_bytes, each_chars, each_codepoints instead for an Enumerator
  • # encoding: utf-8 is the default (which impacts regular expressions that expect it to be us-ascii, eg. vpim)
  • respond_to? on a protected method returns false (was true)
  • inspect doesn't use the redefined to_s
  • Array#values_at returns nil for each number outside of the array
  • CSV.dump & CSV.load are gone (object serialization)
@jehiah
jehiah / activity_snapshot.sh
Created January 7, 2013 18:43
A cron job script to capture computer activity every 30 seconds
#!/bin/sh
# computer activity data collection for http://jehiah.cz/one-two/
# by Jehiah Czebotar
FILE="activity_log/`date +%Y%m%d`.log"
function log_activity()
{
local UTC=`date "+%s,%Z"`
local IDLE=$((`/usr/sbin/ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/!{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000 ))