Skip to content

Instantly share code, notes, and snippets.

def random_datetime( date_ini = '1970/01/01 10:10', date_end = '2010/01/01 10:10' )
time_ini_int = Time.parse( date_ini ).to_i
time_end_int = Time.parse( date_end ).to_i
time_random_int = Kernel.rand( time_end_int - time_ini_int ) + time_ini_int
return Time.at( time_random_int )
end
require 'rubygems'
require 'yaml'
require 'ec2'
AWS_ACCESS_KEY_ID = 'xxx'
AWS_SECRET_ACCESS_KEY = 'xxx'
@ec2 = EC2::Base.new(:access_key_id => AWS_ACCESS_KEY_ID, :secret_access_key => AWS_SECRET_ACCESS_KEY)
puts "------------------"
puts "without aws/s3"
------------------
without aws/s3
------------------
---
reservationSet
  item
  - reservationId
    groupSet
      item
      - groupId
require 'paperclip/geometry'
module Paperclip
module ClassMethods
# Places ActiveRecord-style validations on the width of the file assigned. The
# possible options are:
# * +in+: a Range of pixels (i.e. +10..100+),
# * +less_than+: equivalent to :in => 0..options[:less_than]
# * +greater_than+: equivalent to :in => options[:greater_than]..Infinity
# * +message+: error message to display, use :min and :max as replacements
def validates_attachment_width name, options = {}
require File.dirname(__FILE__) + '/../test_helper'
class PhotoTest < ActiveSupport::TestCase
def test_geometry_validations
@paper = papers(:paper1)
Paper.validates_attachment_width :photo, :greater_than => 576, :less_than => 1000
Paper.validates_attachment_height :photo, :greater_than => 150, :less_than => 300
@paper.photo = File.new( "#{RAILS_ROOT}/test/fixtures/photos/photo50x30.png" )
assert( !@paper.valid? )
# puts "XXX1: #{@paper.errors.full_messages}"
# fguillen 2009-06-25:
# inspired on: http://github.com/patientslikeme/migration_helpers/tree/
#
# add a foreign key constraint
# add_foreign_key 'books', 'author_id', 'authors'
#
class ActiveRecord::Migration
def self.add_foreign_key(
table,
target_table,
/*
* fguillen: 2009-07-09
* return the last word from cursor on a textarea
* example: alert( "last word from cursor: " + $('#my_textarea').lastWord() )
*/
jQuery.fn.lastWord = function() {
var buffer = '';
this.each(function(){
if (this.selectionStart || this.selectionStart == '0') {
/*
* fguillen: 2009-07-09
* delete the last word from cursor on a textarea
* example: $('#my_textarea').deleteLastWord();
*/
jQuery.fn.deleteLastWord = function() {
this.each(function(){
if (this.selectionStart || this.selectionStart == '0') {
var startPos = this.selectionStart;
var endPos = this.selectionEnd;
# Add a bunch of twitter users to one of your twitter lists
#
# use it with a file full of twitter usernames
# one name by line
#
# If the listname indicated doesn't exist it will be created
#
# Example: $ ruby twitter_lists.rb 'username' 'userpass' 'listname' twitter_users.txt
#
# Debug mode: $ ruby twitter_lists.rb 'username' 'userpass' 'listname' twitter_users.txt debug
$('.lazy_loading').each(function() {
if( !this.complete ){
var image = $(this);
var image_original_src = $(this).attr('src');
image.attr({src: '/images/item_image_loading.gif'});
(function() { // New scope hack
var _image = image;