Skip to content

Instantly share code, notes, and snippets.

View willywongi's full-sized avatar

Francesco Pongiluppi willywongi

View GitHub Profile
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Checkbox personalizzate</title>
<style>
#custom_checkbox input[type=checkbox] { display: none; }
#custom_checkbox label { padding-left: 20px; background-position: 0px center;
background-repeat: no-repeat; cursor: pointer; }
/* Python(ish) string formatting:
* >>> format('{0}', ['zzz'])
* "zzz"
* >>> format('{x}', {x: 1})
* "1"
*/
var format = (function() {
var re = /\{([^}]+)\}/g;
return function(s, args) {
return s.replace(re, function(_, match){ return args[match]; });
@willywongi
willywongi / conan.js
Created March 29, 2011 13:36
arbitrary arguments length object constructor, in Javascript
function CONAN(cls) {
/* Arbitrary Number of Arguments Object Constructor,
ANAOC
but everyone calls him
CONAN
CONAN takes a Object Constructor and adds a static method named "build", whose only
argument is an array that get passed to the Constructor with an apply.
*/
var _helper = function(s) {
cls.apply(this, s);
@willywongi
willywongi / entity.js
Created October 26, 2011 08:04
My own way of playing with the Y.App framework.
/* global YUI=true */
/* Note: the "png" prefix you're seeing through this file is just my own
namespace. No reference to the Portable Network Graphic intended. */
YUI.add('png-entity', function(Y) {
/**
The ContainmentUnit's purposes are: creating Entity extensions, store them and handle
the relations between them.
@class ContainmentUnit
@constructor
@willywongi
willywongi / object-extras.js
Created December 29, 2011 14:02
Return a new object from an array of key/value pairs
/**
* Return a new object from an array of key/value pairs.
* Inspired by the "dict" constructor in python.
*
* @method dict
* @param {Array} arr An array of key/value pairs.
* @return {Object} A new object
* @static
*/
Y.namespace('Object').dict = function(arr) {
@willywongi
willywongi / dabblet.css
Created January 16, 2012 09:27
YouTube Footer Buttons
/*
YouTube Footer Buttons
*/
.button {
border: 1px solid #DDD;
border-radius: 3px;
text-shadow: 0 1px 1px white;
box-shadow: 0 1px 1px #fff;
font: bold 11px Sans-Serif;
@willywongi
willywongi / each_with_index.coffee
Created September 18, 2012 11:47 — forked from burin/each_with_index.coffee
each_with_index handlebars helper, adds an {{index}} prop accessible from within the block
Handlebars.registerHelper 'each_with_index', (array, fn) ->
buffer = ''
for i in array
item = i
item.index = _i
buffer += fn(item)
buffer
@willywongi
willywongi / 1-echo.js
Last active January 23, 2024 06:45
Load a Worker from a different domain (CORS + tricks)
/*
You want to use webworkers, but you host all of your js files on a different domain than where
your app lives (es. app.example.com and js.example.com). Given that the static file served from
js.example.com are CORS ready (in that the response header includes Accept-origin: *), I thought
I could load a Worker from other domains. I was almost wrong, but at last I found a solution:
XHRing the worker source and create an inline worker. This is tested only on Firefox (latest).
*/
// This is an example webworker that is on js.example.com. It just echoes messages it receive.
self.onmessage = function(e) {
self.postMessage(e.data);
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,
@willywongi
willywongi / .gitignore
Last active August 29, 2015 14:03 — forked from adamgit/.gitignore
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,