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
@novonimo
novonimo / simpleRouter.js
Created March 8, 2019 09:27
simple router with context api from scrach
import React, {Component} from 'react'
import createHistory from 'history/createBrowserHistory'
const RouterContext = React.createContext();
class Router extends Component {
constructor(props){
super(props);
this.history = createHistory();
@novonimo
novonimo / simpleRouter.js
Last active March 8, 2019 11:00
simple router with context api from scrach
import React, {Component} from 'react'
import {
Route,
Link,
Redirect,
BrowserRouter as Router
} from "react-router-dom";
const HomePage = () => {
return (
@novonimo
novonimo / install-dart-on-linux.sh
Created March 23, 2019 14:32
Linux Script for "Set up your first Dart project on Linux"
# Update package repo listings
sudo apt-get update
# Enable access to repos using the HTTPS protocol
sudo apt-get install apt-transport-https
# Add Google linux sign in key to allow Dart repo registry
sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
# Register Dart repo (release version)
@novonimo
novonimo / install-dart-on-windows.bat
Created March 23, 2019 14:49
Windows Script for "Set up your first Dart project on Windows"
REM Install Chocolatey package manager with cmd.exe
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
REM ..or Install Chocolatey package manager with Powershell.exe
REM Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
REM Install the Dart SDK
choco install dart-sdk
REM ..or Install the Dart SDK development version
/*
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);
};
function* myGenerator () {
yield 1;
yield 2;
return 3;
};
const myIterator = myGenerator();
console.log(myIterator.next());
console.log("************************");
@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
@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;
}
})
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 / 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")
}
})
}