Skip to content

Instantly share code, notes, and snippets.

synthetic_records = []
assert isinstance(synthetic_records, list) and len(synthetic_records) >= 20, \
"Gemini returned an unexpected format. Re-run or adjust the prompt."
# Traceback (most recent call last):
# File "<python-input-1>", line 1, in <module>
# assert isinstance(synthetic_records, list) and len(synthetic_records) >= 20, \
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# AssertionError: Gemini returned an unexpected format. Re-run or adjust the prompt.
import sys
from collections import defaultdict
def build_frequency_counts(text: str, n: int = 2) -> dict[tuple[list[str]], dict[str, int]]:
if n < 1 or n > len(text):
print(f"Error: n should be within 1 and {len(text)}, instead it is: {n}")
sys.exit(1)
counts = defaultdict(lambda: defaultdict(int)) # nested dict w/ a value set to 0
import sys
def extract_ngrams(text: str, n: int = 2) -> list[str]:
if n < 1 or n > len(text):
print(f"Error: n should be within 1 and {len(text)}, instead it is: {n}")
sys.exit(1)
if n == 1:
return list(text)
overall_failure_rate = 0.21052631578947367
f"Overall failure rate: {rate * 100:.2f}%"
# => 'Overall failure rate: 21.05%'
f"Overall failure rate: {rate:.2%}"
# => 'Overall failure rate: 21.05%'
Failure Mode Failure Rate
Incomplete Answer 10.5% (2/19)
Safety Violations 0.0% (0/19)
Unrealistic Tools 0.0% (0/19)
Overcomplicated Solution 0.0% (0/19)
Missing Context 5.3% (1/19)
Poor Quality Tips 15.8% (3/19)
@dskecse
dskecse / list_comprehension.py
Last active May 22, 2026 09:07
Fetching field values across the records in Python and Ruby
from dataclasses import dataclass
@dataclass
class FailureMode:
name: str
evaluation_criteria: str
failure_modes = [
FailureMode(name="incomplete_answer", evaluation_criteria="..."),
FailureMode(name="safety_violations", evaluation_criteria="..."),
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
@dskecse
dskecse / example.rb
Created December 26, 2025 14:28
Ruby 4.0 Ractor push type (send/receive) communication with Ractor::Port
# frozen_string_literal: true
p RACTOR_COUNT: Ractor.count # => 1
p IS_MAIN_RACTOR: Ractor.main? # => true
p Ractor.main # => #<Ractor:#1 running>
port = Ractor::Port.new
p port # => #<Ractor::Port to:#1 id:1>
Ractor.new(port) do |port|
p RACTOR_COUNT: Ractor.count # => 2
@dskecse
dskecse / rubybox.rb
Created December 26, 2025 13:18
Ruby 4.0 Box
# frozen_string_literal: true
X = 1
class Rubybox
def self.x = X
def x = ::X
end
# Usage:
@dskecse
dskecse / backup-analyze-redis.sh
Created February 20, 2025 15:35 — forked from hartleybrody/backup-analyze-redis.sh
backup a production redis URL to your local redis server (and analyze key usage)
# 1. download a copy of prod db to localhost
# connect to remote redis database and
# download a snapshot of the entire database
# to a local file on your filesystem
# via https://stackoverflow.com/a/61365048/625840
# docs https://redis.io/docs/manual/cli/#remote-backups-of-rdb-files
redis-cli -u $PROD_REDIS_URL --rdb dump.rdb