Skip to content

Instantly share code, notes, and snippets.

View allochi's full-sized avatar

Ali Anwar allochi

  • Private
  • Geneva, Switzerland
View GitHub Profile
@allochi
allochi / add_timestamps.sql
Created February 21, 2024 12:11
PostgreSQL add `create_at` and `updated_at` columns
ALTER TABLE __table_name__ ADD COLUMN created_at TIMESTAMP;
ALTER TABLE __table_name__ ALTER COLUMN created_at SET DEFAULT now();
CREATE OR REPLACE FUNCTION trigger_set_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at=now();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
@allochi
allochi / main.go
Created February 20, 2024 13:15
Script to transfer postgres `json` field to camel case
package main
import (
"fmt"
"log"
"regexp"
"strings"
"github.com/jmoiron/sqlx"
"github.com/stoewer/go-strcase"
@allochi
allochi / sqlx_last_inserted_id.go
Last active October 19, 2022 07:58
Returning last inserted record or id in postgresql using sqlx prepared statement in a transaction
package main
import (
"fmt"
"log"
"github.com/jmoiron/sqlx"
"github.com/k0kubun/pp"
_ "github.com/lib/pq"
)
@allochi
allochi / coffeeshop_beverage_prices.sql
Created September 16, 2022 12:32
Sample graph query on SurrealDB
-- coffeeshops
CREATE coffeeshop:starbucks SET name='StarBucks';
CREATE coffeeshop:boreal SET name='Boreal';
-- beverages
CREATE beverage:tea SET name='Tea';
CREATE beverage:latte SET name='Latte';
CREATE beverage:caramel_macchiato SET name='Caramel Macchiato';
CREATE beverage:coka_cola SET name='Coka Cola';
@allochi
allochi / keybase.md
Created July 21, 2022 09:08
keybase.md

Keybase proof

I hereby claim:

  • I am allochi on github.
  • I am allochi (https://keybase.io/allochi) on keybase.
  • I have a public key ASCzybnc48jTYii323iHq5UgEn2HWqU4xTfMZmJo-3vkdAo

To claim this, I am signing this object:

@allochi
allochi / awaitAny_tryout.nim
Created April 16, 2018 13:14
Trying to understand Nim awaitAny()
import threadpool, os, strformat
proc timer(d: int): int =
echo fmt"sleeping {d}"
sleep(d)
echo fmt"done {d}"
return d
var durations = [1000, 2000, 3000, 4000, 5000]
var tasks: seq[FlowVarBase] = @[]