Skip to content

Instantly share code, notes, and snippets.

Avatar

Ahmad Bamieh Bamieh

View GitHub Profile
View boxed.hs
import qualified Data.ByteString.Lazy as L
import Data.Word (Word8)
data Stats = Stats
{ total :: Int
, count :: Int
}
initStats :: Stats
initStats = Stats 0 0
@Bamieh
Bamieh / mapOn.js
Last active Oct 27, 2017
Map over items that meet a certain condition, otherwise just pass the item as is.
View mapOn.js
/*
Description:
Map over an array of items:
- If the item meets the condition, apply the callback
- If the item does not meet the condition return the item without any transformation.
Example:
```
const exampleArray = [1, 2, 9, "C", "B", "C"];
@Bamieh
Bamieh / Instructions.md
Created Sep 28, 2017 — forked from pgilad/Instructions.md
Git commit-msg hook to validate for jira issue or the word merge
View Instructions.md

Instructions

  • copy the file commit-msg to .git/hooks/commit-msg
  • make sure your delete the sample file .git/hooks/commit-msg.sample
  • Make commit msg executable. chmod +x .git/hooks/commit-msg
  • Edit commit-msg to better fit your development branch, commit regex and error message
  • Profit $$

Shell example

@Bamieh
Bamieh / requestPostList.js
Created Aug 18, 2017 — forked from pahund/requestPostList.js
Code Example for Testing a Redux Saga with Mocha
View requestPostList.js
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 }) {
@Bamieh
Bamieh / random.js
Created Feb 10, 2017
pure function random number generator
View random.js
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 / client.js
Created Nov 11, 2016 — forked from davidgilbertson/client.js
Node http vs net modules
View client.js
// 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 / keycode.js
Created Oct 19, 2016
Tiny Crossbrowser Keycode checking function
View keycode.js
/*
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 / destructuring.js
Created Oct 13, 2016 — 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
View destructuring.js
// === 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 / parse-dotless.scss
Last active Dec 1, 2016
Sass parse class without dot (strip dot "." from class name)
View parse-dotless.scss
@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 / what-forces-layout.md
Created Jul 21, 2016 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.
View what-forces-layout.md

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()