Skip to content

Instantly share code, notes, and snippets.

View MaxXx1313's full-sized avatar

Maksim Chartkou MaxXx1313

View GitHub Profile
@MaxXx1313
MaxXx1313 / Promise.always.js
Last active June 14, 2017 16:25
Example of Promise.always() implementation
/**
* Synchronous version of Promise.always()
* @param {function(err:Error, data:any)} onResolveOrRejectFn
*/
Promise.prototype.always = function(onResolveOrRejectFn){
return this.catch(function(error){
onResolveOrRejectFn(error);
throw error;
}).then(function(result){
onResolveOrRejectFn(null, result);
@MaxXx1313
MaxXx1313 / jquery-ui.fix.js
Last active June 22, 2017 09:16
Fix memory leack for menu component and may be some other
/**
* Fix memory leack for menu component and may be some other
*/
$.Widget.prototype._classes = function( options ) {
var full = [];
var that = this;
options = $.extend( {
element: this.element,
classes: this.options.classes || {}
if (!Object.assign) {
Object.assign =
function (target) {
var from, to = Object(target), symbols;
for (var s = 1; s < arguments.length; s++) {
from = Object(arguments[s]);
for (var key in from) {
if (Object.prototype.hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
{
"header": {
"number": {
"low": 0,
"high": 0,
"unsigned": true
},
"previous_hash": "",
"data_hash": "223e57f14464047011a96d77eea75aa0296b25a10d50cdecf217948513644124"
},
// custom middleware: use res.promise() to send promise response
app.use((req,res,next)=>{
/*
Report error
You can use it in severqal ways:
- promise.catch() from promise
- res.error(new Error()) - pass any error object
- res.error({status:401, message:'alala'}) - pass any object
- res.error(401, 'alala') - pass code and message separately
@MaxXx1313
MaxXx1313 / git forward
Last active January 15, 2020 08:40
git forward <branch name> - fast-forward pointed branch to the current state
# add next line in ~/.gitconfig
[alias]
forward = !git tag _temp && git checkout $1 --quiet && git merge _temp --ff-only && git tag _temp -d && git status
mergeto = !bash -x -c 'ish=$(git status |grep -P \"(HEAD detached at|On branch)\" | grep -oP \"[^ ]+$\" ) && echo "$ish" && git checkout '"$1"' --quiet && git merge "$ish" --no-ff --no-edit && git status'
@MaxXx1313
MaxXx1313 / xpath.js
Last active March 17, 2019 18:35
Xpath operations with objects
"use strict";
/* global describe */
/* global it */
/* global require */
/* jshint esversion: 6 */
const assert = require('assert');
/**
*
@MaxXx1313
MaxXx1313 / $.fn.serializeObject
Last active January 29, 2018 17:06
jQuery serializeObject for a form
$.fn.serializeObject = function() {
return this.serializeArray().reduce(function(result, item){
result[item.name]=item.value;
return result;
}, {});
};
@MaxXx1313
MaxXx1313 / iso-8601.js
Last active May 18, 2018 08:53
ISO8601 string to Date
const assert = require('assert');
/**
* Parse string date representation into Date object
* input string - date in ISO format:
* * "2018-05-17T16:40:56"
* * "2018-05-17T16:40:56.303Z"
* * "2018-05-17T16:40:56.303+00:00"
@MaxXx1313
MaxXx1313 / git remove huge files.sh
Last active June 24, 2018 09:16
git remove file/folder from the history
git filter-branch \
--prune-empty -d /dev/shm/scratch \
--index-filter "git rm -rf --cached --ignore-unmatch oops.iso" \
--tag-name-filter cat \
-- --all