Skip to content

Instantly share code, notes, and snippets.

View agentcooper's full-sized avatar

Artem Tyurin agentcooper

View GitHub Profile
@padolsey
padolsey / 1.js
Created February 21, 2013 21:26
A little JS [ES3] task: In each case, implement `x` so that the expression is true. Do not modify the expressions though. Post your solutions as a fork of this gist. ***Remember: ES3 only.
/x/==x
@abozhilov
abozhilov / gist:4011690
Created November 4, 2012 12:27
repeat
function repeat(obj, times) {
var res = typeof obj == 'string' ? '' : [];
times = Math.max(1, times);
do {
if (times & 0x1) res = res.concat(obj);
obj = obj.concat(obj);
} while ((times >>= 1));
return res;
}
@abozhilov
abozhilov / gist:3895019
Created October 15, 2012 20:08
Partial application Value range
function valueRange(start, end) {
return function (value) {
return Math.min(Math.max(value, start), end);
};
}
//Get new value range [0, 20]
var f = valueRange(0, 20);
console.log(f(10)); //10
function ctor(fn) {
function F () {
var obj = Object.create(F.prototype);
fn.apply(obj, arguments);
return obj;
}
F.prototype = Object.create(fn.prototype);
return F;
}
@theturtle32
theturtle32 / compilingNode0.8.4onCentOS5.md
Created July 25, 2012 20:57
Compiling and Installing Node v0.8.4 on CentOS 5.x

Compiling/Installing Node 0.8.4 (and Python 2.6, required by Node) on CentOS 5

Update system packages -- will migrate system forward to CentOS 5.8. (Optional?)

$ sudo yum update

Install the EPEL Repo:

@abozhilov
abozhilov / gist:2594795
Created May 4, 2012 13:27
State machine
var GO = 'GO',
OK = 'OK',
SIGN = 'SIGN',
LZERO = 'LZERO',
INT = 'INT',
FRAC = 'FRAC',
FDIG = 'FDIG',
EXP = 'EXP',
XSIGN = 'XSIGN',
EDIG = 'EDIG',
@mfontani
mfontani / extract-subs.pl
Created December 29, 2011 12:23
Grab subroutines (and variable parameters!) from a Perl file
#!/usr/bin/env perl
use common::sense;
use PPI;
my $file = shift;
die "Need a file to operate on\n"
if !$file
|| !-f $file;
my $doc = PPI::Document->new($file);
@Raynos
Raynos / iterateWalk.js
Created December 13, 2011 19:34
All the DOM recursion you'll ever need
var slice = Array.prototype.slice
function iterativelyWalk(nodes, cb) {
nodes = slice.call(nodes)
while(nodes.length) {
var node = nodes.shift(),
ret = cb(node)
if (ret) {
@jasonLaster
jasonLaster / ConsoleTricks.html
Created February 27, 2011 21:47
WebKit Console tricks adapted from CSS Ninja's excellent tutorial http://bit.ly/fi4lnK
<html>
<body>
<script type="text/javascript" charset="utf-8">
// CONSOLE log
var foo = {baz: "tubular", goo: "rad"}, bar = "baz";
console.log("string",1,foo.goo,bar,foo.baz); // string 1 rad baz tubular
console.log(foo)
// CONSOLE Printf
var foo = {baz: "tubular", goo: "rad"}, bar = "baz";