Skip to content

Instantly share code, notes, and snippets.

View selfish's full-sized avatar

selfish

View GitHub Profile
@selfish
selfish / tables-by-column.mysql
Last active December 20, 2017 14:09
Find MySQL Tables containing a column by name
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ('columnA','ColumnB')
AND TABLE_SCHEMA='YourDatabase';
-- OR:
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%columnA%'
@selfish
selfish / lookupXML.vbs
Created August 13, 2014 15:47
VBS Lookup files in folders. (Execute: cscript lookupXML.vbs)
On Error Resume Next
Dim fso, StdOut, folders, files, ext
folders = Array(_
"c:\",_
"c:\users"_
)
@selfish
selfish / DeleteSched.bat
Last active April 30, 2016 23:41
Remove all windows scheduled tasks cotaining string 'stringToRemove'
FOR /f %%i in ('schtasks /query ^| FINDSTR stringToRemove') do schtasks /Delete /TN "%%i" /F
@selfish
selfish / isOdd.js
Last active November 5, 2015 17:54
Bitwise Operations Make life easier in JS:
function isOdd(number) {
return !!(number & 1);
}
isOdd(1); // true, 1 is odd
isOdd(2); // false, 2 is not odd
isOdd(357); // true, 357 is odd
@selfish
selfish / kill.mysql
Last active November 5, 2015 18:00
Investigate performance and kill sleeping connections
SELECT *
FROM information_schema.processlist;
SELECT concat('KILL ',id,';')
FROM information_schema.processlist
WHERE COMMAND = 'Sleep';
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
//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
@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;
};
@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 / 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