Skip to content

Instantly share code, notes, and snippets.

View JosePedroDias's full-sized avatar

José Pedro Dias JosePedroDias

View GitHub Profile
@JosePedroDias
JosePedroDias / listToArr.js
Last active August 29, 2015 14:03
use this for nodeList to array conversion
var listToArr = function(lst) {
var l = lst.length;
var arr = new Array(l); // optimizable *list-to-array
for (var i = 0; i < l; ++i) {
arr[i] = lst[i];
}
return arr;
};
@JosePedroDias
JosePedroDias / argumentsSnippet.js
Last active August 29, 2015 14:03
performant arguments handling
var ctx = this; // this can be skipped if you don't care about the context
var argsL = arguments.length;
var args = new Array(argsL); // optimizable arguments-to-array
for(var i = 0; i < argsL; ++i) {
args[i] = arguments[i];
}
@JosePedroDias
JosePedroDias / removeCycles.js
Created July 2, 2014 14:17
receives a JS object which may have cycles and returns another one with repeated cycles replaced by '[removed]' string. Use return instead if you don't mind them not being signalled.
var removeCycles = function(o) {
var seen = [];
var s = JSON.stringify(o, function(k, v) {
if (v !== null && typeof v === 'object') {
if (seen.indexOf(v) !== -1) {
//return;
v = '[removed]';
}
else {
@JosePedroDias
JosePedroDias / getMyIPs.js
Created July 2, 2014 13:24
returns object with network interface name -> IP address
var os = require('os');
var getMyIPs = function() {
var ips = {};
var ifaces = os.networkInterfaces();
var onDetails = function(details) {
if (details.family === 'IPv4') {
ips[ dev ] = details.address;
}
@staltz
staltz / introrx.md
Last active April 25, 2024 04:18
The introduction to Reactive Programming you've been missing
@devongovett
devongovett / translate.js
Created February 2, 2014 23:14
Use PhantomJS to translate stdin to english using Google Translate. Useful as a textmate command or just a command line tool.
#!/usr/bin/env phantomjs
var system = require('system');
var text = encodeURIComponent(system.stdin.read());
var url = "http://translate.google.com/#auto/en/" + text;
var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0';
page.onConsoleMessage = function (msg) {
@kevin-smets
kevin-smets / iterm2-solarized.md
Last active April 22, 2024 01:47
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@mathiasbynens
mathiasbynens / deterministic-math-random.js
Last active July 19, 2022 06:52
Here’s a 100% deterministic (predictable) alternative to `Math.random`. Useful when benchmarking.
// Here’s a 100% deterministic alternative to `Math.random`. Google’s V8 and
// Octane benchmark suites use this to ensure predictable results.
Math.random = (function() {
var seed = 0x2F6E2B1;
return function() {
// Robert Jenkins’ 32 bit integer hash function
seed = ((seed + 0x7ED55D16) + (seed << 12)) & 0xFFFFFFFF;
seed = ((seed ^ 0xC761C23C) ^ (seed >>> 19)) & 0xFFFFFFFF;
seed = ((seed + 0x165667B1) + (seed << 5)) & 0xFFFFFFFF;
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active April 19, 2024 11:00
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@domenic
domenic / promises.md
Last active March 31, 2024 14:07
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.