Skip to content

Instantly share code, notes, and snippets.

View Colorfulstan's full-sized avatar

Jonas Krispin Colorfulstan

View GitHub Profile
console.log('Don\'t nest promises with catch without knowing what you are doing!');
new Promise(function(resolve1, reject1){
reject1('This is fine');
})
new Promise(function(resolve2, reject2){
return new Promise(function(resolve2Inner, reject2Inner){
reject2Inner('This is also fine');
})
@Colorfulstan
Colorfulstan / unix_tar-logs.sh
Last active June 16, 2016 09:12
Create tar for logs (or files in general) with previous month in filename on Ubuntu / Linux / Unix And delete those files afterwards
DATESTAMP="$(date -d "1 month ago" +"%Y-%m")"
FILESPEC="*${DATESTAMP}*.log"
tar cvzf "${DATESTAMP}.tar.gz" $FILESPEC && rm ${FILESPEC}
@Colorfulstan
Colorfulstan / js-get-fn-name.js
Created May 4, 2016 13:47 — forked from dfkaye/js-get-fn-name.js
get a javascript function name
function getFnName(fn) {
var f = typeof fn == 'function';
var s = f && ((fn.name && ['', fn.name]) || fn.toString().match(/function ([^\(]+)/));
return (!f && 'not a function') || (s && s[1] || 'anonymous');
}
console.log(getFnName(String)); // 'String'
console.log(getFnName(function test(){})); // 'test'
console.log(getFnName(function (){})); // 'anonymous'
(function () {
var root = $(document.getElementsByTagName('body'));
var watchers = [];
var f = function (element) {
if (element.data().hasOwnProperty('$scope')) {
angular.forEach(element.data().$scope.$$watchers, function (watcher) {
watchers.push(watcher);
});
}
(function loop(sum, stop) {
if (sum < stop) {
return Promise.delay(250).then(() => {
sum++;
console.log(sum);
return loop(sum, stop);
});
}
})(0, 10).then(() => console.log('Done'))
@Colorfulstan
Colorfulstan / new_gist_file_0
Last active April 4, 2016 14:36
https://github.com/paquettg/leaguewrap/issues/110#issuecomment-204030766 paquettg/leaguewrap - GuzzleHttp ssl issue solution comment by inve1951
i lovaed it by placing the crt file from https://github.com/bagder/ca-bundle into php's directory and setting this line in php.ini:
openssl.cafile="full/path/to/ca-bundle.crt"
@Colorfulstan
Colorfulstan / javascript_operators.js
Created March 25, 2016 11:27
strange javascript operators from npm repeat-string >>= and &
//while (max > res.length && num > 0) {
if (num & 1) { // 1 if num is odd
// res += str;
}
num >>= 1; // halfs num to an integer (rounded down)
// if (!num) break;
// str += str;
//{
var keyPressed;
if (charCode == 8) keyPressed = "backspace"; // backspace
if (charCode == 9) keyPressed = "tab"; // tab
if (charCode == 13) keyPressed = "enter"; // enter
if (charCode == 16) keyPressed = "shift"; // shift
if (charCode == 17) keyPressed = "ctrl"; // ctrl
if (charCode == 18) keyPressed = "alt"; // alt
if (charCode == 19) keyPressed = "pause/break"; // pause/break
if (charCode == 20) keyPressed = "caps lock"; // caps lock
if (charCode == 27) keyPressed = "escape"; // escape
// names of known key codes (0-255)
var keyboardMap = [
"", // [0]
"", // [1]
"", // [2]
"CANCEL", // [3]
"", // [4]
"", // [5]
"HELP", // [6]
justify-content
align-items
flex-direction
order
align-self
flex-wrap
flex-flow
align-content