Skip to content

Instantly share code, notes, and snippets.

View sukima's full-sized avatar

Devin Weaver sukima

View GitHub Profile
module Shoulda # :nodoc:
module ActiveRecord # :nodoc:
module Matchers
def validate_format_of(attr)
ValidateFormatOfMatcher.new(attr)
end
class ValidateFormatOfMatcher < ValidationMatcher # :nodoc:
@vrinek
vrinek / avatar.rb
Created June 25, 2009 12:02
attachment_fu custom error messages
class Avatar < ActiveRecord::Base
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 500.kilobytes,
:resize_to => 'c128x128',
:thumbnails => {:tiny => 'c24x24', :small => "c48x48"}
validates_as_attachment
after_validation :greeklize_attachment_errors
@LRDesign
LRDesign / deploy.rb
Created March 21, 2010 18:22 — forked from netzpirat/deploy.rb
Capistrano recipe to sync rails database and files, using remote database.yml instead of local for remote credentials
set :sync_directories, ["public/assets", "public/galleries"]
set :sync_backups, 3
module ActiveRecord
class Base
def self.random
if (c = count) != 0
find(:first, :offset =>rand(c))
end
end
end
end
@tobitailor
tobitailor / get_barcode_from_image.js
Created June 1, 2010 19:33
Barcode recognition with JavaScript - Demo: http://bit.ly/djvUoy
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',
@sukima
sukima / fnotify.sh
Created July 16, 2010 12:20
Grab irssi notifications from a SSH server
#!/bin/sh
# Retrieve irssi notifications from fnotify script via SSH.
# See full blog post at
# http://dev.tritarget.org/2010/07/16/irssi-notifications-over-ssh.html
SSH_CMD="ssh -p 22 username@yourshell.org"
# Set this to what ever unique key generation you wish
RESET_KEY=`date | sha1sum | cut -d\ -f1`
@sukima
sukima / User.rb
Created July 26, 2010 20:36
Parse a persons name into parts. Ruby on Rails
class Instructor < ActiveRecord::Base
# code graciously copied and pasted from
# http://mysmallidea.com/articles/2009/5/31/parse-full-names-with-ruby/index.html
def self.parse_name(name)
return false unless name.is_a?(String)
# First, split the name into an array
parts = name.split
@sukima
sukima / README.md
Created August 5, 2010 21:48
How to customize a global config YAML load in rails

I found this great [RailsCast][1] about making a global configuration. And further offered through the [Nifty Generators][2] (script/generate nifty_config) However I wanted to further customize it by allowing global configurations regardless of the environment.

For example this is the original idea: # config/config.yml development: perform_authentication: false

@sukima
sukima / application.js
Created August 6, 2010 23:36
jQuery datepicker with formtastic and rails
/**
* Shamlessly copied from http://snipt.net/boriscy/datetime-jquery-formtastic/
*
* This did not function with formtastic version 0.9.10
* I had to move the live("change") event below the initializing part
* I also had to adjust the jQuery selections as formtastic uses <ol>'s to
* seperate every select box.
*/
$(document).ready(function() {
#!/bin/bash
# SPDX-License-Identifier: MIT
## Copyright (C) 2009 Przemyslaw Pawelczyk <przemoc@gmail.com>
##
## This script is licensed under the terms of the MIT license.
## https://opensource.org/licenses/MIT
#
# Lockable script boilerplate