Skip to content

Instantly share code, notes, and snippets.

View miladvafaeifard's full-sized avatar
🙌
always looking simple solutions

Milad Vafaeifard miladvafaeifard

🙌
always looking simple solutions
View GitHub Profile
@miladvafaeifard
miladvafaeifard / lambda-calculator.cpp
Created December 26, 2018 23:08
my first lambda use in c++
#include "pch.h" // for visual studio usage
#include <iostream>
#include <functional>
class Calculator {
public:
Calculator(int num) : _baseNum(num) {};
int add(int a, int b) {
@miladvafaeifard
miladvafaeifard / functionAsChild.md
Last active December 18, 2018 08:57
Function as Child pattern gaining consensus within the React community.

Function As Child in React JS

The main concept is that, instead of passing a child in the form of a component, we define a function that can receive parameters from the parent. Let's see what it looks like:

const FunctionAsChild = ({ children }) => children()

FunctionAsChild.propTypes = {
@miladvafaeifard
miladvafaeifard / .dockerignore
Created December 4, 2018 21:23
init docker ignore
# Common
README.md
CHANGELOG.md
docker-compose.yml
Dockerfile
# Node
## Logs
logs
*.log
@miladvafaeifard
miladvafaeifard / custom-element.js
Created November 30, 2018 11:27
Using custom elements
class WordCound extends HTMLElement {
constructor() {
super();
var shadowRoot = this.attachShadow({ mode: "open" });
var p = document.createElement("p");
p.textContent = "Hello World";
p.setAttribute("class", "red-color");
var style = document.createElement("style");
@miladvafaeifard
miladvafaeifard / install-vscode-extensions-cli
Last active December 11, 2022 22:22
How to install VSCode extensions from command line run
abusaidm.html-snippets
andys8.jest-snippets
ashinzekene.nestjs
christian-kohler.npm-intellisense
CoenraadS.bracket-pair-colorizer
DavidAnson.vscode-markdownlint
dawhite.mustache
dbaeumer.jshint
dbaeumer.vscode-eslint
dracula-theme.theme-dracula
@miladvafaeifard
miladvafaeifard / factory-pattern.js
Last active December 1, 2018 23:40
understand factory pattern in plain javascript
class Animal {
constructor(pet) {
this.pet = pet;
}
speak() {
console.log(this.pet);
}
join(animal) {
let num = 2;
console.log(~num); // -3
// how it works
// first we should know binary code, convert 2 to 0010 and flip it to 1101 (-2), and then add 1 to it, the result is -3.
num = -2;
conosle.log(~num); // 1
@miladvafaeifard
miladvafaeifard / test-go.go
Created November 23, 2018 17:45
test golang
package main
import "fmt"
type Person interface {
getName() string
}
func (e Employee) getName() string {
@miladvafaeifard
miladvafaeifard / pre-commit.sh
Created November 23, 2018 16:37
typescript validation and testing (tslint)
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
#!/bin/sh
@miladvafaeifard
miladvafaeifard / commit-msg.sh
Last active January 28, 2019 08:35
The hook will check if the current branch is a story branch.
#!/bin/sh
#
# The hook will check if the current branch is a story branch.
#
# If it is then it will check the commit message if it contains the correct prefix.
#
# Correct commit message form:
# [STORY-ID] A commit message
#
# If the commit message does not follow the from above the hook will fix it.