Skip to content

Instantly share code, notes, and snippets.

View tbassetto's full-sized avatar

Thomas Bassetto tbassetto

View GitHub Profile
@revolunet
revolunet / lzw_encoder.js
Created February 25, 2011 14:55
LZW javascript compress/decompress
// LZW-compress a string
function lzw_encode(s) {
var dict = {};
var data = (s + "").split("");
var out = [];
var currChar;
var phrase = data[0];
var code = 256;
for (var i=1; i<data.length; i++) {
currChar=data[i];
@lsmith
lsmith / iOS_details_arrow.css
Created March 6, 2011 07:56
The CSS to create an iOS details call-to-action arrow
/* assumes .details is position: relative */
.details::after {
content: '';
position: absolute;
border-top: 3px solid #7f7f7f;
border-right: 3px solid #7f7f7f;
height: 6px;
width: 6px;
top: 50%;
right: 12px;
@creationix
creationix / coorspin.html
Created March 6, 2011 22:54
A re-implementation of ColorSpin from iOS to webOS.
<!doctype html>
<html>
<head>
<title>ColorSpin</title>
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,user-scalable=no"/>
<style>
html { height: 100%; }
body {
height: 100%;
margin: 0;
// A simple module to replace `Backbone.sync` with *localStorage*-based
// persistence. Models are given GUIDS, and saved into a JSON object. Simple
// as that.
// Generate four random hex digits.
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
// Generate a pseudo-GUID by concatenating random hexadecimal.
@derekcollison
derekcollison / Cloud Foundry Production Updates
Created April 16, 2011 17:11
How to update your application in Cloud Foundry without dropping user requests..
# vmc update is great for test and development, however it stops your old app and stages and starts the new one,
# resulting in dropped requests.
# If you want to update an application without dropping user requests, see below.
# NOTE: This change assumes your application can share services, etc with the new version.
# Assume my app is named foo
vmc push foo-v2 --url foov2.cloudfoundry.com
@angus-c
angus-c / I_can_haz_10.lol
Created April 28, 2011 18:32
I can haz 10?
HAI
CAN HAS STDIO?
I HAS A VAR
IM IN YR LOOP
UP VAR!!1
VISIBLE VAR
IZ VAR BIGGER THAN 10? KTHXBYE
IM OUTTA YR LOOP
KTHXBYE
@angus-c
angus-c / variables.js
Created May 21, 2011 16:51
variable decalration
//one statement - all on one line - good for short, similar purpose vars
var foo = [], bar = [], buzz = [];
//multiple var statements - good for large number or disperate purpose vars
var a = 12;
var collate = false;
var foo = [1,2,3,4];
var circle = {radius: 2, color: blue};
//one statement on multiple lines, no indent
@leibovic
leibovic / dominant-color.js
Created June 9, 2011 16:27
Dominant Color
function getDominantColor(aImg) {
let canvas = document.createElement("canvas");
canvas.height = aImg.height;
canvas.width = aImg.width;
let context = canvas.getContext("2d");
context.drawImage(aImg, 0, 0);
// keep track of how many times a color appears in the image
let colorCount = {};
@necolas
necolas / snippet.js
Created June 14, 2011 20:36
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@cowboy
cowboy / truthy-eq-good-times.js
Created June 21, 2011 00:49
JavaScript: See what == what!
// This should do a pretty good job of iterating through the following array
// and logging any values that == each other. Beware, this is scary stuff!
// http://benalman.com/news/2010/11/schrecklichwissen-terrible-kno/
var arr = [true, 123, {}, {a:1}, [], [0], [123], "hi", function foo(){},
/re/, Infinity, false, 0, "", null, undefined, NaN];
function pretty(v) {
return /^[os]/.test(typeof v) ? JSON.stringify(v) : String(v);
}