Skip to content

Instantly share code, notes, and snippets.

View juliocesar's full-sized avatar

Julio Cesar Ody juliocesar

View GitHub Profile
(function($) {
$.stuff = function(bitoftext) {
this.bitoftext = bitoftext;
}
$.extend($.stuff, {
report: function() { alert(this.bitoftext) }
})
# largely inspired by http://blog.macromates.com/2006/keychain-access-from-shell/
namespace :deploy do
desc "Generates database.yml from info store in Keychain"
task :generate_database_yml do
account = ENV['KEYCHAIN_ACC']
security_stdout = `security find-generic-password -ga #{account} 2>&1 > /dev/null`
if security_stdout[/could not be found/]
rollback
var table = $('<table />').attr('id', 'host-' + host.host).
.append('<thead />')
.find('thead')
.append('<tr />')
.find('tr')
.append('<th class="name">File name</th>')
.append('<th class="size">Size</th>')
.parent()
.parent()
.append('<tfoot />')
@juliocesar
juliocesar / gist:57892
Created February 4, 2009 02:41 — forked from lachie/gist:57891
hmm
var table = $([
'<table>',
'<thead>,
'<tr'>,
'<th>Foo</th>',
'<th>Bar</th>',
'</tr>',
'</thead>',
'<tfoot />',
'<tbody />'
# Maybe soon to be a feeds plugin. So you go like
#
# class Message < ActiveRecord::Base
# generates_feed do
# after :create, :like => ":sender has sent a message to :recipient"
# end
# end
#
# Capisce? Pure beauty.
# ps: Props to thinking_sphinx
@juliocesar
juliocesar / gist:83845
Created March 23, 2009 23:17
ANDing jQuery selectors
$.extend($.expr[':'], {
'and': function(a, i, m) {
return $(a).filter(m[3]).length
}
})
// Thus allowing $('p:and(.post)')
// finds <p class="post"></p>
# I admit this is somewhat nutty, but I needed to find a way for mini_feed
# (http://github.com/juliocesar/mini_feed/tree/master) to be able to access
# helpers, or more specifically, link_to, so feeds can have links in them.
# This is what I came up with
# for instance
class Book < ActiveRecord::Base
if defined?(Rails)
$.extend($.expr[':'], {
matches: function(e, i, m) {
if (!m[3]) return false;
var regexp = new RegExp(m[3], 'ig');
return regexp.test($(e).text());
}
})
// Usage:
// Say you have
// Oh, by the way, it works like this:
//
// $('myform :text:first').ghost('username');
//
// The above will make the first text element of a form display a
// slightly faded "username" text inside until focused.
$.ghost = function(element, label, options) {
if (typeof options == 'undefined') options = {};
var originalColor = $(element).css('color');
(function($) {
String.prototype.substrUntil = function(index, until, backwards) {
var string = [];
var regex = new RegExp(until, 'ig');
if (backwards) index--; // reverse the caret direction, pretty much
while(this[index]) {
if (regex.test(this[index])) break;
if (backwards) {
string.unshift(this[index]);
index--;