Skip to content

Instantly share code, notes, and snippets.

@ruseel
ruseel / monitor-identifier.applescript
Created September 13, 2025 03:00
macOS Monitor Identifier - Uses NSScreen API and CGDisplaySerialNumber for consistent monitor identification
#!/usr/bin/osascript
(*
Monitor Identifier for macOS
Uses NSScreen API and CGDisplaySerialNumber for consistent monitor identification
Use NSNumber instead of NSString format because CGDisplaySerialNumber returns
a uint32_t that gets converted to floating-point in AppleScript,
NSNumber's stringValue properly converts the floating-point back
to integer string.
#!/usr/bin/env python3
"""
Test script to browser-use.
This script attempts to:
1. Search for flights to Singapore on Google Flights
2. Set departure date to September 17th and return date to September 24th
3. Extract top 4 flight options in JSON format with keys:
airline, departure_time, arrival_time, duration, total_amount, route
"""
@ruseel
ruseel / a.clj
Created April 18, 2024 23:09
What file is raising MalformedInputException on slurp?
;; What file is raising MalformedInputException on slurp?
(use 'clojure.java.io)
(import 'java.nio.file.Files)
(import 'java.nio.file.Paths)
(import 'java.nio.charset.MalformedInputException)
(def directory? (memfn isDirectory))
(def name (memfn getName))
@ruseel
ruseel / README.md
Last active January 16, 2023 06:31
lacinia - resolve-promise - go,future,promesa/future,promesa/thread - {invoke,invoke-async}

lacinia 의 resolver 구성에 대해서 좀 더 알아야 (async 혹은 ThreadPoolExecutor) 의 동작을 이해할 수 있을 것 같습니다.

lacinia 에서 resolver 를 구현할 때 value 를 바로 리턴하도록 할 수도 있지만 ResolveResultPromise 를 리턴하게 할 수도 있습니다. [1] lacinia 에서 이것을 "Asynchronous Field Resolvers" 라고 부릅니다.

resolver 에서 ResolveResultPromise 를 리턴하게 만들 때는 아래와 같은 pattern 을 따릅니다.

(defn resolve-xyz
@ruseel
ruseel / emoji-subs.clj
Created November 18, 2022 10:29
substring java string with emoji
(import 'java.text.BreakIterator)
(defn break-index-seq [s]
(let [iter (doto (BreakIterator/getCharacterInstance)
(.setText s))
c (.first iter)
-seq (fn f [c iter]
(lazy-seq (when (not= c BreakIterator/DONE)
(cons c (f (.next iter) iter)))))]
(-seq c iter)))
@ruseel
ruseel / README.md
Created March 4, 2022 08:28
mitmproxy for gRPC server-streaming response

When you request gRPC through mitmproxy and the server responses with streaming client is not receiving that response.

Because mitmproxy tries to read entire response for manipulating opportunity.

So in that case, we can use '--set stream_large_bodies=1' option.

https://docs.mitmproxy.org/stable/overview-features/#streaming

@ruseel
ruseel / BUILD.bazel
Last active December 21, 2021 09:24
varticle/bazel-distribution deploy_maven example
load('@vaticle_bazel_distribution//maven:rules.bzl', "assemble_maven", "deploy_maven")
java_library(
name = "some_lib",
resources = glob(["src/test/resources/**/*"]),
tags = ["maven_coordinates=group_id:artifact:{pom_version}"],
)
assemble_maven(
name = "assemble",
import org.json4s._
import org.json4s.native.JsonMethods._
import org.json4s.native.Serialization
import org.json4s.native.Serialization.write
case class A(s: String, i: Int)
implicit val formats = Serialization.formats(NoTypeHints)
val a = A("a", 1)
@ruseel
ruseel / keycloak-rest-api-sample.clj
Last active August 27, 2023 18:17
Keycloak Admin REST API Sample
;; this worked for me
;;
(defn access-token []
(->
(client/post
(str base-url "/auth/realms/" realm "/protocol/openid-connect/token")
{:accept :json
:form-params {"client_id" "admin-cli"
"username" some-username
import random
import statsmodels
import pmap
groups = ["control", "treatment"]
POPULATION = 1e6
SAMPLE = 1e4
TRIES_PER_PERSON = 3