Skip to content

Instantly share code, notes, and snippets.

Avatar
🍊
workin' goodly

Gianni Chiappetta gf3

🍊
workin' goodly
View GitHub Profile
@gf3
gf3 / example.js
Created Jun 12, 2009
Render JS string templates
View example.js
var data = {
business: {
id: 123,
service: "Cleaners",
name: "Weeoo",
user: {
id: 987,
name: "Jeff Smith"
}
}
@gf3
gf3 / gist:132012
Created Jun 18, 2009
Curry method in JavaScript
View gist:132012
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 / jsonp.js
Created Jun 18, 2009
Simple JSONP in vanilla JS
View jsonp.js
/**
* loadJSONP( url, hollaback [, context] ) -> Null
* - url (String): URL to data resource.
* - hollaback (Function): Function to call when data is successfully loaded,
* it receives one argument: the data.
* - context (Object): Context to invoke the hollaback function in.
*
* Load external data through a JSONP interface.
*
* ### Examples
@gf3
gf3 / gist:143893
Created Jul 9, 2009
Hidden elements on a page
View gist:143893
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 Jul 13, 2009
Get the iframe document object
View gist:146218
// 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."));
View gist:147681
document.observe('dom:loaded', function() {
$$('input[tabindex="1"]')[0].focus();
});
View we_is_gonna_be_rich.rb
=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 Jul 27, 2009
Proposed syntax for IRC bot
View gist:156663
// 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 Aug 11, 2009
Truncate a string to the closest word
View gist:166083
// 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 Dec 18, 2009 — forked from mislav/description.txt
Git Workflow
View description.txt
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]