Skip to content

Instantly share code, notes, and snippets.

ANCESTOR=123;
COMMIT_TO_CHECK=456;
git -C . merge-base --is-ancestor $ANCESTOR $COMMIT_TO_CHECK && echo 'IS ANCESTOR' || echo 'IS NOT ANCESTOR';
-- https://github.com/Big-Time-Data/blog-snippets/blob/main/loading-dynamic-csv-files-with-snowflake/snippets.sql
-- usage: call load_csv('@unit_test_data/bookings_ut_v3/expected/FACT.BOOKINGS.csv', 'FACT', 'BOOKINGS');
create or replace procedure load_csv(file_location varchar, target_schema varchar, target_table varchar) returns string language JAVASCRIPT strict EXECUTE AS CALLER AS
$$
const maxNumberOfColumns = 60 // max is 100 // not strict // TODO: query from target table and count
const exec = (sqlText) => {
stmt = snowflake.createStatement({sqlText});
return stmt.execute();
}
package wkhtmltoimage
import (
"errors"
"io/ioutil"
"os"
"os/exec"
"strconv"
"strings"
)
import * as crypto from "crypto";
export function verifyPassword(password, hashedPassword) {
const isValid = _compare(password, hashedPassword);
return isValid;
}
// https://stackoverflow.com/questions/27970431/using-sha-256-with-nodejs-crypto
function _compare(inputPassword, hashedPassword) {
const hashedInputPassword = crypto.createHash('sha256').update(inputPassword).digest('hex');
@adamilyas
adamilyas / UploadImageClient.js
Last active June 30, 2021 06:34
Upload file from axios to flask
class apiClient {
static uploadProfilePicture(file) {
var formData = new FormData();
formData.append("image", file);
formData.append("from", "frontend");
return postImage(`/user/upload`, formData).then((res) => res);
}
}
@adamilyas
adamilyas / object.go
Created March 15, 2021 10:25
unit tests in go (with mockery and testify)
package main
import (
"context"
"errors"
)
type object struct {
dependencyDAO DependencyDAO
}
@adamilyas
adamilyas / errors-is-with-wrapping.go
Created March 11, 2021 02:32
Handling errors with errors.Is() and error wrapping
package main
import (
"errors"
"fmt"
)
var (
errInvalid = errors.New("validation err")
errUploadFail = errors.New("upload err")

Simple HTTP Server using net/http package

Server

type response struct {
	Message string
}

func main(){

Learning Go: Return REST Response from struct/slice to JSON

We have a very simple REST server setup and access it via a GET request on http://localhost:8080/: \

func homeHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("[homeHandler]")
	fmt.Fprintf(w, "Hello World")
}
@adamilyas
adamilyas / golang-sync-basic-example.md
Last active October 17, 2020 06:06
Learning Go: Using sync package to handle concurrent write issues

Learning Go: Using sync package to handle concurrent write issues

We start of with a simple example: Iterate through and increment the value of the key

	counter := make(map[string]int)
	count := 1000

	for i := 0; i < count; i++ {
		counter["key"]++
	}