Skip to content

Instantly share code, notes, and snippets.

View mfilej's full-sized avatar

Miha Filej mfilej

View GitHub Profile
# Used for IO objects that need to report the current offset at each operation that changes the said offset
# (useful for building progress bars that report on a file read operation)
class ProgressiveIO < DelegateClass(IO)
# Should contain a block that accepts the current offset in bytes and the total size
attr_accessor :progress_block
# Get or set the total size of the contained IO. If the passed IO is a File object
# the size will be preset automatically
attr_accessor :total_size
@mislav
mislav / brew-log.rb
Created April 17, 2010 12:34
brew-log command for displaying git log of selected Homebrew formulae
#!/usr/bin/env ruby -wKU
if ARGV.empty?
puts "Usage: #{File.basename $0} <names>"
exit(2)
else
dir = `brew --prefix`.chomp
exec 'git', "--git-dir=#{dir}/.git", 'log', '--', *ARGV.map { |name|
"Library/Formula/#{name}.rb"
}
@futureshocked
futureshocked / Bash
Created June 12, 2010 22:23
This is an example on how to use MacRuby to read/write CoreData records. Tested with MacRuby 0.6 on Mac OS X 10.6.3.
$ /Developer/usr/bin/momc simpleTextMessageModel.xcdatamodel simpleTextMessageModel3.mom
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
@Krule
Krule / articles_controller.rb
Created July 16, 2010 13:13
Pluralize using Rails 3 in Slovenian language
class ApartmentsController < ApplicationController
def index
@apartments = Apartment.all
end
end
@mislav
mislav / _notes.md
Created July 21, 2010 18:25
"livereload" server replacement for working with Rails

A replacement for "livereload" gem on OS X

This script is a replacement for livereload server component designed for working with Rails. It watches the filesystem with FS Events (Mac OS X) rather than with EventMachine. This is better for large projects for wich EventMachine fails with "too many open files" exception.

Sass is supported; .sass files can also be stored in "app/styles/" directory. Compass is detected if "config/compass.rb" file exists.

Installation:

Download this script to somewhere in your PATH and make it executable. You can name it something different than "livereload" if you want to try this and the official gem executable in parallel.

#!/bin/bash
#
# mkv2m4v inputfile.mkv
#
# Given an MKV container with H.264 video and AC3 audio, converts
# quickly to an iPad-compatible MP4 container without re-encoding the
# video (so it must already be in an iPad-compatible resolution); the
# audio is downmixed to stereo with Dynamic Range Compression.
#
ME=$(basename $0)
@LeeRJohnson
LeeRJohnson / html5-doctype-en-utf-8.html
Created August 25, 2010 17:33
HTML5 Optimized Markup Document Starts
<!doctype html>
<html lang=en>
<meta charset=utf-8>
<title>Valid HTML5 Document - Language English - Encoding UTF-8</title>
require "ffaker"
class ActiveRecord::Base
def self.define_factory(name=:factory, &block)
scope name, lambda { |overrides={}|
attributes = instance_eval(&block).merge(overrides)
where(attributes)
}
end
end
@mislav
mislav / sass_heroku.rb
Created September 17, 2010 22:17
Detect and compensate for Sass / Compass on Heroku
# drop into "initializers" dir
heroku = !!ENV['HEROKU_TYPE']
css_dir = heroku ? 'tmp' : 'public'
location = Rails.root + 'app/styles'
unless Sass::Plugin.template_location_array.any? { |pair| pair.first.to_s == location.to_s }
Sass::Plugin.add_template_location(location, Rails.root + css_dir + 'stylesheets')
end