Skip to content

Instantly share code, notes, and snippets.

View hoodwink73's full-sized avatar

Arijit Bhattacharya hoodwink73

View GitHub Profile
@hoodwink73
hoodwink73 / components.content-item.js
Last active September 25, 2017 11:12
Scrollable Content
import Ember from 'ember';
export default Ember.Component.extend({
attributeBindings: ['index:data-item-index']
});
@hoodwink73
hoodwink73 / components.magic-title.js
Created September 26, 2017 10:25
Intergration tests with Components Examples
import Ember from 'ember';
export default Ember.Component.extend({
'title': 'Hello World',
actions: {
updateTitle () {
this.set('title': 'This is magic')
}
}
});
@hoodwink73
hoodwink73 / artificial-mouse-click.js
Created December 27, 2017 06:06
Generate a mouse click event without jQuery
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
function simulateClick() {
var evt = new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: window
});
var cb = document.getElementById("checkbox"); //element to click on
var canceled = !cb.dispatchEvent(evt);
if(canceled) {
@hoodwink73
hoodwink73 / retry-upon-failure.js
Last active March 23, 2018 16:02
Abstraction to retry async tasks upon failure using Promises
function mockAsyncTask () {
console.log('Simulating Failure');
return Promise.reject(new Error('failure'));
}
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
const retry = (asyncTask, strategy) => {
return strategy.reduce(function (promiseChain, interval, index) {
return promiseChain
@hoodwink73
hoodwink73 / README.md
Last active July 5, 2018 04:48
Basic functional programming concepts taken from the course Functional Light v2 by Kyle Simpson on Frontend Masters

Instructions

  1. Define a compose(..) that takes any number of functions (as individual arguments) and composes them right-to-left.

  2. Define a pipe(..) that takes any number of functions (as individual arguments) and composes them left-to-right.

@hoodwink73
hoodwink73 / .storybook-config.js
Created August 28, 2018 10:09
Switch between emotion themes in Storybook
import React, {Fragment} from 'react'
import {ThemeProvider} from 'emotion-theming'
import {configure, addDecorator} from '@storybook/react'
import DarkTheme from '../src/styles/themes/Dark'
import LightTheme from '../src/styles/themes/Light'
import {withKnobs} from '@storybook/addon-knobs'
import {select} from '@storybook/addon-knobs'
@hoodwink73
hoodwink73 / get_all_paginated_response.js
Created March 26, 2019 12:56
Handling paginated API using Asyquence
const ASQ = require("asynquence")
const asyncTaskFactory = () => {
let invokationCount = 0
const asyncTask = () => {
return ASQ().then(done => {
setTimeout(() => {
invokationCount = invokationCount + 1
done({
@hoodwink73
hoodwink73 / unique_array.js
Created April 5, 2019 07:01
Call it trickery or geekery, I am going to create a unique array using `filter` (thanks @getify)
const the_redundants = [1, 2, 2, 3, 4, 6, 6, 7, 7, 7, 8]
// this is posiible because indexOf always
// returns the left most index
const the_pures = the_redundants
.filter((n, index, arr) =>
arr.indexOf(n) === index
)
@hoodwink73
hoodwink73 / unique_array.js
Created April 5, 2019 07:01
Call it trickery or geekery, I am going to create a unique array using `filter` (thanks @getify)
const the_redundants = [1, 2, 2, 3, 4, 6, 6, 7, 7, 7, 8]
// this is posiible because indexOf always
// returns the left most index
const the_pures = the_redundants
.filter((n, index, arr) =>
arr.indexOf(n) === index
)
@hoodwink73
hoodwink73 / 1. error_behavior_in asynquence.js
Last active April 15, 2019 06:14
Error handling with Asynquence is a bit different. By default a error in the sequence suspends the entire sequence.
ASQ()
.promise(delayWithReject(200))
.or(() => console.log('caught'))
.val(() => console.log('The sequence deactivates. So this never gets logged.'))
ASQ()
// a `try` always ends up in a sequence progress
// in case the task fails the next step will receive a special messsage
// -> {error: "Reason for failure" }
.try((done) => done.fail('Doomed!!'))