Skip to content

Instantly share code, notes, and snippets.

View novonimo's full-sized avatar
🏠
Working from home

Nima Mohamadian novonimo

🏠
Working from home
View GitHub Profile
import service from "./service.json";
function sendAvailableArea() {
const headers = {
'x-api-key': process.env.REACT_APP_MAP_IR_ACCESS_TOKEN,
// 'Content-Type': 'multipart/form-data'
};
const formData = new FormData();
//
@novonimo
novonimo / reducer.js
Created November 13, 2019 08:07
reducerSnippet
case VOTE_COMMENT_SUCCESS:
return {
...state,
comments: state.comments.map(comment =>
comment.id === action.id
? {
...comment,
cached_votes_up: action.data.vote_up,
cached_votes_down: action.data.vote_down,
}
@novonimo
novonimo / memoization.js
Created September 15, 2019 19:04
create a simple and fast memoization function for calculation.
/*
use this memoiziation function with immutable js and see the
beautifulness of Js
calculate one time and use it every where
*/
function memoize(fn) {
let prevArg;
let prevResult;
return function (arg) {
@novonimo
novonimo / consoleCoolFeature.js
Created September 13, 2019 12:30
use some cool features of console in dev tool
console.log("%c Hello my name is nima", "color: orange; font-weight: bold;");
const foo = {name: "nima", age: 30};
const bar = {name: "sina", age: 28};
const baz = {name: "ahmad", age: 58};
console.table([foo, bar, baz])
console.time("looper")
@novonimo
novonimo / promis.js
Created September 13, 2019 11:59
learn promise with a single file example
function makeReques(location) {
return new Promise((resolve, reject) => {
console.log(`Making requrest to ${location}`)
if (location === "Google") {
resolve("Google says hi")
} else {
reject("We can only talk to Google")
}
})
}
async function fetchAvatarUrl(userId) {
const response = await fetch(`https://catappapi.herokuapp.com/users/${userId}`)
const user = await response.json();
return Promise.all(user.cats.map(async (catId) => {
const response = await fetch(`https://catappapi.herokuapp.com/cats/${catId}`)
const catData = await response.json()
return catData.imageUrl
}))
}
@novonimo
novonimo / simpleSort.js
Last active September 13, 2019 09:00
introduce to sort HOC
const listOfNumbers = [4, 5, 8, 1, 0, 2, 7, 3]
const sortedList = listOfNumbers.sort((n1, n2) => {
if (n1 > n2) {
return 1;
} else {
return -1;
}
})
@novonimo
novonimo / stopwatch.js
Created September 13, 2019 07:25
simple OOP exercise, stopwatch that count time between start and stop
/**
* Stopwatch onject will used for count time between start and stop time
* there are thre method on it: start, stop, reset
* and there are one property "duration"
* Implement constructor function for create object
*/
function Stopwatch () {
let duration = 0;
let intervalId = null;
let isRunning = false
function* myGenerator () {
yield 1;
yield 2;
return 3;
};
const myIterator = myGenerator();
console.log(myIterator.next());
console.log("************************");
/*
increase function will use number but it copy new number for use it
number is a Primitive type so ther are independent and will not change
*/
let number = 10;
function increase (param) {
param++;
console.log("param value is: ", param);
};