Skip to content

Instantly share code, notes, and snippets.

View gf3's full-sized avatar
🍊
workin' goodly

Gianni Chiappetta gf3

🍊
workin' goodly
View GitHub Profile
@gf3
gf3 / example.js
Created June 12, 2009 14:57
Render JS string templates
var data = {
business: {
id: 123,
service: "Cleaners",
name: "Weeoo",
user: {
id: 987,
name: "Jeff Smith"
}
}
@gf3
gf3 / gist:132012
Created June 18, 2009 17:02
Curry method in JavaScript
if (typeof Function.prototype.curry === 'undefined') {
Function.prototype.curry = function() {
var func = this
, a = Array.prototype.slice.call(arguments, 0)
return function () {
var a_len = a.length
, length = arguments.length
while (length--)
a[a_len + length] = arguments[length]
return func.apply(this, a)
@gf3
gf3 / gist:143893
Created July 9, 2009 18:58
Hidden elements on a page
Many times, when creating a site, I need hidden elements on a page that I must later make visible. Of course it would
be great if one could simply hide them via CSS, and later [easily] show them via javascript. However this is not the
case, javascript has some difficulties overriding styles set in a stylesheet. So, I've found the best way to
accomplish this is to use a combo of CSS and javascript in a two-step process:
1. Hide the elements via CSS class – so they are hidden when the user first sees the page
2. Hide the elements via javascript and remove the corresponding CSS class, after the DOM has loaded.
The second step has the potential to be quite expensive on the DOM, but I feel that it's an acceptable trade-off
because the elements in question are already hidden. This way they are ready to be manipulated, one doesn't need to
@gf3
gf3 / gist:146218
Created July 13, 2009 16:02
Get the iframe document object
// How to get the iframe document object
// Assume 'iframe' is a variable to the iframe DOM element
var iframe_document = null;
if (iframe.contentDocument) iframe_document = iframe.contentDocument;
else if (iframe.contentWindow) iframe_document = iframe.contentWindow.document;
else if (iframe.document) iframe_document = iframe.document;
else throw(new Error("Cannot access iframe document."));
document.observe('dom:loaded', function() {
$$('input[tabindex="1"]')[0].focus();
});
=begin
License: latest LGPL :D
As per my discussion with Gianni (@gf3),
http://twitter.com/phillmv/status/2659984348
http://twitter.com/phillmv/status/2660026344
http://twitter.com/phillmv/status/2660059102
http://twitter.com/phillmv/status/2660184885
http://twitter.com/phillmv/status/2660283856 and
http://twitter.com/phillmv/status/2660306850
@gf3
gf3 / gist:156663
Created July 27, 2009 18:19
Proposed syntax for IRC bot
// Proposed syntax for IRC bot
// ---------------------------
jerk(function() {
// `watch_for` takes a regular expression, and matches it against everything that is said
watch_for(/^api (\w+)\.(\w+)/, function(message) {
// Message object has properties: match_data, channel, user, text
// `say` replies in the channel that the message was heard in
say(message.user.nick + ": Something " + message.match_data[1]);
});
@gf3
gf3 / gist:166083
Created August 11, 2009 20:09
Truncate a string to the closest word
// Truncate a string to the closest word
String.prototype.truncateToWord = function( length ) {
return this
.slice( 0, length + 1 )
.split( /\s+/ )
.slice( 0, -1 )
.join( " " )
}
// Examples
@gf3
gf3 / description.txt
Created December 18, 2009 07:12 — forked from mislav/description.txt
Git Workflow
so my workflow is that each ticket gets a branch. Before merging the branch to master
it needs to be peer-reviewed. So sometimes I have a bunch of branches that are off
being reviewed while I work on something else.
Currently when I run "git branch" I see:
[branch 1]
[branch 2]
[branch 3]
*[branch 4]
[branch 5]
@gf3
gf3 / prototype.konami.js
Created December 18, 2009 13:02
KONAMI cheat code for your site!
// Example
document.observe("lol:konami", function() {
$(document.body).insert(new Element('h1').update("KONAMI!!!").setStyle({fontWeight: "bold", color: "red"}));
});