Skip to content

Instantly share code, notes, and snippets.

Avatar
🔥
#BLM

Dan Levy justsml

🔥
#BLM
View GitHub Profile
@justsml
justsml / inheritance-nodejs-style.js
Last active Aug 29, 2015
Browserify and JS `Object.Prototype` Magic - this is Browser && || Server code!!!!
View inheritance-nodejs-style.js
var inherits = require('inherits'),
EventEmitter = require('events').EventEmitter;
function BaseController($scope, $http, $location) {
if (!(this instanceof BaseController)) { return new BaseController.apply(null, [].slice(arguments)); }
$scope.load = this.load;
this.$scope = $scope;
this.$location = $location;
this.$http = $http;
}
View patch-object-extend.js
function extend(obj, src) {
Object.getOwnPropertyNames(src)
.forEach( (propName) => Object.defineProperty(obj, propName, Object.getOwnPropertyDescriptor(src, propName)) );
return obj;
}
@justsml
justsml / mongodb-backup.sh
Last active Aug 29, 2015
Daily MongoDB Backup Script, Requires 7z for compression + encryption
View mongodb-backup.sh
#! /bin/sh
BACKUP_PATH=/data/backups
# IMPORTANT: SET BACKUP PASSWORD, $USER IS A PLACEHOLDER
PASSWORD=$(USER)
# Add database name, or set to $1 to use command line parameters
DATABASE_NAME=$1
BACKUP_TAG="mongodb-"$(DATABASE_NAME)"-"$(date +%F)
mongodump -d $(DATABASE_NAME) -o $(BACKUP_PATH)/$(BACKUP_TAG)
7z a -r -mx=1 -p$(PASSWORD) $(BACKUP_PATH)/$(BACKUP_TAG).7z $(BACKUP_PATH)/$(BACKUP_TAG)/$(COLLECTION)/*.*son
View list-docker-instance-ips.sh
#!/bin/bash
$DETECTED_DOMAIN=$(dnsdomainname)
for CID in `docker ps -q`; do
IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $CID)
NAME=$(docker inspect --format '{{ .Config.Hostname }}' $CID)
echo "$IP $NAME $NAME.$DETECTED_DOMAIN"
done
@justsml
justsml / index.js
Last active Aug 29, 2015
sum-sub-sequence-challenge! This simplified version has notable enhancements missing like, using a hashtable, memoization, and an optimal sort or partial-sort step.
View index.js
module.exports = function(numArray) {
var args = [].slice.call(arguments);
if ( args.length < 2 ) { throw new Error('Invalid parameters'); }
if ( !Array.isArray(numArray) ) { throw new Error('Invalid Input, Must be Array'); }
var findSums = args.slice(1, args.length);
// unpack sums if array, or use arguments[1:]
findSums = Array.isArray(findSums[0]) ? findSums[0] : findSums;
return numArray.some(checkSums, findSums);
}
@justsml
justsml / docker-clone-backup-example.sh
Created Aug 3, 2015
Clone/Backup Docker - Live Stream over SSH pipe !!!!
View docker-clone-backup-example.sh
# Save the built CONTAINER (named myapp), stream via ssh
docker save myapp | bzip2 | pv | ssh root@vhost2 'bunzip2 | docker load'
# Clone a running INSTANCE, stream via ssh
docker export web0 | bzip2 | pv | ssh root@vhost2 'bunzip2 | docker import web0'
View HTTP_STATUS_DICT.js
// Credit/Reference: http://www.lowendguide.com/3/webservers/http-status-codes-cheat-sheet/
var HTTP_STATUS_DICT = module.exports = {
/*## HTTP Successful Codes (2xx)*/
"200": "OK",
"201": "Created",
"202": "Accepted",
"203": "Non-Authoritative Information 1.1",
"204": "No Content",
"205": "Reset Content",
@justsml
justsml / simple-geocoder-wrapper.js
Created Aug 7, 2015
Simple async remote service wrapper. ToDo: Needs to validate & parse the remote JSON response
View simple-geocoder-wrapper.js
var API_KEY = '';// <<-- '<__YOUR_KEY__HERE__>';
module.exports = function _geocode(address, callback) {
require('request')
.get('https://maps.googleapis.com/maps/api/geocode/json?region=us&address=' + encodeURIComponent(address) + '&key=' + encodeURIComponent(API_KEY))
.on('response', function(response) {
callback(null, response);
}).on('error', function(err) {
callback(err);
});
View dashboard-tiles.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
<link href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css' rel='stylesheet' type='text/css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js'></script>
<script>
'use strict'
@justsml
justsml / rkhunter-debian-setup
Last active Dec 3, 2015
rkhunter debian installer
View rkhunter-debian-setup
#!/bin/bash
apt-get install -y unhide lsof file sudo
sleep 2s
cd ~/
wget http://downloads.sourceforge.net/project/rkhunter/rkhunter/1.4.2/rkhunter-1.4.2.tar.gz
tar xzvf rkhunter-1.4.2.tar.gz
cd rkhunter-1.4.2
sudo ./installer.sh --install
rkhunter --update
rkhunter --propupd
You can’t perform that action at this time.