Skip to content

Instantly share code, notes, and snippets.

View Tahseenm's full-sized avatar

Tahseen Malik Tahseenm

View GitHub Profile
// Make new flatDict and return it
function flattenDictionary(dict) {
const go = (dict, initialKey, flatDict) => {
for (const key of Object.keys(dict)) {
const value = dict[key];
const flatKey = initialKey ? `${initialKey}.${key}` : key;
// When the value is a primitive
if (typeof value !== 'object') flatDict[flatKey] = value;
@Tahseenm
Tahseenm / nightmare-hacker-news-top-story.js
Created October 6, 2016 06:07
Get Top story from Hacker News using NightmareJs
import Nightmare from 'nightmare';
import colors from 'chalk';
import fs from 'fs';
import path from 'path';
import config from './../config.js';
/* ------------------------------------------ *\
// ------------------------------------------------- \\
// Check Mobile version
// ------------------------------------------------- //
const USER_AGENT = navigator.userAgent || navigator.vendor || window.opera
/**
* Detect if the enviroment executing this script is a Windows phone
* @returns {boolean}
*/
/**
* Check if device has a touch screen
*
* @returns {boolean}
*/
function isTouchDevice() {
return !!(window.ontouchstart && navigator.maxTouchPoints > 0)
}
@Tahseenm
Tahseenm / helpers.dom.js
Last active November 23, 2016 20:38
DOM Helpers
/**
* Wrapper for `addEventListener`
*
* @param {HTMLElement} target
* @param {string} eventType
* @param {function} eventHandler
* @param {boolean|Object.<boolean>} opt - useCapture OR
* {capture, once, passive} (NOTE: Low browser support)
*/
function on(target, eventType, eventHandler, opt = false) {
@Tahseenm
Tahseenm / cube.html
Last active August 26, 2017 19:46 — forked from anonymous/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
* {
box-sizing: inherit;
}
@Tahseenm
Tahseenm / mocha-react.test.js
Created August 26, 2017 22:37
React Component testing examples with Mocha, expect and React-Test-Utils
import React from 'react'
import ShallowRenderer from 'react-test-renderer/shallow'
import expect from 'expect'
import expectJSX from 'expect-jsx'
expect.extend(expectJSX)
// Component
const Greeting = ({greeting}) => (
@Tahseenm
Tahseenm / foo.js
Last active September 26, 2017 14:50
Javascript Undefined
/**
* Undefined cannot be assigned using window.undefined = someVal or
* undefined = someVal but can be changed using function scope.
* window.undefined is the same as window['undefined']
*
* The same example does not work with the null keyword and program throws
* a syntax error (function (null) {...})(123)
*/
;(function (undefined) {
// x is undefined
@Tahseenm
Tahseenm / index.js
Last active January 1, 2018 15:25
Minimal redux(y) lib
import { createStore } from './lib'
/**
* Main reducer
*/
const counter = function (state = 0, action) {
switch (action.type) {
case 'INCREMENT':
return state + 1
@Tahseenm
Tahseenm / widgets.js
Created October 21, 2017 19:39
Redux Ducks module pattern
/**
* PATH: -> ./src/redux/modules/widgets.js
*
* [RULES]
*
* A module...
*
* - MUST export default a function called reducer()
* - MUST export its action creators as functions
* - MUST have action types in the form npm-module-or-app/reducer/ACTION_TYPE