Skip to content

Instantly share code, notes, and snippets.

View roccomuso's full-sized avatar

Rocco Musolino roccomuso

View GitHub Profile
const log = new Proxy({}, {
get: (_, colour) => function() {
console.log(`%c ${[].slice.call(arguments).join(' ')}`, `color: ${colour}`)
}
})
// example
log.tomato('I am tomato')
log.chocolate('I am chocolate')
log.cornflowerblue('I am cornflowerblue')
@wilsonsilva
wilsonsilva / undo_last_commit.sh
Created June 21, 2017 15:47
Undo last commit but keep changes
# https://stackoverflow.com/a/44672195/3013522
git reset --soft HEAD~1
@roccomuso
roccomuso / update_repos.sh
Last active October 29, 2018 23:51
Update all git repository under a given directory, maxdepth 1.
#!/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 April 20, 2017 13:56
SSH Interactive shell session in Node.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)
@chrvadala
chrvadala / server.js
Last active March 27, 2020 21:01
node.js api webserver
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(cors());
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
@roccomuso
roccomuso / index.html
Last active April 10, 2018 18:44
p2p-graph esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
<style>
body{
background-color: #7f7a7a;
};
@NoMan2000
NoMan2000 / openssl.md
Last active March 14, 2024 17:31 — forked from zhiguangwang/openssl.md
Common OpenSSL Commands with Keys and Certificates

Common OpenSSL Commands with Keys and Certificates

SSL Info

Generate RSA private key with certificate in a single command

openssl req -x509 -newkey rsa:4096 -sha256 -keyout example.key -out example.crt -subj "/CN=example.com" -days 3650 -passout pass:foobar

Generate Certificate Signing Request (CSR) from private key with passphrase

openssl x509 -x509toreq -in example.crt -out example.csr -signkey example.key -passin pass:foobar

@roccomuso
roccomuso / Client.js
Last active February 19, 2023 21:19
Node.js remote shell example
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
@roccomuso
roccomuso / log-rotation.js
Last active October 29, 2018 23:53
stream and save stdout on log files. This snippet also manage automatic deletion for files older than X days.
#!/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
*/
@Bradcomp
Bradcomp / toggle-menu.js
Created September 3, 2016 00:08
Toggles the .is-active class for a hamburger menu
(function() {
var burger = document.querySelector('.nav-toggle');
var menu = document.querySelector('.nav-menu');
burger.addEventListener('click', function() {
burger.classList.toggle('is-active');
menu.classList.toggle('is-active');
});
})();