Skip to content

Instantly share code, notes, and snippets.

@tomasdev
tomasdev / gist:1459269
Created December 11, 2011 08:07
writing my name obfuscating JS
// the M is the problem.
var tomas = ([!![]]+[])[+[]]+([]+{})[+!![]]+((+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!+[]+[])[+[]]+(!+[]+[])[!+[]+!+[]+!+[]]+(!+[]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!+[]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!+[]+[])[+[]]+(!+[]+[])[!+[]+!+[]+!+[]]+(!+[]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!+[]+[])[+[]]+(!+[]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!+[]+[])[+[]]+(!+[]+[])[!+[]+!+[]+!+[]]+(!+[]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!+[]+[])[+[]]+(!+[]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!+[]+[])[+[]]+(!+[]+[])[!+[]+!+[]+!+[]]+(!+[]+[])[+!+[]]])[+!+[]+[+[]]]+(!+[]+[])[+!+[]]]+[])[+!+[]+[+!+[]]]+(![]+[])[+!![]]+(![]+[])[-~-~+!![]];
// ta-da
console.log(tomas);
@tomasdev
tomasdev / splitAll.js
Created December 20, 2011 03:56
String multiple split
String.prototype.splitAll = function(){
var i = arguments.length,
original = this,
str = arguments[--i];
for( ; str ; ){
original = original.split(str);
(str = arguments[--i]) && (original = original.join(str));
}
return original;
}
@tomasdev
tomasdev / byCOWBOY
Created January 2, 2012 20:59
update chromium
#!/bin/bash
if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
Chromium Updater
http://benalman.com/
Usage: $(basename "$0") [revision]
Download and install the latest Chromium and dev tools, modifying the binary
to use those custom dev tools (downloaded into ~/.dotfiles/caches/chromium).
@@ -339,6 +339,12 @@ var Cufon = (function() {
return glyphs;
})(data.glyphs);
+ this.missingGlyphs = '';
+ for (var i in this.glyphs) {
+ this.missingGlyphs += i;
+ }
+ this.missingGlyphsRegexp = new RegExp("[^" + this.missingGlyphs.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + "]");
+
@tomasdev
tomasdev / date.js
Created January 16, 2012 13:16
date comparison
/**
* Long version
*/
var isLeap = function(year) {
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
};
var getAge = function(birthDate) {
var now = new Date(),
age = 0,
// days since the birthdate
@tomasdev
tomasdev / levenshtein.js
Created February 29, 2012 00:48
Levenshtein JavaScript
var levenshtein = function(str1, str2) {
str1 = str1.split("");
str2 = str2.split("");
var distance = [],
l = str1.length,
m = str2.length,
i, j;
for( i = 0; i <= l; i++ ) {
@tomasdev
tomasdev / psort.js
Created April 1, 2012 22:10
Array of Objects property sort
/**
* @type void as per Array#sort
* @see http://jsfiddle.net/tomasdev/ns2wj/
*/
/** @version 1 */
Array.prototype.psort=function(p){p&&this.sort(function(a,b){return(a[p]<b[p]?-1:a[p]>b[p])})};
/** @version 2 */
Array.prototype.psort=function(p,g,u){p&&this.sort(function(a,b){return +((typeof a[p]===u+"")?!g:((typeof b[p]===u+"")?g:((a[p]<b[p])?-1:(a[p]>b[p]))))})};
@tomasdev
tomasdev / gist:3163571
Created July 23, 2012 13:19 — forked from paulirish/gist:366184
html5 geolocation with fallback.
// geo-location shim
// currentely only serves lat/long
// depends on jQuery
// doublecheck the ClientLocation results because it may returning null results
;(function(geolocation){
if (geolocation) return;
@tomasdev
tomasdev / relativeTime.js
Created July 23, 2012 14:13
Relative Time JS
/**
* Relative time converter
* FIXME: fix hardcoded strings (ago, just now)
* @param {Date} dateObj Date object to convert to string
* @return {String}
*/
var relativeTime = function(dateObj) {
var delta = new Date() - dateObj;
now_threshold = 5000;
if (delta <= now_threshold) {
@tomasdev
tomasdev / Laravel-Resource.sublime-snippet
Created September 20, 2012 04:38
Laravel resource routing creation snippet for Sublime Text 2
<snippet>
<content><![CDATA[
// $1 Resource
Route::get('$1s', array('as' => '$1s',
'uses' => '$1s@index'));
Route::get('$1s/(:any)', array('as' => '$1',
'uses' => '$1s@show'));
Route::get('$1s/new', array('as' => 'new_$1',
'uses' => '$1s@new'));
Route::get('$1s/(:any)/edit', array('as' => 'edit_$1',