Skip to content

Instantly share code, notes, and snippets.

View salzhrani's full-sized avatar

Samy Al Zahrani salzhrani

View GitHub Profile
@salzhrani
salzhrani / foo.js
Last active February 6, 2017 18:53
bundle js modules using rollup
export default function foo() {
return "foo";
}
@salzhrani
salzhrani / nightwatch.sublime-completions
Created November 18, 2015 12:06
nightwatch js sublime text completions
{
"scope": "source.js",
"completions": [
{
"trigger": ".attributeContains",
"contents": ".assert.attributeContains(${1:selector}${2:, attribute}${3:, expected}${4:, message})"
},
{
"trigger": ".attributeEquals",
"contents": ".assert.attributeEquals(${1:cssSelector}${2:, attribute}${3:, expected}${4:, msg})"
@salzhrani
salzhrani / completions.js
Created November 18, 2015 12:04
Create sublime text completions for nightwatch.js from the console
var methods = document.querySelectorAll('.assertions .apimethod');
methods = Array.from(methods);
var assertions = methods.map(function(method){
var args = Array.from(method.querySelectorAll('table code'));
return {
name: method.querySelector('h3 code').textContent,
args: args.map(function(table){ return table.textContent}),
};
});
@salzhrani
salzhrani / polyfill.js
Created March 27, 2015 13:33
canvas.toBlob polyfill
if( !HTMLCanvasElement.prototype.toBlob ) {
Object.defineProperty( HTMLCanvasElement.prototype, 'toBlob',
{
value: function( callback, type, quality )
{
var bin = atob( this.toDataURL( type, quality ).split(',')[1] ),
len = bin.length,
len32 = len >> 2,
a8 = new Uint8Array( len ),
a32 = new Uint32Array( a8.buffer, 0, len32 );
@salzhrani
salzhrani / index.html
Created March 26, 2015 13:48
Good quality JS image resize
<!DOCTYPE html>
<html>
<head></head>
<body>
<img src="img.jpg" width="500" alt="">
<button onclick="doResize()">Resize</button>
<script src="parallel.js"></script>
<script>