Skip to content

Instantly share code, notes, and snippets.

Avatar
🎨
Programming

Abdulrahman Alotaibi abdulrahmanAlotaibi

🎨
Programming
  • Riyadh, KSA
View GitHub Profile
@abdulrahmanAlotaibi
abdulrahmanAlotaibi / numeric_vs_uuid
Created Sep 17, 2022 — 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.
View numeric_vs_uuid
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 Sep 17, 2022 — 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.
View numeric_vs_uuid
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)
View AnonymsStructsAndEmptyInterfaces.go
package main
import "fmt"
func main() {
s:= struct {
name string
age int
}{
name:"Hello",
View select.go
package main
import (
"fmt"
"time"
)
func addMsg(ch chan string, msg string){
time.Sleep(10 * time.Second)
ch <- msg
View generics.go
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
View workers.go
package main
import (
"fmt"
"time"
)
func worker(id int , jobs <- chan int, results chan <- int ){
for j:= range jobs {
View json.go
package main
import (
"fmt"
"encoding/json"
)
/* terms:
- Marshaling = Encoding
links:
- https://www.sohamkamani.com/golang/json/
@abdulrahmanAlotaibi
abdulrahmanAlotaibi / cheatsheet.sql
Last active Aug 13, 2022
SQL Cheatsheet for MySQL client CLI
View cheatsheet.sql
create table table_name (
id integer primary key
name varchar(255)
);
insert into table_name (column1,c2) values ('','') ;
drop user '<user_name>'@'localhost';
@abdulrahmanAlotaibi
abdulrahmanAlotaibi / load_env.sh
Created Sep 10, 2021
Load your database environment variables in the terminal session
View load_env.sh
#/!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 / knexjs.js
Last active Sep 10, 2021
Knex.js Query Builder - Queries Cheatsheet
View knexjs.js
/**
* @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)