Skip to content

Instantly share code, notes, and snippets.

View preslavrachev's full-sized avatar

Preslav Rachev preslavrachev

View GitHub Profile
@preslavrachev
preslavrachev / claude_tokens.5m.py
Created July 18, 2025 07:38
An xbar plugin that displays your current Claude Code usage on your Mac's toolbar
#!/usr/bin/env python3
# <xbar.title>Claude Token Usage</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Preslav Rachev</xbar.author>
# <xbar.desc>Shows today's Claude Code token usage in the Mac toolbar</xbar.desc>
import json
import subprocess
import os
@preslavrachev
preslavrachev / do.go
Last active August 4, 2022 13:15
Do is an experiment in mimicking the Result type (known from languages like Rust and Haskell). The idea is to minimize the amount of error checking and let the developer focus on the happy path, without undermining the power of Go's errors. The code below requires Go 1.18+, as it makes use of generic type parameters.
package do
type Void struct{}
type Result[T any] interface {
Unwrap() (T, error)
}
type defaultResult[T any] struct {
val T
@preslavrachev
preslavrachev / README.md
Last active November 16, 2021 10:19
Generic Go Optionals

Goal

The goal of this experiment is to try and implement the minimum requirements for the existence of a generic-style Option type in Go, similar to what we know from other languages, such as Java or Rust.

Motivation

Provide a fluent approach to error handling in Go which focuses on highlighting the "happy path", while being 100% idiomatic with Go's error handling convention.

NOTE: The core type is an interface called Option, having a single requirement:

@preslavrachev
preslavrachev / duration.ex
Created April 10, 2021 13:14
Duration until a given date
def time_until_reset() do
today = :erlang.date()
now = :erlang.time()
now_in_sec = :calendar.datetime_to_gregorian_seconds({today, now})
days_until_next_monday = 8 - :calendar.day_of_the_week(today)
midnight = {0, 0, 0}
next_monday_in_sec =
:calendar.datetime_to_gregorian_seconds(
@preslavrachev
preslavrachev / Readme.MD
Last active January 2, 2021 07:30
A Simple Grayscale Filter in Golang

This is a simple grayscale filter implementening image.Image. It can be used in place where an image.Image is expected.

img, err := loadImage("input.jpg")
// check error

err := saveImage(&GrayscaleFilter{img})
//check error

Daily Idea: Use CNNs to Categorize Apps, Based on Their App Store Screenshots

The idea is rather simple and feasible, but as of this moment, not really useful. It just popped up in my mind, and I decided to write it down in case someone is looking for a ML challenge to work on. The idea is very simple:

  1. Use the iTunes Search API to download app screenshots and categorize them by folders, corresponding to the names of categories that those apps have been featured in.
  2. Teach a simple convolutional neural network (CNN) to categorize apps based on screenshots provided
  3. Try and evaluate the NNs capabilities using screenshots that are not present in the model.
// src/index.ts
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
ViewStyle,
TextStyle
} from 'react-native';
@preslavrachev
preslavrachev / kotlin-gradle-executable-jars.md
Created December 10, 2016 07:29
Kotlin Basics: Create Executable Kotlin JARs, using Gradle

Kotlin Basics: Create Executable Kotlin JARs, using Gradle

Kotlin is great for creating small command-line utilities, which can be packaged and distributed as normal JAR files. This short tutorial will show you how to:

  • Set up a Gradle project that supports Kotlin
  • Add a starting function
  • Configure your build to call this function when you execute your JAR.

Setting up Kotlin dependencies

@preslavrachev
preslavrachev / DateUtil.java
Last active December 9, 2016 10:27
A simple utility class for converting Date to Java 8's LocalDate and vice versa. Via: http://stackoverflow.com/questions/22929237/convert-java-time-localdate-into-java-util-date-type
public class DateUtil {
public static Date asDate(LocalDate localDate) {
return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
}
public static Date asDate(LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
@preslavrachev
preslavrachev / hamcrest-cheatsheet.md
Last active February 5, 2016 12:08
Hamcrest Cheatsheet

Hamcrest Cheatsheet

Collection Matchers

Check if a collection contains a single item

assertThat(collection, hasItem("item1"));
assertThat(collection, not(hasItem("item2")));