Skip to content

Instantly share code, notes, and snippets.

View yaminmhd's full-sized avatar

Yamin yaminmhd

View GitHub Profile
@yaminmhd
yaminmhd / MapRunner.java
Created June 10, 2018 15:11
MapRunner.java - Number of occurrences in a given string
package collections;
import java.util.LinkedHashMap;
public class StringRunner {
public static void main(String[] args) {
String str = "This is a great thing";
String[] arr = str.toLowerCase().replaceAll("\\s", "").split("");
LinkedHashMap<String, Integer> arrayMap = new LinkedHashMap<>();
const string = 'hello';
for(let char of string){
console.log(char.toUpperCase().repeat(5));
}
//HHHHH
//EEEEE
//LLLLL
//LLLLL
//OOOOO
const person = {
name: 'Alex',
age: 25,
sayHi: function(){
console.log(`Hi there, my name is ${this.name} and I am ${this.age} years old`)
}
}
for (let key in person){
console.log(`${key} => ${person[key]}`)
const numbers = [1,2,3,4,5];
for(let i = 0; i < 10; i ++){
console.log(numbers[i]);
}
@yaminmhd
yaminmhd / packages
Created March 25, 2018 10:42
Adding prettier dependencies for create-react-app
yarn add prettier eslint-config-prettier eslint-plugin-prettier husky lint-staged pretty-quick --dev
@yaminmhd
yaminmhd / reducer.js
Created March 25, 2018 05:23
high order function reducer
const votes = [
'tacos',
'pizza',
'pizza',
'tacos',
'fries',
'ice cream',
'ice cream',
'pizza'
]
@yaminmhd
yaminmhd / .eslintrc
Created March 24, 2018 16:45
Prettier/eslint configuration in create-react-app
{
"extends": ["react-app", "plugin:prettier/recommended"]
}
@yaminmhd
yaminmhd / react-lifecycle-events.js
Created March 24, 2018 16:39
React Lifecycle events
/*
We can break React's life cycle methods into two categories
1. When a component gets mounted to the DOM and unmounted
2. When a component receives new data
When a component is initialized and added to the DOM (mounting) and when the component is removed from the DOM(unmounting).
These methods will be invoked only once during the life of the component
*/
//Some tasks that are important to do when a component mounts or unmounts
// - Establish some default props in our component
@yaminmhd
yaminmhd / different-components.js
Created March 24, 2018 08:18
Stateless components vs functional stateless components vs functional components
//Stateless components
import React, {Components} from 'react';
class Repos extends Component {
render(){
return (
<div>
<h3> User Repos </h3>
<ul className="list-group">
{this.props.repos.map((repo, index) => {