Skip to content

Instantly share code, notes, and snippets.

View selfish's full-sized avatar

selfish

View GitHub Profile
@selfish
selfish / md5.js
Last active December 20, 2017 15:04
Simple MD5 hash in your Node.js application. Not recommended for security.
var crypto = require('crypto');
var data = "whatever";
var hashedValue = crypto.createHash('md5').update(data).digest("hex");
@selfish
selfish / uuid.js
Created May 1, 2016 16:46
Javascript One-liner non-compliant UUID
// Source: https://gist.github.com/jed/982883
// On the fly:
(()=>([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,a=>(a^Math.random()*16>>a/4).toString(16)))()
// Or define as named function:
function a(){
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,a=>(a^Math.random()*16>>a/4).toString(16));
}
@selfish
selfish / hidePs.bat
Created May 1, 2016 16:32
Start Powershell from command-line in hidden mode
:: To start any powershell command on hidden mode, use:
powershell -windowstyle hidden <command>
@selfish
selfish / CMDAdminHere.reg
Created May 1, 2016 15:07
Add Admin CMD Here to contect menu on Windows Folder / Directory / Drive
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\Directory\shell\runas]
[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Open command window here as Administrator"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""
@selfish
selfish / ad-hoc.bat
Created April 30, 2016 23:51
Create ad-hoc network in Windows 10
:: Create ad-hoc network in Windows via cmd:
netsh wlan set hostednetwork mode=allow ssid=<network name> key=<password>
netsh wlan start hostednetwork
@selfish
selfish / db.js
Last active April 30, 2016 23:16
Node.js simple MySQL DB driver
// Require libraries:
const _ = require('lodash');
const mysql = require('mysql');
// Load configuration for DB server:
var config = require('./config');
// Create DB connection object:
var conn = mysql.createConnection(config.db);
@selfish
selfish / errors.js
Created April 29, 2016 15:09
Express.js Error Handling
/**
* Module dependencies.
*/
var express = require('../../');
var app = module.exports = express();
var logger = require('morgan');
var silent = 'test' == process.env.NODE_ENV;
// general config
@selfish
selfish / AddRemoveStoreApp.ps1
Last active December 20, 2017 13:56
Add and Remove windows store apps from Powershell/CMD
# To hide the console, see:
# https://gist.github.com/NitaiPerez/6d665465e0a6e7b63b21ce7e57fbf0cc
# Sideload windows store app using .appxbundle file:
# Enable sideload apps in settings ().
Add-AppxPackage <app name>.appxbundle
#Remove package:
Remove-AppxPackage -package <package name>
@selfish
selfish / cache.js
Last active April 30, 2016 23:21
Google Apps Script Cache Util. Will cache values for 6 hours.
// Comfotability util for easy caching using Apps Script DocumentCache.
// Uses md5 for cache keys.
// See: https://developers.google.com/apps-script/reference/cache/cache
var CACHE_INTERVAL = 21600;
var docCache = CacheService.getDocumentCache();
function cacheSet(key, val){
return dcache.put(md5(key), JSON.stringify(val), CACHE_INTERVAL); // Max is: 21600 = 6hours
@selfish
selfish / angularService.js
Last active April 30, 2016 23:27
Angular Debugging via console; Import angular service / $rootScope to console.
// Use Angular service in console:
// clientDetails service (get method):
angular.element(document.body).injector().get('clientDetails').get();
// configAPI service (set method):
angular.element(document.body).injector().get('configAPI').set();
// Also works with var:
var configAPIService = angular.element(document.body).injector().get('configAPI');
configAPIService.set();
// View $rootScope in console: