Skip to content

Instantly share code, notes, and snippets.

View selfish's full-sized avatar

selfish

View GitHub Profile
@selfish
selfish / WebStorm.bat
Last active March 16, 2018 21:20
Add context menu to Windows to open file/folder in WebStorm
@ECHO OFF
::Change WebStormPath to whatever suits your system then right-click and 'run as administrator'.
SET WebStormPath=C:\Program Files (x86)\JetBrains\WebStorm 8.0.2\bin\WebStorm64.exe
ECHO Adding file entries
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in WebStorm" /t REG_SZ /v "" /d "Open in WebStorm" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in WebStorm" /t REG_EXPAND_SZ /v "Icon" /d "%WebStormPath%,0" /f
@selfish
selfish / ListPackages.js
Last active April 30, 2016 23:40
List all NPM dependencies in project, recursively
var _ = require('lodash');
var j2csv = require('json2csv');
var cp = require("child_process");
var fs = require('fs');
/* Consts: */
var showErrors = false; // Show errors in console flag
var listCmd = 'npm list --long --json'; // npm list command
var maxBuffer = 1024 * 1000 * 10; // 10 MB. // cp maxBuffer
var cwd = require('path').dirname(require.main.filename); // Current working directory
@selfish
selfish / DeleteDups.mysql
Created November 15, 2015 16:07
Delete duplicates MySQL table, leaving one row for each duplicate group
DELETE `t1`
FROM `table` `t1`
INNER JOIN `table` `t2`
ON `t1`.`dup_col1` = `t2`.`dup_col1`
AND `t1`.`dup_col2` = `t2`.`dup_col2`
# AND...
WHERE `t1`.`primary_key` > `t2`.`primary_key`
@selfish
selfish / Backdate.bat
Created December 1, 2015 11:14
Set computer date to older date before launching app.
SET BackupDate=%date:~4%
DATE 28/02/2000
timeout 1
START "" "C:\Program Files\app\app.exe"
timeout 2
DATE %BackupDate%
@selfish
selfish / identity
Last active May 25, 2020 00:48
Spreadsheets relative indirect.
=SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","") & ROW() // Current cell path (i.e. A5)
=INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(),4),"1","") & ROW()) // Current cell content.
@selfish
selfish / consoleStyling.js
Last active June 28, 2016 12:23
Chrome console styling
// For some reason space is required after %c. Second parameter is any css.
console.log("%c This will be formatted", "color: #FAC66E; background-color: #2B2B2B; font-size: medium");
console.log(`%c This will be ${}`, "color: #FAC66E; background-color: #2B2B2B; font-size: medium");
@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:
@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 / 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 / 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