Skip to content

Instantly share code, notes, and snippets.

@edygar
edygar / websocket-ping-server.js
Last active November 17, 2015 21:01
Receives request of pings to desired hostnames and responds with the pongs at its arrival through WebSocket
import netPing from 'net-ping';
import express from 'express';
import http from 'http';
import dns from 'dns';
import socketIO from 'socket.io';
import { BehaviorSubject, Observable } from 'rx';
const app = express();
const server = http.Server(app);
const io = socketIO(server);
@edygar
edygar / introrx.md
Last active August 29, 2015 14:27 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@edygar
edygar / LerNumeros.rb
Created June 16, 2015 12:52
Gist de explicação como ler apenas números em Ruby para ajudar um amigo ;D
# Para números inteiros, é bem mais fácil
puts "Input a number: "
# a gente lê para o input o que o usuário digitou e
# testa de convertando para inteiro e depois para string
# o valor continua sendo o mesmo, se sim, é inteiro:
# Exemplos:
# "asdasda".to_i => 0.to_s => "0" != "asdasda"
# "0".to_i => 0.to_s => "0" == "0"
# "123123".to_i => 123123.to_s => "123123" == "123123"
while(input = gets.chomp and input.to_i.to_s != input)
@edygar
edygar / PromiseBasedAPI.js
Created January 21, 2015 11:07
Promise Epiphany
function get(path) {
return user.waitForAuthentication()
.then(function() {
return $http.get(path);
})
.then(function(response){
return resposne data;
})
}
@edygar
edygar / Convert Groups To Layers.jsx
Last active July 19, 2023 14:44
Illustrator Script: Convert Groups under selected to Layers
// Save to... /Applications/Adobe Illustrator CC/Presets.localized/<LOCALE>/Scripts/
// Polyfill for forEach
function forEach(array, fn, scope) {
scope = scope || array;
// array is cloned in order to allow mutations
// in `fn` but not suffer from them, so iteration
// keeps normally.
array = Array.prototype.slice.call(array,0);
for(var i = 0, len = array.length; i < len; i++) {
function zeroRight(i) {
var j = 1,
k = i;
while(k > 10) {
j *= 10;
k = parseInt(k/10);
}
return k*j;
@edygar
edygar / .jshintrc
Created October 16, 2014 17:48
JSHintrc
{
// -----------------
// --------------------------------------------------------------------
// JSHint Configuration, Strict Edition
// --------------------------------------------------------------------
//
// This is a options template for [JSHint][1], using [JSHint example][2]
// and [Ory Band's example][3] as basis and setting config values to
// be most strict:
//
@edygar
edygar / getSubdirs.js
Last active August 29, 2015 14:04
Get subdirectories asynchronously
var fs = require('fs');
module.exports = function getSubDirectories( dir )
{
var deferred = new Promise();
var dirs = [], count = 0;
fs.readdir(dir, function(err, files)
{
if (err) deferred.error(err);