Skip to content

Instantly share code, notes, and snippets.

View mortymacs's full-sized avatar

Morteza NourelahiAlamdari mortymacs

View GitHub Profile
@mortymacs
mortymacs / a.c
Created April 11, 2024 16:45
Release heap memory when it goes out of scope in C
// gcc a.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void clean_name(char **name) {
printf("clean clean!");
free(*name);
}
@mortymacs
mortymacs / aggregation.sh
Last active February 5, 2024 22:26
Sample AWK
#!/bin/sh
# Iterate over a csv file and aggregate items.
# in BEGIN we define global variables.
# in the middle block we define the logic.
# in the END we define the conclusion logic like prints etc.
# NR>1 means ignore the first line.
awk -F "," 'BEGIN {
delete visited_items;
}
NR>1 {
@mortymacs
mortymacs / shell.nix
Created January 19, 2024 15:09
Shell nix empty structure
{ pkgs ? import <nixpkgs> {} }:
# { pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-23.11.tar.gz") {} }:
with pkgs;
mkShell {
nativeBuildInputs = [
];
@mortymacs
mortymacs / initdb.json
Last active January 16, 2024 14:55
DynamoDB aws-cli sample
{
"TableName": "Users",
"KeySchema": [{
"AttributeName": "ID",
"KeyType": "HASH"
}],
"AttributeDefinitions": [{
"AttributeName": "ID",
"AttributeType": "S"
}],
@mortymacs
mortymacs / readme.md
Created December 22, 2023 20:32
localstack and aws-cli local config

Run localstack docker:

docker run -d --rm \
                -p 4566:4566 -p 4510-4559:4510-4559 \
                --name localstack \
                localstack/localstack

Add aws cli config:

@mortymacs
mortymacs / CMakeLists.txt
Created December 5, 2023 00:30
Sample cmake thirdparty + ide for a C++ project
cmake_minimum_required(VERSION 3.25.0)
project(HelloWorld)
# Enable for IDE
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Download thirdparty
include(FetchContent)
FetchContent_Declare(
tomlplusplus
@mortymacs
mortymacs / main.go
Created November 7, 2023 16:34
Find what data type is behind the any in Go
package main
import "fmt"
func GetData() any {
a := map[string]any{
"name": map[string]any{
"age": 1,
},
}
@mortymacs
mortymacs / enable-if.cc
Created November 4, 2023 19:59
Sample std::enable-if in c++
#include <iostream>
#include <string>
#include <type_traits>
// Custom data structures.
struct Car{
std::string name;
};
struct Bike{
std::string name;
@mortymacs
mortymacs / sample.sh
Created November 4, 2023 19:52
Temporal CLI sample commands
# Create a namespace
$ tctl --ns <NAMESPACE> n re
# Get namespace description.
$ tctl --ns <NAMESPACE> n desc
# Send a request to the workflow.
$ tctl workflow run --taskqueue <TASK-QUEUE> --workflow_type <WORKFLOW-NAME> --input '{"name": "something", "foo": "bar"}'
# Get list of workflows.
@mortymacs
mortymacs / main.go
Created November 1, 2023 09:34
DynamoDB sample Go code
package main
import (
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"