View appleapple.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias ghome="gwip && gpsup --no-verify" | |
alias gfire="ghome --force" |
View camelCaseToSpaceSeparated.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'camelCaseStyle' | |
.split(/([a-z][A-Z])/g) | |
.reduce((words, group, index) => (index % 2 ? `${words}${group[0]} ${group[1]}` : `${words}${group}`), '') |
View Form.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
View forward.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asyncOperation() { | |
// returns promise | |
} | |
// show blocking loading modal | |
asyncOperation() | |
.then(function() { | |
// all fine | |
}, function() { | |
// something went wrong |
View promises-all.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asyncOperation() { | |
// returns promise | |
} | |
var promises = []; | |
for (var i=0; i<=10; i++) { | |
var promise = asyncOperation(); | |
promises.push(promise); | |
} |
View promises-example-applied.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async1() | |
.then(function(inputsFromAsync1) { | |
return async2(); | |
}) | |
.then(function(inputsFromAsync2) { | |
return async3(); | |
}) | |
.then(function(inputsFromAsync3) { | |
return async4(); | |
}) |
NewerOlder