Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Code wins arguments

Alexander frontenddeveloping

:octocat:
Code wins arguments
View GitHub Profile
@frontenddeveloping
frontenddeveloping / array mergeAsNumber
Last active Aug 29, 2015
Array.prototype.mergeAsNumber example
View array mergeAsNumber
Array.prototype.mergeAsNumber = function (array) {
var sortFunction = function (a,b) {return a-b},
commonArray = this.concat(array).sort(sortFunction),
element,
suchNumberAnotherIndex;
for (var i = 0, l = commonArray.length; i<l; i++) {
element = commonArray[i];
suchNumberAnotherIndex = commonArray.indexOf(element, i+1);
while (suchNumberAnotherIndex > -1) {
@frontenddeveloping
frontenddeveloping / index.html
Created May 29, 2014
FileReader.prototype.readAsArrayBuffer vs FileReader.prototype.readAsDataUrl
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FileReader test</title>
</head>
<body>
<form action="">
<input type=file multiple accept="image/*"><br/>
<input type=submit value="Run test">
@frontenddeveloping
frontenddeveloping / dataUri2Blob.js
Created Jun 20, 2014
Conversion dataUri string to Blob
View dataUri2Blob.js
function dataUri2Blob (dataUri) {
var dataUriArr = dataUri.split(';base64,'),
imageType = dataUriArr[0].replace('data:', ''),
base64Str = dataUriArr[1],
BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder || window.MozBlobBuilder,
binaryString = window.atob(base64Str),
bytes,
arrayBuffer,
blob;
@frontenddeveloping
frontenddeveloping / async-javascript-loading.js
Last active Aug 29, 2015
Async javascript loading (with saving order).
View async-javascript-loading.js
/*
The main feature is script.async = false.
The async IDL attribute controls whether the element will execute asynchronously or not.
So if you will set async to false, scripts will load without blocking user i/o, but scripts will execute synchronously.
Support:
FF 4+
FF for Android All Versions
IE 10+ (starting with preview 2)
Chrome 12+
Chrome For Android All versions
View sw-example.js
var version = 'v2.0.24:';
var offlineFundamentals = [
'/',
'/offline/'
];
//Add core website files to cache during serviceworker installation
var updateStaticCache = function() {
return caches.open(version + 'fundamentals').then(function(cache) {
View jquery.leaks.js
/**
* Watcher leaks for jQuery
* RubaXa <trash@rubaxa.org>
* MIT Licensed.
*
* API:
* $.leaks.get();
* $.leaks.watch();
* $.leaks.unwatch();
* $.leaks.remove();
@frontenddeveloping
frontenddeveloping / gitclean.sh
Created Feb 15, 2016 — forked from ericelliott/gitclean.sh
gitclean.sh - cleans merged/stale branches from origin
View gitclean.sh
git remote prune origin
git branch -r --merged master | egrep -iv '(master|develop)' | sed 's/origin\///g' | xargs -n 1 git push --delete origin
@frontenddeveloping
frontenddeveloping / Fix Cygwin Issues with Ruby
Created Mar 15, 2016 — forked from mztriz/Fix Cygwin Issues with Ruby
No such file or directory — /cygdrive/c/Ruby193/bin/gem (LoadError)
View Fix Cygwin Issues with Ruby
Add the following to your .bashrc (change path as necessary):
alias ruby='/cygdrive/c/Ruby193/bin/ruby'
alias gem='/cygdrive/c/Ruby193/bin/gem.bat'
alias irb='/cygdrive/c/Ruby193/bin/irb.bat'
View devtools-perf-annotations-example.js
//@DevToolsPerfTest('my_super_fast_code')
Array(1e6).fill(1).map(() => Math.random())
//@DevToolsPerfTestEnd('my_super_fast_code', 5)
// if my code runs more than 5ms I want to get warining in console.
View deferred-es2015-class.js
const PENDING_STATE = 'pending';
const REJECTED_STATE = 'rejected';
const RESOLVED_STATE = 'resolved';
class Deferred {
static PENDING_STATE = PENDING_STATE;
static REJECTED_STATE = REJECTED_STATE;
static RESOLVED_STATE = RESOLVED_STATE;
constructor() {
let state = PENDING_STATE;