Skip to content

Instantly share code, notes, and snippets.

Amr Abdulrahman AmrAbdulrahman

Block or report user

Report or block AmrAbdulrahman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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();
})
View promises-skeleton.js
function asyncSayHiTo(name) {
// define a defer
// defer is the context of the ASYNC operation
var defer = q.defer();
// make an async operation
setTimeout(function() {
// this should run after the function already terminated
// and returned a promise
View promises-callbacks-way.js
async1(function() {
// do some stuff
async2(function(inputsFromAsync1) {
// do stuff that depends on inputsFromAsync1
async3(function(inputsFromAsync2) {
// do stuff that depends on inputsFromAsync2
async4(function(inputsFromAsync3) {
You can’t perform that action at this time.