Skip to content

Instantly share code, notes, and snippets.

@alaboudi
alaboudi / Dockerfile
Created October 14, 2017 03:51
Docker file for Angular4 application on an Nginx server
# This docker file will consist of two stages. The first stage will be used to arrange the application
# dependencies and compile it. The second stage will be used to set up an nginx server to serve the
# static angular content.
### Stage 1: Downloading application dependencies and compiling angular AoT
# Create image based on the official Node based on the Alpine linus distribution image from dockerhub
FROM node:alpine AS builder
# Create a directory where our app will be placed. -p is to create parent directories as necessary
@alaboudi
alaboudi / compose.js
Created January 24, 2018 22:05
Function to compose other functions
const compose = (...fns) =>
fns.reverse().reduce((prevFn, nextFn) =>
value => nextFn(prevFn(value)),
value => value
);
@alaboudi
alaboudi / someReducer.wrong.test.js
Last active August 5, 2018 18:57
Incorrect Reducer Initial State Test
import { someReducer, SOME_REDUCER_INITIAL_STATE } from './someReducer.js'
describe('someReducer', () => {
it('should return the correct initial state', () => {
expect(someReducer(undefined, {}).toEqual(SOME_REDUCER_INITIAL_STATE);
});
});
@alaboudi
alaboudi / someReducer.correct.test.js
Last active August 5, 2018 18:57
Correct Reducer Initial State Test
import { someReducer } from './someReducer.js'
describe('someReducer', () => {
it('should return the correct initial state', () => {
expect(someReducer(undefined, {}).toEqual({
prop1: 'someValue1',
prop2: 'someValue2',
.....
});
});
@alaboudi
alaboudi / coupling-in-component.js
Last active November 29, 2018 13:44
Imperative Action Type
// scoreboard-reducer.js
const INITIAL_STATE = {
home: 0,
away: 0,
}
export const scoreboardReducer = (state = INITIAL_STATE, action) {
switch (action.type) {
case 'INCREMENT_HOME_SCORE':
return {...state, home: state.home + 1 };
case 'INCREMENT_AWAY_SCORE':
// scoreboard-reducer.js
const INITIAL_STATE = {
home: 0,
away: 0,
}
export const scoreboardReducer = (state = INITIAL_STATE, action) {
switch (action.type) {
case 'INCREMENT_SCORE':
const scoringSide = action.payload.team
return {...state, [scoringSide]: state[scoringSide] + 1 };
@alaboudi
alaboudi / no-coupling-be-happy.js
Last active March 18, 2019 19:04
Declarative Action Type
// scoreboard-reducer.js
const INITIAL_STATE = {
home: 0,
away: 0,
}
export const scoreboardReducer = (state = INITIAL_STATE, action) {
switch (action.type) {
case 'GOAL_SCORED':
const scoringSide = action.payload.team;
return {...state, [scoringSide]: state.[scoringSide] + 1 };
// scoreboard-reducer.js
const INITIAL_STATE = {
home: 0,
away: 0,
}
export const scoreboardReducer = (state = INITIAL_STATE, action) {
switch (action.type) {
case 'INCREMENT_SCORE':
const scoringSide = action.payload.team;
@alaboudi
alaboudi / checkbox.tsx
Last active April 2, 2020 23:47
Customize checkbox only using css
import styled from "styled-components";
const Checkbox = styled.input.attrs(() => ({
type: 'checkbox'
}))`
appearance: none;
background-color: #ffffff;
border: 1px solid #000000;
box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05);
padding: 8px;
@alaboudi
alaboudi / load-state.js
Created May 6, 2020 20:21
load-state.js
// You and your teammate have been working on a project for two and a half
// weeks. Everything is going well except you notice that one of the functions
// your teammate wrote is failing a test case, which you know to be correct.
// Unfortunately, your teammate is sick today and to make matters worse, you
// realize that you need to demo your project in ten minutes. So you decide
// to try and fix the function. Can you fix it in time for your demo?
////////////////////////////////////////////////////////////////////////////////
const SYMBOLS = [ 'AAPL', 'AMZN', 'MONY', 'PETS', 'PZZA', 'SHOP', 'TSLA', 'WIFI' ];