Skip to content

Instantly share code, notes, and snippets.

View selfish's full-sized avatar

selfish

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / un-gzip.bat
Last active December 20, 2017 13:57
Un-Gzip file with Unix utils on Windows
printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" |cat - metadata |gzip -dc %1 >> %1.json
rm %1
@selfish
selfish / finally.js
Last active April 30, 2016 23:23
Easy implementation of Promise Finally using native JS
Promise.prototype['finally'] = function finallyPolyfill(callback) {
var constructor = this.constructor;
return this.then(function(value) {
return constructor.resolve(callback()).then(function() {
return value;
});
}, function(reason) {
return constructor.resolve(callback()).then(function() {
throw reason;
@selfish
selfish / bluebird-promise-sequence.js
Created July 16, 2015 08:51
Bluebird Promise Sequences
var Promise = require('bluebird');
// waterfall
Promise.sequence = function (tasks) {
var current = Promise.cast();
for (var k = 0; k < tasks.length; ++k) {
current = current.then(tasks[k]);
}
return current;
};
//PSEUDOCODE!!
function fisher_yates_shuffle(items):
for(i in _.range(items.length)){
var randomIndex = random.randint(i, len(items)-1)
temp = items[randomIndex]
items[randomIndex] = items[i]
items[i] = temp
}
return items