This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use helpers from models or any part of your app (you shouldn't do that, however...) | |
# ... put in config/initializers | |
# | |
# class MyModel < ActiveRecord::Base | |
# def some_attribute | |
# HelperProxy.instance.number_format some_value, precision: 4 | |
# end | |
# end | |
class HelperProxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class Proc | |
def ===(*parameters) | |
self.call(*parameters) | |
end | |
end | |
sunday = Proc.new { |time| time.wday == 0 } | |
monday = Proc.new { |time| time.wday == 1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require('adodbrecord/init.php'); # v0.5 or higher required | |
# CREATE TABLE cars (id INTEGER PRIMARY KEY, | |
# brand VARCHAR(50), | |
# color VARCHAR(50), | |
# destination VARCHAR(50) | |
# ) | |
require_once("AdoDBRecord://Car_Base"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Useful if your mp3 player doesn't like fancy long filenames | |
# | |
require 'digest/sha1' | |
Dir.glob("*.mp3") do |f| | |
name = f.downcase.split("."); | |
next if name.length < 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RVideo | |
module Tools | |
class Mp4creator | |
include AbstractTool::InstanceMethods | |
attr_reader :raw_metadata | |
def tool_command | |
'mp4creator' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A ruby implementation of python's with statement | |
# | |
# not sure if this is semantically identical, it was meant as a small excercise | |
module WithStatement | |
def with(*objs) | |
raise "no block given" unless block_given? | |
options = objs.unshift! if objs.last.is_a? Hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def labelled_form_for(name, object, options, &proc) | |
form_for(name, object, options.merge(:builder => LabellingFormBuilder), &proc) | |
end | |
def multipart_form_for(name, object, options, &proc) | |
html_options = options.delete(:html) || {} | |
html_options.merge!(:multipart => true) | |
form_for(name, object, options.merge(:html => html_options), &proc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Delayed | |
class Job < ActiveRecord::Base | |
def self.db_time_now | |
(ActiveRecord::Base.default_timezone == :utc) ? Time.now.utc : Time.zone.now | |
rescue NoMethodError | |
Time.now | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#slide-images { | |
position: relative; | |
display: block; | |
margin: 0px; | |
padding: 0px; | |
width: 738px; | |
height: 234px | |
overflow: hidden; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tableless ActiveRecord models | |
# http://stackoverflow.com/questions/315850/rails-model-without-database/318919#318919 | |
class Tableless < ActiveRecord::Base | |
def self.columns | |
@columns ||= []; | |
end | |
def self.column(name, sql_type = nil, default = nil, null = true) | |
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null) |
OlderNewer