Skip to content

Instantly share code, notes, and snippets.

View appleapple.js
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
View git-fire.sh
alias ghome="gwip && gpsup --no-verify"
alias gfire="ghome --force"
@AmrAbdulrahman
AmrAbdulrahman / camelCaseToSpaceSeparated.js
Created May 16, 2019
Convert camelCase to space separated words
View camelCaseToSpaceSeparated.js
'camelCaseStyle'
.split(/([a-z][A-Z])/g)
.reduce((words, group, index) => (index % 2 ? `${words}${group[0]} ${group[1]}` : `${words}${group}`), '')
View Form.js
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 Jan 5, 2018
Forward all files as modules from a directory
View forward.js
/*
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
View convert-2-spaces-indentation-to-4-spaces.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');
View promises-notify.js
function uploadFile(data) {
// we can send notification one or more time as following:
defer.notify(percentageUploaded);
// returns promise
}
uploadFile()
.then(function() {
// fine
View promises-finally.js
function asyncOperation() {
// returns promise
}
// show blocking loading modal
asyncOperation()
.then(function() {
// all fine
}, function() {
// something went wrong
View promises-all.js
function asyncOperation() {
// returns promise
}
var promises = [];
for (var i=0; i<=10; i++) {
var promise = asyncOperation();
promises.push(promise);
}
View promises-example-applied.js
async1()
.then(function(inputsFromAsync1) {
return async2();
})
.then(function(inputsFromAsync2) {
return async3();
})
.then(function(inputsFromAsync3) {
return async4();
})