Skip to content

Instantly share code, notes, and snippets.

Avatar

Rocco Musolino roccomuso

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am roccomuso on github.
  • I am roccomuso (https://keybase.io/roccomuso) on keybase.
  • I have a public key ASDYVzLuaGmRCGjHViw8SM3gNsZmntfh7GDM8VYJ71lVawo

To claim this, I am signing this object:

@roccomuso
roccomuso / streamloop.js
Created Sep 3, 2018
Stream a buffer in loop.
View streamloop.js
const {isBuffer} = Buffer
const {Readable} = require('readable-stream')
class StreamLoop extends Readable {
constructor(data, options = {}) {
if (!isBuffer(data)) throw new Error('data must be a Buffer')
super(options) // Readable opts
this.data = data
this.length = data.byteLength
this.offset = 0
@roccomuso
roccomuso / update_repos.sh
Last active Oct 29, 2018
Update all git repository under a given directory, maxdepth 1.
View update_repos.sh
#!/bin/bash
# store the current dir
CUR_DIR=$(pwd)
# Let the person running the script know what's going on.
echo -e "\n[Pulling in latest changes for all repositories...]"
# Find all git repositories and update it to the master latest revision
for i in $(find ./* -maxdepth 1 -name ".git" | cut -c 3-); do
@roccomuso
roccomuso / Interactive-SSH-Client.js
Created Apr 20, 2017
SSH Interactive shell session in Node.js
View Interactive-SSH-Client.js
var Client = require('ssh2').Client;
var readline = require('readline')
var conn = new Client();
conn.on('ready', function() {
console.log('Client :: ready');
conn.shell(function(err, stream) {
if (err) throw err;
// create readline interface
var rl = readline.createInterface(process.stdin, process.stdout)
@roccomuso
roccomuso / index.html
Last active Apr 10, 2018
p2p-graph esnextbin sketch
View index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
<style>
body{
background-color: #7f7a7a;
};
@roccomuso
roccomuso / Client.js
Last active Oct 8, 2020
Node.js remote shell example
View Client.js
var net = require('net')
var readline = require('readline')
/**
* @class Client
* @param host {String} the host
* @param post {Integer} the port
*/
function Client (host, port) {
this.host = host
View debug.js
var path = require('path');
var config = require('config');
var chalk = require('chalk');
/*
*
* DEBUG wrapper to enhance the debug module features. Include this wrapper into your projects to enable debug from a config file and make the files use the global namespace and their name.
* Use it along with the 'config' module. The provides at least this configuration:
* {namespace: "projectName", debug: true}
*
@roccomuso
roccomuso / log-rotation.js
Last active Oct 29, 2018
stream and save stdout on log files. This snippet also manage automatic deletion for files older than X days.
View log-rotation.js
#!/usr/bin/env node
/*
Don't forget to:
$ chmod 755 log-rotation.js
$ mkdir logs
Then you can save any generic stdout on logs piping it with log-roation.js:
$ node whatever.js | ./log-rotation.js
*/
@roccomuso
roccomuso / index.html
Last active Nov 5, 2015
Modular Javascript - How to create javascript modules and use event handling. Inspired by: https://www.youtube.com/playlist?list=PLoYCgNOIyGABs-wDaaxChu82q_xQgUb4f
View index.html
<html>
<head>
<title>Modules in JS</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.1.3/mustache.min.js"></script>
@roccomuso
roccomuso / oop in javascript.js
Last active Apr 5, 2017
Prototypal Pattern vs Classical OOP in JS.js
View oop in javascript.js
var human = {
species: "human",
create: function(values) {
var instance = Object.create(this);
Object.keys(values).forEach(function(key) {
instance[key] = values[key];
});
return instance;
},
saySpecies: function() {
You can’t perform that action at this time.