Skip to content

Instantly share code, notes, and snippets.

View lifeofcoding's full-sized avatar
💭
4RwPdnGala2QfMua

Jimmy Rousseau lifeofcoding

💭
4RwPdnGala2QfMua
View GitHub Profile
// Create Base64 Object
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r
@lifeofcoding
lifeofcoding / skeleton-daemon.sh
Created September 12, 2018 09:26 — forked from shawnrice/skeleton-daemon.sh
A template to write a quick daemon as a bash script
#!/bin/sh
# This is a skeleton of a bash daemon. To use for yourself, just set the
# daemonName variable and then enter in the commands to run in the doCommands
# function. Modify the variables just below to fit your preference.
daemonName="DAEMON-NAME"
pidDir="."
pidFile="$pidDir/$daemonName.pid"
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@lifeofcoding
lifeofcoding / .eslintrc.js
Last active September 13, 2018 09:26
ESLint Configuration
// $ cat .eslintrc.js
module.exports = {
'env': {
'browser': true,
'meteor': true,
'node': true,
'es6': true
},
'extends': 'eslint:recommended',
'parserOptions': {
@lifeofcoding
lifeofcoding / .eslintrc
Created September 13, 2018 09:40 — forked from cletusw/.eslintrc
ESLint Reset - A starter .eslintrc file that resets all rules to off and includes a description of what each rule does. From here, enable the rules that you care about by changing the 0 to a 1 or 2. 1 means warning (will not affect exit code) and 2 means error (will affect exit code).
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
#!/bin/bash
# ==============================================================
# CPU limit daemon - set PID's max. percentage CPU consumptions
# ==============================================================
# Variables
CPU_LIMIT=20 # Maximum percentage CPU consumption by each PID
DAEMON_INTERVAL=3 # Daemon check interval in seconds
BLACK_PROCESSES_LIST= # Limit only processes defined in this variable. If variable is empty (default) all violating processes are limited.
WHITE_PROCESSES_LIST= # Limit all processes except processes defined in this variable. If variable is empty (default) all violating processes are limited.
#!/bin/bash
# CPU limit of a process
#
# Variables
CPU_LIMIT=50 # Maximum percentage CPU consumption by each PID
# NOTE: If your machine has one processor you can limit the percentage from 0% to 100%, which means that if you set for example 50%, your process cannot use more than 500 ms of cpu time for each second. But if your machine has four processors, percentage may vary from 0% to 400%, so setting the limit to 200% means to use no more than half of the available power.
DAEMON_INTERVAL=3 # Daemon check interval in seconds
BLACKLIST="atom|chrome" # Processes to be limited. If variable is empty (default) all violating processes are limited.
@lifeofcoding
lifeofcoding / api.proxy.server.js
Created January 16, 2019 05:01 — forked from davemo/api.proxy.server.js
A simple express.js server with a proxy that intercepts all requests with /api/ and proxies them to localhost:3000
var express = require('express'),
httpProxy = require('http-proxy'),
app = express();
var proxy = new httpProxy.RoutingProxy();
function apiProxy(host, port) {
return function(req, res, next) {
if(req.url.match(new RegExp('^\/api\/'))) {
proxy.proxyRequest(req, res, {host: host, port: port});
@lifeofcoding
lifeofcoding / gist:22fba9e64fb181251a6e884ac9b30045
Created January 16, 2019 05:01 — forked from axefrog/gist:3353609
Node.js HTTP/HTTPS double forward proxy with two-stage authorization
/*
HTTP/HTTPS Forward Proxy
------------------------
The purpose of this proxy is to manage a set of third party proxies
internally, routing incoming requests through those proxies and
rotating which remote proxies are in use periodically as requests come
through, and without exposing the proxy credentials to the originating
client. Rate limiting will later be implemented internally so that if
the remote proxies have all been utilised too heavily, a "rate limit
exceeded" message will be returned to the client.
@lifeofcoding
lifeofcoding / externalip
Created March 30, 2019 09:59
get machine external ip
#!/bin/sh
# get external IP address
# used for outgoing Internet connections
# see: https://github.com/rsp/scripts/blob/master/externalip.md
case "$1" in
""|dns) dig +short myip.opendns.com @resolver1.opendns.com ;;
http) curl -s http://whatismyip.akamai.com/ && echo ;;
https) curl -s https://4.ifcfg.me/ ;;