Skip to content

Instantly share code, notes, and snippets.

View roccomuso's full-sized avatar

Rocco Musolino roccomuso

View GitHub Profile
@pulsar256
pulsar256 / wifiProbeRequestSniffer.js
Last active February 6, 2018 20:22
wifi probe request monitoring in node.js
var pcap=require('pcap');
pcap.createSession("mon0", '(type mgt) and (type mgt subtype probe-req )').
on('packet', function (raw_packet) {
with(pcap.decode.packet(raw_packet).link.ieee802_11Frame)
if (type == 0 && subType == 4)
console.log("Probe request",shost, "-> ",bssid);
}
);
@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;
};
@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 / 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
*/
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')
@TooTallNate
TooTallNate / mp3player.js
Created October 24, 2012 17:42
node.js command line MP3 player in 9 lines of code!
var fs = require('fs');
var lame = require('lame');
var Speaker = require('speaker');
fs.createReadStream(process.argv[2])
.pipe(new lame.Decoder())
.on('format', function (format) {
this.pipe(new Speaker(format));
});
@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());
@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');
});
})();
@chris-rock
chris-rock / crypto-stream.js
Last active October 6, 2022 18:38
Encrypt and decrypt streams
// Part of https://github.com/chris-rock/node-crypto-examples
// Nodejs encryption of buffers
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'd6F3Efeq';
var fs = require('fs');
var zlib = require('zlib');
@smeranda
smeranda / facebook_like-box_responsive.css
Created May 1, 2012 20:37
Flexible width layout for Facebook Like Box/Activity Stream to use in Responsive Designs
/*
Make the Facebook Like box responsive (fluid width)
https://developers.facebook.com/docs/reference/plugins/like-box/
*/
/* This element holds injected scripts inside iframes that in some cases may stretch layouts. So, we're just hiding it. */
#fb-root {
display: none;
}