Skip to content

Instantly share code, notes, and snippets.

View johanastborg's full-sized avatar
🧭
Dreaming in Code

Johan Astborg johanastborg

🧭
Dreaming in Code
  • Sweden
View GitHub Profile
@johanastborg
johanastborg / company.proto
Created May 7, 2023 15:24
A Protobuf3 schema for a company with employees
syntax = "proto3";
message Company {
string name = 1;
repeated Employee employees = 2;
}
message Employee {
int32 id = 1;
string name = 2;
@johanastborg
johanastborg / msetredis.py
Created May 7, 2023 15:23
The mset command in Redis using Python
import redis
# Connect to Redis server
r = redis.Redis(host='localhost', port=6379, db=0)
# Set multiple keys using MSET command
r.mset({'name': 'John', 'age': '30', 'location': 'New York'})
# Retrieve the values of the keys
name = r.get('name')
@johanastborg
johanastborg / maxflow.cc
Created May 7, 2023 15:21
Calculting max flow in a graph in C++
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int INF = 1e9;
class Graph {
@johanastborg
johanastborg / dgraph.cc
Created May 7, 2023 15:21
A directed graph in C++
#include <iostream>
#include <vector>
using namespace std;
class Graph {
public:
int V; // number of vertices
vector<vector<int>> adjList; // adjacency list
@johanastborg
johanastborg / prefixtree.py
Created May 7, 2023 15:19
Implementation of a prefix tree (trie) in Python
class TrieNode:
def __init__(self):
self.children = {}
self.is_word = False
class Trie:
def __init__(self):
self.root = TrieNode()
def insert(self, word: str) -> None:
@johanastborg
johanastborg / hashimpl.cc
Created May 7, 2023 15:18
Implementation of a hash function using the FNV-1a hash
#include <string>
unsigned int fnvHash(const std::string& str) {
const unsigned int FNV_offset_basis = 2166136261;
const unsigned int FNV_prime = 16777619;
unsigned int hash = FNV_offset_basis;
for (std::size_t i = 0; i < str.length(); ++i) {
hash = (hash ^ static_cast<unsigned int>(str[i])) * FNV_prime;
}
@johanastborg
johanastborg / binarytree.cc
Created May 7, 2023 15:18
A binary tree in C++
#include <iostream>
using namespace std;
// Define a binary tree node
struct TreeNode {
int val;
TreeNode* left;
TreeNode* right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
import datetime
import re
#select * from sftp_1min_v3 where isin = 'AUDCAD' order by ts;
#select avg(value) from sftp_1min_v3 where isin = 'USDSEK';
#delete from sftp_1min_v2 where 1 > 0;
def format_date(p1, p2):
#Y = int(float(p1[0:4]))
#M = int(float(p1[4:6]))
#D = int(float(p1[6:8]))
import sqlalchemy
import os
# gcloud sql instances describe marketdata
# ./cloud_sql_proxy -instances=qvonto-lab:us-central-1:marketdata=tcp:5432
def init_db_connection():
db_config = {
'pool_size': 5,
'max_overflow': 2,

Using C++ as a language for Microservices

Here I try out Functions Framework for C++ on Google Cloud Run.

Motivation:
Provide small footprints (e.g. ~MB) and efficient execution (compared to scripting languages).

Result:
This can be used as an optimization strategy for enhancing performance once a prototype is in place.