Skip to content

Instantly share code, notes, and snippets.

View maxvipon's full-sized avatar

Maxim Ponomarev maxvipon

View GitHub Profile
@maxvipon
maxvipon / git-filter-branch
Created November 5, 2014 07:17
Change commit author or email
git filter-branch --commit-filter \
'if [ "$GIT_AUTHOR_NAME" = "OldAuthor Name" ]; then \
export GIT_AUTHOR_NAME="Author Name";\
export GIT_AUTHOR_EMAIL=authorEmail@example.com;\
export GIT_COMMITTER_NAME="Commmiter Name";\
export GIT_COMMITTER_EMAIL=commiterEmail@example.com;\
fi;\
git commit-tree "$@"'
@maxvipon
maxvipon / parse_query
Created April 23, 2015 07:33
Deserialize URL query params
var args = location.search.substr(1)
.split('&')
.map(function (pair) {
pair = pair.split('=');
try {
pair[1] = pair[1] !== undefined ? decodeURIComponent(pair[1]) : true;
if (typeof pair[1] === 'string') {
pair[1] = pair[1].replace(/\+/g, ' ');
if (pair[1].indexOf(',') !== -1) {
pair[1] = pair[1].split(',');
@maxvipon
maxvipon / bench-number.js
Last active September 11, 2015 09:37
bench-number
const Benchmark = require('benchmark').Benchmark;
const suite = new Benchmark.Suite();
function uid() {
return 'xxx'.replace(/x/g, function(c) {
return Math.floor(Math.random()*10);
});
}
const count = 100;
@maxvipon
maxvipon / random-item.js
Created September 11, 2015 09:41
Random item from Array
items[ Math.floor(Math.random() * items.length) ]
items[ ~~(Math.random() * items.length) ]
items[ Math.random() * items.length >>> 0 ]
@maxvipon
maxvipon / bench-hash.js
Created September 11, 2015 09:38
bench-hash
const Benchmark = require('benchmark').Benchmark;
const siphash = require('siphash');
const murmur = require('murmur');
const HASH_KEY = siphash['string16_to_key']('A054ED26FF2BC196');
const suite = new Benchmark.Suite('Generate Hash');
var hash;
@maxvipon
maxvipon / ie-detect.js
Last active October 11, 2015 11:27 — forked from padolsey/gist:527683
JavaScript: Detecting IE
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@maxvipon
maxvipon / jquery-pubsub.js
Last active October 11, 2015 11:27 — forked from TexRx/gist:2010435
JavaScript: PubSub [jquery]
/* @paul_irish Pub/Sub
* Works in modern browsers + IE9
* Use Modernizr ployfill for function.bind */
(function($) {
var o = $({});
$.subscribe = o.on.bind(o);
$.unsubscribe = o.off.bind(o);
$.publish = o.trigger.bind(o);
}(jQuery));
@maxvipon
maxvipon / gist:3851843
Created October 8, 2012 10:25
CSS: Text indent (font crushing)
.ir {
border: 0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;
}
@maxvipon
maxvipon / gist:3851912
Created October 8, 2012 10:44
CSS: Text indent (positive text)
.ir {
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
@maxvipon
maxvipon / rus_to_translit
Last active October 11, 2015 13:17
JavaScript: RusToTranslit
function RusToTranslit( text ) {
return text.replace(/([а-яё])|([\s_-])|([^a-z\d])/gi,
function(all, ch, space, words, i) {
if (space || words) {
return space ? '-' : '';
}
var code = ch.charCodeAt(0),
next = text.charAt(i+1),
index = code == 1025 || code == 1105 ? 0 : code > 1071 ? code - 1071 : code - 1039,