Skip to content

Instantly share code, notes, and snippets.

Avatar

Bilal Haidar bhaidar

View GitHub Profile
@bhaidar
bhaidar / pivot-tables.md
Created Apr 14, 2021 — forked from Braunson/pivot-tables.md
Laravel 8.x - Diving into Pivot Tables
View pivot-tables.md

Laravel 6 - Diving Into Pivot Tables

Pivot tables can be confusing and a little hard to wrap your head around at first. In this quick article we are going to dive into what a pivot table is, how to create one and finally how to use the pivot table. Let's dive in!

What is a pivot table?

A pivot table is used to connect relationships between two tables. Laravel provides a Many To Many relationship where you can use a pivot table.

@bhaidar
bhaidar / update-git.sh
Created Dec 2, 2020 — forked from YuMS/update-git.sh
Update git to latest version on Ubuntu
View update-git.sh
#!/bin/bash
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git -y
@bhaidar
bhaidar / update-git.sh
Created Dec 2, 2020 — forked from YuMS/update-git.sh
Update git to latest version on Ubuntu
View update-git.sh
#!/bin/bash
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git -y
@bhaidar
bhaidar / useGeolocation.md
Created Nov 18, 2020 — forked from whoisryosuke/useGeolocation.md
React Hooks - Geolocation use native browser API
View useGeolocation.md

useGeolocation

React sensor hook that tracks user's geographic location.

Hook

const useGeolocation = () => {
  const [state, setState] = useState({
    accuracy: null,
@bhaidar
bhaidar / node_nginx_ssl.md
Created Sep 21, 2020 — forked from bradtraversy/node_nginx_ssl.md
Node app deploy with nginx & SSL
View node_nginx_ssl.md

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user

@bhaidar
bhaidar / EslintNodeJS.md
Created Aug 10, 2020 — forked from LucasMallmann/EslintNodeJS.md
Eslint and Prettier configuration for NodeJS and Express projects
View EslintNodeJS.md

Eslint and prettier config for nodejs and express projects

Eslint and Libs

You need to install eslint and some other config libs.

yarn add eslint prettier eslint-config-prettier eslint-plugin-prettier -D

yarn eslint --init

.eslintrc.js

@bhaidar
bhaidar / git-helpers.plugin.zsh
Created May 27, 2020 — forked from clauswitt/git-helpers.plugin.zsh
Git zsh aliases and functions
View git-helpers.plugin.zsh
#git aliases
alias gsts='git status --short'
alias c='git commit '
alias gd='git diff '
alias clean='git clean -f'
alias gl='git l'
#git function to add last parameter of last command via git add (used after a diff)
gal() {
@bhaidar
bhaidar / postgres-cheatsheet.md
Created Apr 7, 2020 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet
View postgres-cheatsheet.md

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
View algo.js
function diffArray(arr1, arr2) {
let arr1UniqueItems = arr1.filter(item => arr2.indexOf(item) < 0);
let arr2UniqueItems = arr2.filter(item => arr1.indexOf(item) < 0);
return [...arr1UniqueItems, ...arr2UniqueItems];
}
@bhaidar
bhaidar / random.js
Created Mar 18, 2020 — forked from kerimdzhanov/random.js
JavaScript: get a random number from a specific range
View random.js
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {number} a random floating point number
*/
function getRandomFloat(min, max) {
return Math.random() * (max - min) + min;
}