Skip to content

Instantly share code, notes, and snippets.

@giuliohome
giuliohome / db.go
Last active April 16, 2024 20:39
Connections count while concurrent goroutines run inside a DB conn pool
package main
import (
"database/sql"
"fmt"
"log"
"sync"
"time"
_ "github.com/lib/pq"
@giuliohome
giuliohome / latest.sh
Last active April 3, 2024 12:04
dotnet on gitpod
see https://learn.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#scripted-install
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x ./dotnet-install.sh
./dotnet-install.sh --version latest
/home/gitpod/.dotnet --version
/home/gitpod/.dotnet/dotnet clean
/home/gitpod/.dotnet/dotnet build
@giuliohome
giuliohome / unit_test.bat
Created November 15, 2023 08:46
python unit test with one's company's ssl root cert on windows
set CURL_CA_BUNDLE=C:\path\to\mycompanyCA.pem
set PYTHONPATH=src
python -m unittest test\mytest.py
@giuliohome
giuliohome / ubuntu-sleep.yaml
Created November 1, 2023 16:52 — forked from tcdowney/ubuntu-sleep.yaml
Ubuntu Sleep Pod
apiVersion: v1
kind: Pod
metadata:
name: ubuntu
labels:
app: ubuntu
spec:
containers:
- image: ubuntu
command:
@giuliohome
giuliohome / soap_call.py
Last active October 21, 2023 14:22
calling a wsdl service from python
from zeep import Client
wsdl = 'http://www.dneonline.com/calculator.asmx?WSDL'
arg = {'intA':2, 'intB':3}
op = 'Add'
client = Client(wsdl)
res = client.service[op](**arg)
print(res) # 5
@giuliohome
giuliohome / async_loop.py
Last active October 3, 2023 12:09
The script simulates a scenario where certain activities depend on others as weak dependencies and may be restarted if the dependencies are completed.
import asyncio
# weak dependencies list as (dependency, dependent)
weak_deps = [(2,3),(4,1)]
# e.g. let's say activity 2 updates input of activity 3 as a weak dependency, etc...
async def gather_with_first_completed(awaitable_results):
# Create a list to store the completed results
completed_results = []
@giuliohome
giuliohome / workflow.hs
Last active October 1, 2023 20:15
Async Workers with Condition Handling
import Control.Concurrent.STM
import Control.Monad
import Control.Concurrent
workerWaitForCondition :: TVar Bool -> IO ()
workerWaitForCondition condition = atomically $ do
c <- readTVar condition
unless c retry
workerMakeConditionTrue :: TVar Bool -> IO ()
package io.github.nomisrev
import app.cash.sqldelight.driver.jdbc.asJdbcDriver
import arrow.continuations.SuspendApp
import arrow.continuations.ktor.server
import arrow.fx.coroutines.autoCloseable
import arrow.fx.coroutines.closeable
import arrow.fx.coroutines.resourceScope
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
@giuliohome
giuliohome / scala-http-postgres-html-docker.scala
Created September 30, 2023 08:18 — forked from keynmol/scala-http-postgres-html-docker.scala
Sample gist showing how to run a HTTP server with Typelevel Scala libraries, and a postgres docker container
//> using dep "org.http4s::http4s-scalatags::0.25.2"
//> using dep "org.http4s::http4s-dsl::0.23.23"
//> using dep "org.http4s::http4s-ember-server::0.23.23"
//> using dep "org.tpolecat::skunk-core::0.6.0"
//> using dep "com.dimafeng::testcontainers-scala-postgresql::0.41.0"
//> using dep "com.outr::scribe-slf4j::3.12.2"
import skunk.*, codec.all.*, syntax.all.*
import cats.effect.*
import scalatags.Text.all.*
open Donald
open System.Data.Common
open System.Data.SQLite
open System.Threading.Tasks
open Giraffe
open Giraffe.ViewEngine
open FsToolkit.ErrorHandling
open Microsoft.AspNetCore.Builder
[<RequireQualifiedAccess>]