Skip to content

Instantly share code, notes, and snippets.

View shayelkin's full-sized avatar

Shay Elkin shayelkin

View GitHub Profile
@shayelkin
shayelkin / calendar-utils.gs
Created January 22, 2026 04:56
Google Apps Scripts: Calendar Utils
function colorBy(calId, colorRules) {
const cal = CalendarApp.getCalendarById(calId);
const startDate = new Date(); // now
const endDate = new Date();
endDate.setMonth(endDate.getMonth()+1);
const events = cal.getEvents(startDate, endDate);
for (const [ftype, param, color] of colorRules) {
let filtered = [];
@shayelkin
shayelkin / rg-gh.sh
Created January 21, 2026 22:44
A CLI replacement for GitHub code search.
#!/bin/bash
# A CLI replacement for GitHub code search.
# Requires: ripgrep, skim (sk), and bat.
github_remote_url=$(gh repo view --json url --jq '.url')
if [[ -z "$github_remote_url" ]]; then
echo "error: no github url for current repository."
exit 1
@shayelkin
shayelkin / refresh-adc.sh
Last active January 15, 2026 17:57
Refresh Google ADC credentials (if needed)
#!/bin/bash
# `gcloud auth application-default print-access-token` can also serve as a check
# but takes a few seconds to run. POSTing directly to Google's oauth endpoint is
# much faster.
function check_adc {
ADC_FILE="$HOME/.config/gcloud/application_default_credentials.json"
[ ! -f "$ADC_FILE" ] && return 1
@shayelkin
shayelkin / statusline-command.sh
Last active January 15, 2026 20:14
Status line hook for Claude Code that shows remaining plan usage
#!/bin/bash
# Read JSON input from stdin
input=$(cat)
# Uncomment to debug what fields are available:
#echo "$input" | jq '.' > /tmp/statusline-debug.json
# Initialize status parts array
status_parts=("$(echo "$input" | jq -r '.model.display_name')")
@shayelkin
shayelkin / erase-github-workflows.sh
Last active January 22, 2026 04:55
Mass erase Github Workflow runs
#!/bin/sh
gh run ls --all --workflow $1 --json databaseId -q ".[].databaseId" | xargs -n1 gh run delete
@shayelkin
shayelkin / threading.lisp
Created January 19, 2024 03:21
A lisp implementation of Clojure's threading macro
(defmacro -> (form &rest forms)
(reduce
(lambda (acc next)
(if (listp next)
(list* (car next) acc (cdr next))
(list next acc)))
forms
:initial-value form))
@shayelkin
shayelkin / aoc-2020-day-4.clj
Created December 5, 2020 04:55
AoC 2020 Day 4. Solve by generating a huge regex
;; AoC 2020 Day 4. Solve by generating a huge regex.
(require '[clojure.string :as s])
(def sample-passports
"ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
@shayelkin
shayelkin / is_pow_of_2.c
Last active July 26, 2019 07:57
Four methods to test if an integer is a power of two.
/**
* Four methods to test if an integer is a power of two.
* Compile with `-march=haswell`.
*/
#include <stdlib.h>
#include <stdio.h>
#include <immintrin.h>
#include <time.h>
@shayelkin
shayelkin / soduko.py
Last active May 21, 2019 18:18
Soduko solver. Everybody writes one.
#!/usr/bin/env python2
"""
Soduko solver. Everybody writes one.
"""
sample = "003020600900305001001806400008102900700000008006708200002609500800203009005010300"
all_bits = int('1'*9,2)
def load_puzzle(s):
@shayelkin
shayelkin / tomer-numbers.clj
Last active November 23, 2018 20:30
Ratio of non primes naturals <100 that only have primary divisors
;; https://twitter.com/sartanbegavhaum/status/1066051737650429952
(defn non-trivial-factors [n]
(filter #(zero? (mod n %)) (range 2 n)))
(def prime? (comp empty? non-trivial-factors))
(defn tomer-number? [n]
(when-let [facts (seq (non-trivial-factors n))]
(every? prime? facts)))