Skip to content

Instantly share code, notes, and snippets.

Avatar

Julio Cesar Ody juliocesar

View GitHub Profile
View gist:41145
(function($) {
$.stuff = function(bitoftext) {
this.bitoftext = bitoftext;
}
$.extend($.stuff, {
report: function() { alert(this.bitoftext) }
})
View gist:46319
# 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
View gist:57888
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 />')
View gist:57892
var table = $([
'<table>',
'<thead>,
'<tr'>,
'<th>Foo</th>',
'<th>Bar</th>',
'</tr>',
'</thead>',
'<tfoot />',
'<tbody />'
View gist:61334
# 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 Mar 23, 2009
ANDing jQuery selectors
View gist:83845
$.extend($.expr[':'], {
'and': function(a, i, m) {
return $(a).filter(m[3]).length
}
})
// Thus allowing $('p:and(.post)')
// finds <p class="post"></p>
View gist:96149
# 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)
View gist:184370
$.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
View gist:188340
// 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');
View gist:203610
(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--;