Skip to content

Instantly share code, notes, and snippets.

View pid's full-sized avatar

Sascha pid

  • Baden-Württemberg, Germany
View GitHub Profile
@pid
pid / process-shutdown.js
Created September 20, 2013 14:26
Controlling shutdown of your nodejs script (JavaScript)
process.once('SIGUSR2', function () {
gracefulShutdown(function () {
process.kill(process.pid, 'SIGUSR2');
})
});
@pid
pid / isSafeInteger.js
Created October 1, 2013 12:40
isSafeInteger - is Safe Integer
// http://www.2ality.com/2013/10/safe-integers.html
isSafeInteger = function(n) {
Number.MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
Number.MIN_SAFE_INTEGER = -Number.MAX_SAFE_INTEGER;
return (typeof n === 'number' &&
Math.round(n) === n &&
Number.MIN_SAFE_INTEGER <= n &&
n <= Number.MAX_SAFE_INTEGER);
};
@pid
pid / JavaScript-XPath.js
Created October 7, 2013 12:36
JavaScript-XPath 0.1.12
/* JavaScript-XPath 0.1.12
* (c) 2007 Cybozu Labs, Inc.
*
* JavaScript-XPath is freely distributable under the terms of an MIT-style license.
* For details, see the JavaScript-XPath web site: http://coderepos.org/share/wiki/JavaScript-XPath
*
/*--------------------------------------------------------------------------*/
@pid
pid / gist:6867228
Created October 7, 2013 12:40
exif remove metadata
exiftool -all= *.jpg
This removes all meta data from all files ending with the extension .jpg in the current folder, moving the originals to files with the additional extension "_original".
exiftool -overwrite_original -tagsfromfile *_original -make -model -exposuretime -aperturevalue -flash -iso -lens -focallength -orientation -datetimeoriginal *.jpg
This copies the specified meta data (Make, Model, Exposure, etc.) from the "backuped" _original files to those stripped clean of any data.
exiftool -all= *.jpg;exiftool -overwrite_original -tagsfromfile *_original -make -model -exposuretime -aperturevalue -flash -iso -lens -focallength -orientation -datetimeoriginal *.jpg
@pid
pid / gist:6867250
Created October 7, 2013 12:42
Decorator Javascript Design Pattern
function MacBook() {
this.cost = function() {
return 997;
};
this.screenSize = function() {
return 11.6;
};
}
//Decorator1
@pid
pid / gist:6867252
Created October 7, 2013 12:42
Factory Javascript Design Pattern
function Car(options) {
// some defaults
this.doors = options.doors || 4;
this.state = options.state || "brand new";
this.color = options.color || "silver";
}
function Truck(options) {
this.state = options.state || "used";
this.wheelSize = options.wheelSize || "large";
@pid
pid / gist:6867265
Created October 7, 2013 12:43
convert bytes to human readable size
/**
* convert bytes to human readable size
*
* @params int bytes
* @params int decimalPlaces, default=2
* @params boolean autoSize, default=false
* @return string
*/
function szxHumanSize(bytes, decimalPlaces, autoSize) {
if (typeof (decimalPlaces) == "undefined") decimalPlaces = 2;
@pid
pid / gist:6867427
Created October 7, 2013 12:51
Check YAML File
perl -MYAML -e 'YAML::LoadFile "tmp/config.yml";'
jQuery.fn.brightness = function() {
var bg_color, rgba, y;
bg_color = this.css('background-color');
if ((bg_color != null) && bg_color.length) {
rgba = bg_color.match(/^rgb(?:a)?\(([0-9]{1,3}),\s([0-9]{1,3}),\s([0-9]{1,3})(?:,\s)?([0-9]{1,3})?\)$/);
if (rgba != null) {
if (rgba[4] === '0') {
if (this.parent().length) return this.parent().brightness();
} else {
y = 2.99 * rgba[1] + 5.87 * rgba[2] + 1.14 * rgba[3];
@pid
pid / clipboard.js
Last active December 25, 2015 08:29
copy to clipboard in all browsers - tricky
function copyToClipboard(text) {
if (window.clipboardData && window.clipboardData.setData) {
window.clipboardData.setData('text', text);
} else {
window.prompt ("Copy to clipboard: Ctrl+C, Enter", text);
}
}