This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Handy URL params access | |
* @example | |
* location.href = 'http://www.google.com/search?q=foo+bar&client=firefox' | |
* location.params == {q: 'foo+bar', client: 'firefox'} | |
*/ | |
// JS 1.6 | |
location.params = {}; | |
location.search.substr(1).split('&').forEach(function(el){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function source_of (array, up_to_dimension) { | |
// Your implementation | |
} | |
source_of([1, [2, [3]]], 0) == '[1, ?]' | |
source_of([1, [2, [3]]], 1) == '[1, [2, ?]]' | |
source_of([1, [2, [3]]], 2) == '[1, [2, [3]]]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# /usr/local/sbin/post-firewall | |
# $1 = vlan1 | |
# $2 = 192.168.1.1 | |
iptables -t nat -I PREROUTING 1 -p tcp -d "$2" --dport 80 -j DNAT --to "$2":8082 | |
iptables -t nat -D PREROUTING -i "$1" -p tcp --dport 80 -j DROP | |
iptables -t nat -I PREROUTING 2 -i "$1" -p tcp --dport 8082 -j DROP | |
iptables -I INPUT 1 -i "$1" -d "$2" -p tcp --syn --dport 8082 -j ACCEPT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# git config --global core.excludesfile /usr/local/git/exclude/exclude | |
# see http://groups.google.com/group/peepcode/browse_thread/thread/fe6f9c1fc9d6e725 | |
# Rivals | |
.svn | |
.hg | |
# Archives | |
*.zip | |
*.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JS Events API sucks. addEventListener ugly. If I'll design this API from scratch, I've done this: | |
window.events // {} | |
window.events.load // [] | |
window.events.load.length // 0 | |
window.events.load.push(function(e){ | |
alert('window loaded') | |
}) | |
window.events.load.length // 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example: | |
* 'hello {{username}}'.between('{{','}}') === 'username' | |
*/ | |
String.prototype.between_regexp = function between(begin, end) { | |
var regexp = new RegExp(begin + '(.+)' + end); | |
return this.match(regexp)[1]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function f(){/* comment */} | |
alert(f+''); | |
// Opera, IE, Chrome: function f(){/* comment */} | |
// Firefox, Safari: function f(){} | |
// | |
// Note: in Firefox: f+'' === f.toSource() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name ligatweet | |
// @namespace http://leaverou.me/demos/ligatweet/ | |
// @description Script for tweet shortening using unicode ligatures and other compound symbols | |
// @include htt*://twitter.com/* | |
// @author Lea Verou (UserJS by Nikita Vasilyev) | |
// @version 1.0 | |
// @license Licensed under the MIT license http://www.opensource.org/licenses/mit-license.php | |
// ==/UserScript== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'wrath, greed, sloth, pride, lust, envy, and gluttony'.match(/greed.+/) | |
#<MatchData "greed, sloth, pride, lust, envy, and gluttony"> | |
'wrath, greed, sloth, pride, lust, envy, and gluttony'.match(/greed.+?/) | |
#<MatchData "greed,"> |