Skip to content

Instantly share code, notes, and snippets.

View hkupty's full-sized avatar

Henry John Kupty hkupty

View GitHub Profile
@hkupty
hkupty / count.zig
Created October 4, 2025 21:37
Testing count scalar
const std = @import("std");
const findScalarPos = std.mem.indexOfScalarPos;
/// Returns the number of needles inside the haystack
pub fn countScalar(comptime T: type, haystack: []const T, needle: T) usize {
var i: usize = 0;
var found: usize = 0;
while (findScalarPos(T, haystack, i, needle)) |idx| {
i = idx + 1;
@hkupty
hkupty / x_json.sh
Created December 3, 2021 12:37
bash function to extract json values, either using stdin or argument
function x_json() {
jq -creM "${1}" <([ -z ${2+x} ] && cat - || echo "${2}")
}
package benchmarks.regex;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
public class ReplaceBenchmark {
@hkupty
hkupty / dynamic-protobuf-to-clojure.clj
Last active February 20, 2020 06:15
Transforming java proto instances in clojure maps
;; The main function is `protobuf->map`, which performs the transformation.
;; Runtime reflection can be avoided if class is known beforehand.
;; The macro is completely optional, though it makes things *slightly* easier to read:
;; (protobuf->clj instance OuterClass$InnerClass) vs (protobuf->map instance (OuterClass$InnerClass/getDescriptor))
(defn- *proto->fields
"Get fields from protobuf object's descriptor as clojure keywords"
[descr]
(map #(keyword (.getName %))
(.getFields descr)))
# Default config for sway
#
# Copy this to ~/.config/sway/config and edit it to your liking.
#
# Read `man 5 sway` for a complete reference.
### Variables
#
# Logo key. Use Mod1 for Alt.
set $mod Mod4
@hkupty
hkupty / select-oath
Created December 18, 2019 08:21
Select yubikey oath on rofi - so I don't have to go to the terminal
#!/bin/bash
set -euo pipefail
ykman info > /dev/null
SELECTED=$(ykman oath list | rofi -dmenu)
if [ -n "${SELECTED}" ]; then
ykman oath code ${SELECTED} | awk '{ print $NF }' | xsel -b
fi
@hkupty
hkupty / git-chk
Created December 18, 2019 08:19
Fuzzy-find branches in git repo
#!/bin/bash
set -euo pipefail
# TODO Fix multiple remotes
readarray LOCAL <<< $(git branch --no-color | awk '{print $NF}')
readarray REMOTE <<< $(git branch -r | sed 's/.*origin\///g')
REMOTE_ONLY=($(echo ${LOCAL[@]} ${LOCAL[@]} ${REMOTE[@]} | tr ' ' '\n' | sort | uniq -u))
@hkupty
hkupty / ceq
Created December 18, 2019 08:18
jq for edn
#!/bin/sh
#_(
DEPS=''
OPTS='
-J-Xms256m -J-Xmx256m -J-client
'
exec clojure $OPTS -Sdeps "$DEPS" "$0" "$@"
)
(require '[clojure.edn :as edn]
@hkupty
hkupty / git-fzchk
Created April 9, 2019 09:04
Fuzzy-find branches to git checkout
#!/bin/env bash
# Requires https://github.com/junegunn/fzf
git checkout "$(git branch | awk '{print $NF}' | fzf)"
" Code Completion
Plug 'shougo/deoplete.nvim'
" Plug 'roxma/nvim-completion-manager'
" Snippets
Plug 'shougo/neosnippet.vim'
Plug 'shougo/neosnippet-snippets'
" Ctags