Skip to content

Instantly share code, notes, and snippets.

View Szer's full-sized avatar

Ayrat Hudaygulov Szer

  • Thrive Global
  • Dublin, Ireland
  • X @omgszer
View GitHub Profile
@Szer
Szer / advent2023-1-2.fs
Last active December 1, 2023 12:31
Advent of Code 2023 1-2
let realFirstDigitRegex = Regex("one|two|three|four|five|six|seven|eight|nine|[0-9]")
let realLastDigitRegex = Regex("one|two|three|four|five|six|seven|eight|nine|[0-9]", RegexOptions.RightToLeft)
let matchToInt = function
| "one" -> 1
| "two" -> 2
| "three" -> 3
| "four" -> 4
| "five" -> 5
| "six" -> 6
@Szer
Szer / advent2023-1-1.fs
Created December 1, 2023 11:46
Advent of Code 2023 1-1
// https://adventofcode.com/2023/day/1
open System.Text.RegularExpressions
let firstDigitRegex = Regex("[0-9]")
let lastDigitRegex = Regex("[0-9]", RegexOptions.RightToLeft)
let sumOfCalibrationValues =
Seq.fold (fun acc (line: string) ->
let first = firstDigitRegex.Match(line).Value |> int
@Szer
Szer / CoreTracerProxy.kt
Last active September 25, 2023 13:34
DataDog reflection hack
package com.thriveglobal.tracing.proxy
import ddtrot.dd.trace.bootstrap.instrumentation.api.AgentScope
import ddtrot.dd.trace.bootstrap.instrumentation.api.ScopeState
import java.lang.reflect.InvocationHandler
import java.lang.reflect.Method
import java.util.concurrent.ConcurrentHashMap
// this class is needed because DataDog relocates classes on purpose, so they are not available through reflection
// to overcome that we are building dynamic proxies for this and all returned objects
@Szer
Szer / CacheDecorators.java
Created June 16, 2023 17:21
Keycloak patch for KC storages
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@Szer
Szer / JwtHelpers.kt
Last active June 6, 2023 12:01
Example of JWK creation
object JwtHelpers {
data class KeyPair(val public: RSAPublicKey, val private: RSAPrivateKey)
// we need static keyPairs for consistent testing
val rsaKeyPair = run {
// keySize = 512
// Choose two distinct prime numbers p and q.
val p = BigInteger("80015048226958274584861777197787136869318208410134237774308318008156105353397")
val q = BigInteger("84597213199129215561490406209976328146625812489295431631787994073201979267081")
namespace csharp
{
using System.Linq;
public class Skynet
{
static int children = 10;
static async Task<long> Loop(int level, long num)
{
@Szer
Szer / SAMLIdentityProviderWithCert.kt
Created May 5, 2023 13:45
SAML IDP with custom certificate
package com.thriveglobal.identity.keycloak.idp
import com.thriveglobal.identity.keycloak.utils.Utils.logger
import java.security.PrivateKey
import java.security.PublicKey
import java.util.*
import java.util.stream.Stream
import org.keycloak.broker.saml.SAMLIdentityProvider
import org.keycloak.broker.saml.SAMLIdentityProviderConfig
import org.keycloak.broker.saml.SAMLIdentityProviderFactory
package com.thriveglobal.connect.postgresql.junit
import com.thriveglobal.connect.postgresql.Env
import com.thriveglobal.env.CommonEnv
import java.time.Instant
import org.flywaydb.core.Flyway
import org.flywaydb.core.api.output.MigrateResult
import org.junit.jupiter.api.Tag
import org.junit.platform.engine.TestTag
import org.junit.platform.launcher.TestExecutionListener
@Szer
Szer / kestrel_script.fsx
Created July 11, 2022 13:39
Running Kestrel from scripts is simple, you only need to...
#r "nuget: Microsoft.AspNetCore.Server.Kestrel, 2.2.0"
#r "nuget: Microsoft.AspNetCore.Server.Kestrel.Core, 2.2.0"
#r "nuget: Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv, 2.2.0"
#r "nuget: Microsoft.AspNetCore.WebSockets, 2.2.0"
#r "nuget: Ply"
open System
open System.Net.WebSockets
open System.Text
open System.Threading
#r "nuget: FSharp.Control.AsyncSeq, 3.2.1"
open System
open System.Threading.Channels
open System.Threading.Tasks
open FSharp.Control
// это наша асинхронная операция
let doWork x = task {
do! Task.Delay 100