Skip to content

Instantly share code, notes, and snippets.

View AmrAbdulrahman's full-sized avatar

Amr Abdulrahman AmrAbdulrahman

View GitHub Profile
@AmrAbdulrahman
AmrAbdulrahman / UK tax calculator.js
Created January 19, 2024 15:04
UK tax calculator
/**
* Calculates the employee national insurance contribution based on annual net salary.
* @param {number} annual net salary.
* @return The employee national insurance contribution based on annual net salary
* @customfunction
*/
function EMPLOYEE_NATIONAL_INSURANCE(income) {
/**
* If you're an employee you start paying National Insurance when you earn more than £242 a week (2023/24). The National Insurance rate you pay depends on how much you earn, and is made up of: 12% of your weekly earnings between £242 and £967 (2023/24) 2% of your weekly earnings above £967.
*/
function checkWinner(codeList, shoppingCart) {
if (codeList.length === 0) return 1;
if (shoppingCart.length === 0) return 0;
function canMatch(group, fromIndex) {
// if cart has no enough items to match the group
if (fromIndex + group.length > shoppingCart.length) return false;
for (let groupItemIndex = 0; groupItemIndex < group.length; groupItemIndex++) {
// if items don't match, and we don't have a wildcard, then fail immediately
alias ghome="gwip && gpsup --no-verify"
alias gfire="ghome --force"
@AmrAbdulrahman
AmrAbdulrahman / camelCaseToSpaceSeparated.js
Created May 16, 2019 12:32
Convert camelCase to space separated words
'camelCaseStyle'
.split(/([a-z][A-Z])/g)
.reduce((words, group, index) => (index % 2 ? `${words}${group[0]} ${group[1]}` : `${words}${group}`), '')
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { withStyles } from 'material-ui/styles';
import Grid from 'material-ui/Grid';
import Loading from '~/Components/Loading';
import styles from './styles';
@withStyles(styles)
class Form extends Component {
@AmrAbdulrahman
AmrAbdulrahman / forward.js
Last active January 5, 2018 19:59
Forward all files as modules from a directory
/*
It's often we have a bunch of modules that we need to just forward
from a single entry point
as following:
-- src
---- utils
------ isFunction.js
------ isString.js
------ isArray.js
/*
In case you have tens of files with '2 spaces' indentation that you need to convert to '4 spaces'
1. Install 'recursive-readdir-sync', do not add the --save label.
2. cd to the root of the directory you want to process
3. Place this script.
3. Run the script, commit, push, enjoy!
*/
let fs = require('fs');
let recursiveReadSync = require('recursive-readdir-sync');
function uploadFile(data) {
// we can send notification one or more time as following:
defer.notify(percentageUploaded);
// returns promise
}
uploadFile()
.then(function() {
// fine
function asyncOperation() {
// returns promise
}
// show blocking loading modal
asyncOperation()
.then(function() {
// all fine
}, function() {
// something went wrong
function asyncOperation() {
// returns promise
}
var promises = [];
for (var i=0; i<=10; i++) {
var promise = asyncOperation();
promises.push(promise);
}