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 / gist:349292
Created March 30, 2010 16:54 — forked from paulirish/gist:274913
jQuery backgroundPosition
// The CSS property backgroundPosition does not exist in the accessible DOM properties within IE 8.
// this monkeypatch retifies that issue
// usage: $(elem).css('backgroundPosition');
// ticket: http://dev.jquery.com/ticket/5749
(function($){
var _css = $.fn.css;
@gf3
gf3 / gist:357155
Created April 6, 2010 02:37 — forked from paulirish/gist:357048
Average hex colour
// get the average color of two hex colors.
function avgcolor(color1,color2){
var avg = function(a,b){ return (a+b)/2; },
t16 = function(c){ return parseInt((''+c).replace('#',''),16) },
hex = function(c){ return (c>>0).toString(16) },
hex1 = t16(color1),
hex2 = t16(color2),
r = function(hex){ return hex >> 16 & 0xFF},
g = function(hex){ return hex >> 8 & 0xFF},
b = function(hex){ return hex & 0xFF},
@gf3
gf3 / gist:361449
Created April 9, 2010 18:41 — forked from paulirish/gist:315916
Everyones favourite closure!
// everyone's new favorite closure pattern:
(function(window,document,undefined){ ... })(this,this.document);
// when minified:
(function(w,d,u){ ... })(this,this.document);
// which means all uses of window/document/undefined inside the closure
// will be single-lettered, so big gains in minification.
// it also will speed up scope chain traversal a tiny tiny little bit.
@gf3
gf3 / comma-first-var.js
Created April 9, 2010 18:56 — forked from isaacs/comma-first-var.js
A better coding convention for lists and object literals in JavaScript
// See comments below.
// This code sample and justification brought to you by
// Isaac Z. Schlueter, aka isaacs
// standard style
var a = "ape",
b = "bat",
c = "cat",
d = "dog",
@gf3
gf3 / fold.c
Created April 20, 2010 18:25 — forked from Veejay/fold.c
Inject in C
#include <stdio.h>
#include <stdlib.h>
struct node{
void* data;
struct node* next;
};
void set_int_value(struct node* node, int val)
{
@gf3
gf3 / linked_list.c
Created April 20, 2010 18:25 — forked from Veejay/linked_list.c
Map in C
#include <stdio.h>
#include <stdlib.h>
struct node{
void* data;
struct node* next;
};
void set_int_value(struct node* node, int val)
{
/*
userData = {
'person1' : [1,2,3,4],
'person2' : [3,4,5,6]
}
function returns
{
'person1': {'person2': [3, 4]},
@gf3
gf3 / html5.vim
Created May 5, 2010 15:27 — forked from rcmachado/html5.vim
vim HTML5 Syntax File
" Vim syntax file
" Language: HTML (version 5)
" Maintainer: Rodrigo Machado <rcmachado@gmail.com>
" URL: http://rm.blog.br/vim/syntax/html.vim
" Last Change: 2009 Aug 19
" License: Public domain
" (but let me know if you liked it :) )
"
" Note: This file just adds the new tags from HTML 5
" and don't replace default html.vim syntax file
i = [10,20,30,40,50].index {|n| n > 20 }
/*!
* jQuery whenLoaded - v0.1pre - 06/25/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// NOTE: TOTALLY UNTESTED!