Skip to content

Instantly share code, notes, and snippets.

View Bamieh's full-sized avatar

Ahmad Bamieh Bamieh

View GitHub Profile
/*!
* jQuery Tiny Pub/Sub - v0.X - 11/18/2010
* http://benalman.com/
*
* Original Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*
* Made awesome by Rick Waldron
*
@Bamieh
Bamieh / app.html
Last active April 17, 2016 06:58 — forked from ebidel/app.html
Fast Polymer app loading (Promises version) - optimized for first render, progressively enhanced lazy loading
<!DOCTYPE html>
<html class="no-scroll">
<head>
<style>
.no-scroll,
body.loading-app {
overflow: hidden;
}
body.loading-app #splash-screen {
opacity: 1;
@Bamieh
Bamieh / dynamic-waterfall-promise.js
Created July 20, 2016 19:49
Promise Waterfall for dynamic number of promises with callback on each and array resolve on complete
var counter = 0;
function run(cb) {
counter++;
return (function(count) {
return new Promise(function(resolve, reject) {
cb(count);
resolve(count);
});
})(counter);
}
@Bamieh
Bamieh / what-forces-layout.md
Created July 21, 2016 10:27 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@Bamieh
Bamieh / parse-dotless.scss
Last active December 1, 2016 13:59
Sass parse class without dot (strip dot "." from class name)
@function parse-dotless($class) {
$this: quote($class);
@return if(str-slice($this, 0, 1) == ".", str-slice($this, 2, str-length($this)), $this);
}
/*
example usage:
.14px {
font-size: parse-dotless(#{&}); // will strip the class from .14px to return 14px;
}
@Bamieh
Bamieh / destructuring.js
Created October 13, 2016 09:36 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@Bamieh
Bamieh / keycode.js
Created October 19, 2016 06:47
Tiny Crossbrowser Keycode checking function
/*
usage:
Events.on(window, 'keydown', (event) => {
tabPressed = keycode(event, 13);
});
*/
export default function keycode(event, code) {
const property = event.key || event.keyIdentifier || event.keyCode;
return property && property === code;
};
@Bamieh
Bamieh / client.js
Created November 11, 2016 09:13 — forked from davidgilbertson/client.js
Node http vs net modules
// This makes two connections, one to a tcp server, one to an http server (both in server.js)
// It fires off a bunch of connections and times the response
// Both send strings.
const net = require(`net`);
const http = require(`http`);
function parseIncomingMessage(res) {
return new Promise((resolve) => {
@Bamieh
Bamieh / random.js
Created February 10, 2017 14:10
pure function random number generator
const randomNumber = (m_w, m_z) => {
const c_m_z = 36969 * (m_z & 65535) + (m_z >> 16);
const c_m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (c_m_z << 16) + c_m_w;
}
// code snippet from Joe Nelson's course at frontend masters.
@Bamieh
Bamieh / requestPostList.js
Created August 18, 2017 13:36 — forked from pahund/requestPostList.js
Code Example for Testing a Redux Saga with Mocha
import { push } from 'react-router-redux';
import { takeLatest, call, put } from 'redux-saga/effects';
import config from '../../../config/client';
import { REQUEST_POST_LIST } from '../actions';
import updatePostList from '../actions/updatePostList';
import fetchPostList from './utils/fetchPostList';
import trackPageViewWithGoogleAnalytics from '../actions/trackPageViewWithGoogleAnalytics';
import trackPageViewWithIvw from '../actions/trackPageViewWithIvw';
export function *requestPostList({ threadId, page }) {