Skip to content

Instantly share code, notes, and snippets.

@roninhack
roninhack / gist:70ea0b7b2692efe2101f90ecf4b2ae69
Created April 27, 2017 09:13 — forked from aku/gist:5466527
Example of Socket.io proxy config for NGINX (version 1.3.13+)
upstream backend {
server 127.0.0.1:3000;
}
server {
listen 80;
access_log /var/log/nginx/yoursite.access.log;
error_log /var/log/nginx/yoursite.error.log;
@roninhack
roninhack / node-ubuntu-upstart-service.md
Created May 2, 2017 15:19 — forked from willrstern/node-ubuntu-upstart-service.md
Run Node.js App as Ubuntu Upstart Service

###The Issue With Forever Forever is great for running node services, with a minor setback: the word "forever" doesn't apply to system reboots.

###The solution, run node apps as a system service logged in as root

vim /etc/init/node-app.conf

Contents for node-app.conf

@roninhack
roninhack / node-ubuntu-upstart-service.md
Last active May 2, 2017 15:32 — forked from willrstern/node-ubuntu-upstart-service.md
Run Node.js App as Ubuntu Upstart Service

###The Issue With Forever Forever is great for running node services, with a minor setback: the word "forever" doesn't apply to system reboots.

###The solution, run node apps as a system service logged in as root

vim /etc/init/node-app.conf

Contents for node-app.conf

var attempts = 1;
function createWebSocket () {
var connection = new WebSocket();
connection.onopen = function () {
// reset the tries back to 1 since we have a new connection opened.
attempts = 1;
// ...Your app's logic...
@roninhack
roninhack / index.html
Created May 29, 2017 07:32 — forked from mandulaj/index.html
Webssh
<!doctype html>
<html>
<head>
<title>SSH Client</title>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.5/socket.io.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
@roninhack
roninhack / height.java
Created June 14, 2017 22:55 — forked from hamakn/height.java
Android: Get height of status, action, navigation bar (pixels)
// status bar height
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
// action bar height
int actionBarHeight = 0;
final TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes(
@roninhack
roninhack / height.java
Created June 14, 2017 22:55 — forked from hamakn/height.java
Android: Get height of status, action, navigation bar (pixels)
// status bar height
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
// action bar height
int actionBarHeight = 0;
final TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes(
@roninhack
roninhack / decrypt.js
Created August 17, 2017 03:33 — forked from mekicha/decrypt.js
Compress and encrypt the file. To decrypt, see decrypt.js
fs.createReadStream(file)
.pipe(crypto.createDecipher('aes192', 'a_secret'))
.pipe(zlib.createGunzip())
.pipe(reportProgress)
.pipe(fs.createWriteStream(file.slice(0, -3)))
.on('finish', () => console.log('Done'));
@roninhack
roninhack / walksync.js
Created August 17, 2017 04:13 — forked from kethinov/walksync.js
List all files in a directory in Node.js recursively in a synchronous fashion
// List all files in a directory in Node.js recursively in a synchronous fashion
var walkSync = function(dir, filelist) {
var fs = fs || require('fs'),
files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function(file) {
if (fs.statSync(dir + file).isDirectory()) {
filelist = walkSync(dir + file + '/', filelist);
}
else {
@roninhack
roninhack / crypto-buffer.js
Created August 17, 2017 07:08 — forked from chris-rock/crypto-buffer.js
Encrypt and decrypt buffers in nodejs
// Part of https://github.com/chris-rock/node-crypto-examples
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'd6F3Efeq';
function encrypt(buffer){
var cipher = crypto.createCipher(algorithm,password)
var crypted = Buffer.concat([cipher.update(buffer),cipher.final()]);
return crypted;