Skip to content

Instantly share code, notes, and snippets.

@subimage
subimage / prince_xml.rb
Created February 7, 2013 22:58
Prince XML library I created in 2007
# Prince XML Ruby interface.
# http://www.princexml.com
#
# Library by Subimage Interactive - http://www.subimage.com
#
#
# USAGE
# -----------------------------------------------------------------------------
# prince = Prince.new()
# html_string = render_to_string(:template => 'some_document')
@subimage
subimage / sync_database.rb
Created February 7, 2013 22:27
Capistrano task to import production database code locally.
namespace :db do
desc "Load production data into development database"
task :load_production_data, :roles => :db, :only => { :primary => true } do
require 'yaml'
# Gets db yml from server, because we don't store it on dev boxes!
get "#{current_path}/config/database.yml", "tmp/prod_database.yml"
prod_config = YAML::load_file('tmp/prod_database.yml')
local_config = YAML::load_file('config/database.yml')
@subimage
subimage / sync.rb
Created November 2, 2012 14:17
Capistrano recipe to sync database with production machine
namespace :sync do
desc "Load production data into development database"
task :database, :roles => :db, :only => { :primary => true } do
require 'yaml'
# Gets db yml from server, because we don't store it on dev boxes!
get "#{current_path}/config/database.yml", "tmp/prod_database.yml"
prod_config = YAML::load_file('tmp/prod_database.yml')
local_config = YAML::load_file('config/database.yml')
@subimage
subimage / ChildView.js
Created September 25, 2012 10:26
Sencha Touch 2 "child store" that keeps data sync'd from a parent Ext.data.Store
// A sub-store implementation that allows you to store local
// cached records in a 'parentStore', and then use this to present
// a view you can filter on for DataViews like List, etc.
//
// Dynamically selects data from parentStore, and refreshes itself
// when data in that store is changed.
//
// Allows passing a queryFunc to restrict selection of records
// from the parentStore.
Ext.define('CbMobile.store.ChildView', {
@subimage
subimage / FullScreenTextArea.js
Created September 12, 2012 01:26
A fullscreen textarea for Sencha Touch 2
// The default TextAreaField in Sencha touch 2 is difficult to use
// on a mobile device.
//
// This when tapped to edit, this displays the text full screen, and allows
// for better reading and editing.
//
// Modified from 'BetterTextArea'
// http://colinramsay.co.uk/diary/2012/05/18/a-better-textareafield-for-sencha-touch-2/
Ext.define('Ext.ux.field.FullScreenTextArea', {
@subimage
subimage / ColorPickerField.js
Created September 11, 2012 08:39
Sencha Touch 2 custom colorpicker
/*
Original Author : Mitchell Simoens
ST2 revision Author : Di Peng
ST2 revised revision by: webmaster@subimage.com
Purpose : Creation of a custom color picker
License : GPL v3 (http://www.gnu.org/licenses/gpl.html)
Warranty : none
Price : free
@subimage
subimage / CbMobile.model.Base.js
Created September 9, 2012 18:40
Sencha touch data model that fires CRUD events and can reload data from server
// Extended model that fires events on CRUD actions,
// and allows for reloading of data from the server.
Ext.define('CbMobile.model.Base', {
extend: 'Ext.data.Model',
// Overloaded methods that fire events
set: function(fieldName, value) {
this.callParent(arguments);
this.fireEvent('set', fieldName, value);
},
@subimage
subimage / .autotest.rb
Created July 8, 2012 20:45
Pass files or directories to autotest
# If you have a large test suite, being able to test only a subset
# of those items is a big speed boost.
#
# With this in your .autotest file you can run "autotest /some/dir" and only test
# the files within.
#
require 'redgreen/autotest'
Autotest.add_hook :initialize do |at|
unless ARGV.empty?
@subimage
subimage / gnarly_rails_scope.rb
Created July 6, 2012 04:53
Gnarly Rails scope of the day
# Projects a user has access to either through ProjectAssignment, or as an "account manager"
named_scope :user_has_access_to, lambda{|user|
{
:select => 'DISTINCT projects.*',
:joins => %q\
LEFT JOIN project_assignments
ON (
projects.id = project_assignments.project_id
AND project_assignments.has_access = 1
)
@subimage
subimage / fuck_yourself_in_ie.js
Created June 28, 2012 20:48
How you can totally fuck yourself with JavaScript in IE.
// Inline assignment inside an 'if' statement works with most programming languages.
// However, in JavaScript there's a gotcha.
// This works in Safari, Firefox & Chrome...but will destroy your life in IE.
if(thing=functionThatReturnsThing()) {
doStuff();
}
// Do this instead
var thing=functionThatReturnsThing();