Skip to content

Instantly share code, notes, and snippets.

var redirect = (function () {
var isFirefox = false;
var browser = window.navigator.userAgent;
var location = window.location;
var fixFirefoxHistory = function () {
var hash = window.location.hash;
var timestamp = Date.now();
if (isFirefox) {
getCleanTodayTimestamp = function () {
return new Date().setHours(0, 0, 0, 0);
}
/**
* Get position of given element in array or given sub-string in string
*
* @raram {String|Array} source
* @param {String|Number|Boolean} term
*
* @return {Number} Position of term in source or -1
*/
var indexOf = (function () {
var NEGATIVE = -1;
var formatThousands = function (input, separator) {
var output = [];
input = String(input).split('').reverse();
if (separator === void 0 || separator == null) {
separator = ',';
}
for (var i = 0, len = input.length, lastIndex = len - 1; i < len; i++) {
@tytskyi
tytskyi / inheritance.js
Last active August 29, 2015 14:11
Quickstart jQuery plugin boilerplate.
// Example of creation new plugin based on this one.
(function ($) {
var pluginName = 'myBoilerplate';
var parent = $.fn.boilerplate;
var defaults = {};
var Constructor = function (element, options) {
this.element = element;
this._settings = $.extend({}, defaults, options);
@tytskyi
tytskyi / choco_install.bat
Created December 9, 2014 22:34
Install bunch of cool windows programs by 1 command.
:: archivers
choco install 7zip.install
:: messaging/collaboration
choco install skype
choco install teamviewer
:: iso/usb
choco install cdburnerxp
choco install poweriso
// Easy way to parse raw URL without regex.
var locator = document.createElement('a');
locator.href = 'http://google.com/?search=true&other=isnt#anchor'
console.log(locator.protocol);
console.log(locator.host);
console.log(locator.search);
console.log(locator.hash);
var createObject = (function () {
function Object() {}
return function createObjectF(obj) {
Object.prototype = obj;
obj = new Object();
Object.prototype = null;
return obj;
}
}());
var gulp = require('gulp')
var concat = require('gulp-concat')
var sourcemaps = require('gulp-sourcemaps')
var uglify = require('gulp-uglify')
var ngAnnotate = require('gulp-ng-annotate')
gulp.task('js', function () {
gulp.src(['src/**/module.js', 'src/**/*.js'])
.pipe(sourcemaps.init())
.pipe(concat('app.js'))
@tytskyi
tytskyi / 2x-audio.js
Created September 7, 2016 10:18
Listen HTML5 audio book 2x faster.
var __$$play = HTMLAudioElement.prototype.play;
HTMLAudioElement.prototype.play = function () {
this.playbackRate = 2;
return __$$play.apply(this, arguments);
};