Skip to content

Instantly share code, notes, and snippets.

View abdulrahmanAlotaibi's full-sized avatar
🎨
Programming

Abdulrahman Alotaibi abdulrahmanAlotaibi

🎨
Programming
  • Riyadh, KSA
  • 03:09 (UTC -12:00)
View GitHub Profile
@abdulrahmanAlotaibi
abdulrahmanAlotaibi / knexjs.js
Last active September 10, 2021 20:55
Knex.js Query Builder - Queries Cheatsheet
/**
* @Desc : All of my data are seeded using this testing database(https://github.com/datacharmer/test_db) just import it to your local database server
*/
const knex = require("knex")
const db = knex(require("./knexfile")["development"])
const { bgCyan, bgRed, redBright, bold, underline } = require("colorette") // To add colors for stdout text
db.from("departments").select("*").first().then(res => {
console.log(bgCyan("Basic select:"))
console.log(res)
@abdulrahmanAlotaibi
abdulrahmanAlotaibi / load_env.sh
Created September 10, 2021 19:30
Load your database environment variables in the terminal session
#/!bin/bash
# 1) Change the variables to your desired environment
# 2) Use the . ./load_env.sh dev to run the script
# . load_env.sh dev ==> load dev environment variables
# . load_env.sh staging ==> load staging environment variables
# . load_env.sh production ==> load production environment variables
echo "Loading your database environment variables to your shell session..."
if [[ "${1}" == "dev" ]]; then
@abdulrahmanAlotaibi
abdulrahmanAlotaibi / cheatsheet.sql
Last active August 13, 2022 11:23
SQL Cheatsheet for MySQL client CLI
create table table_name (
id integer primary key
name varchar(255)
);
insert into table_name (column1,c2) values ('','') ;
drop user '<user_name>'@'localhost';
package main
import (
"fmt"
"encoding/json"
)
/* terms:
- Marshaling = Encoding
links:
- https://www.sohamkamani.com/golang/json/
package main
import (
"fmt"
"time"
)
func worker(id int , jobs <- chan int, results chan <- int ){
for j:= range jobs {
package main
import "fmt"
func MapKeys[K comparable, V any](m map[K]V) []K {
r := make([]K, 0, len(m))
for k := range m {
r = append(r, k)
}
return r
package main
import (
"fmt"
"time"
)
func addMsg(ch chan string, msg string){
time.Sleep(10 * time.Second)
ch <- msg
@abdulrahmanAlotaibi
abdulrahmanAlotaibi / AnonymsStructsAndEmptyInterfaces.go
Created September 2, 2022 15:20
Anonyms structs + empty interfaces
package main
import "fmt"
func main() {
s:= struct {
name string
age int
}{
name:"Hello",
@abdulrahmanAlotaibi
abdulrahmanAlotaibi / numeric_vs_uuid
Created September 17, 2022 09:50 — forked from jgaskins/numeric_vs_uuid
Comparing numeric vs UUID in Postgres. Rehearsal benchmarks are thrown out. Only the second run is kept. Insertions are done all in one query to minimize the impact of I/O. This is harder to do with retrieval, but the ids are randomized in each one to minimize the effects of caching inside the database.
Inserting
user system total real
Numeric 0.070000 0.010000 0.080000 ( 0.586738)
UUID 0.070000 0.020000 0.090000 ( 3.101085)
Retrieving by id
user system total real
Numeric 0.810000 0.980000 1.790000 ( 6.831551)
UUID 0.830000 0.990000 1.820000 ( 6.981944)
@abdulrahmanAlotaibi
abdulrahmanAlotaibi / numeric_vs_uuid
Created September 17, 2022 09:50 — forked from jgaskins/numeric_vs_uuid
Comparing numeric vs UUID in Postgres. Rehearsal benchmarks are thrown out. Only the second run is kept. Insertions are done all in one query to minimize the impact of I/O. This is harder to do with retrieval, but the ids are randomized in each one to minimize the effects of caching inside the database.
Inserting
user system total real
Numeric 0.070000 0.010000 0.080000 ( 0.586738)
UUID 0.070000 0.020000 0.090000 ( 3.101085)
Retrieving by id
user system total real
Numeric 0.810000 0.980000 1.790000 ( 6.831551)
UUID 0.830000 0.990000 1.820000 ( 6.981944)