Skip to content

Instantly share code, notes, and snippets.

View frontenddeveloping's full-sized avatar
:octocat:
Code wins arguments

Alexander frontenddeveloping

:octocat:
Code wins arguments
View GitHub Profile
@frontenddeveloping
frontenddeveloping / array mergeAsNumber
Last active August 29, 2015 13:57
Array.prototype.mergeAsNumber example
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 06:23
FileReader.prototype.readAsArrayBuffer vs FileReader.prototype.readAsDataUrl
<!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 June 20, 2014 06:46
Conversion dataUri string to Blob
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 August 29, 2015 14:07
Async javascript loading (with saving order).
/*
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
/**
* Watcher leaks for jQuery
* RubaXa <trash@rubaxa.org>
* MIT Licensed.
*
* API:
* $.leaks.get();
* $.leaks.watch();
* $.leaks.unwatch();
* $.leaks.remove();
@frontenddeveloping
frontenddeveloping / gitclean.sh
Created February 15, 2016 21:36 — forked from ericelliott/gitclean.sh
gitclean.sh - cleans merged/stale branches from origin
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 March 15, 2016 13:39 — forked from mztriz/Fix Cygwin Issues with Ruby
No such file or directory — /cygdrive/c/Ruby193/bin/gem (LoadError)
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'
@frontenddeveloping
frontenddeveloping / devtools-perf-annotations-example.js
Created March 31, 2016 07:39
DevTools Perdomance annotation example
//@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.
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;
import fs from 'fs';
import path, { resolve } from 'path';
import assert from 'assert';
import Module from 'module';
import jsdom from 'jsdom';
import Mocha from 'mocha';
import chokidar from 'chokidar';
// Let's import and globalize testing tools so
// there's no need to require them in each test