Skip to content

Instantly share code, notes, and snippets.

View seanpianka's full-sized avatar
🦀
Busy

Sean Pianka seanpianka

🦀
Busy
  • Somewhere in Cislunar Space
  • LinkedIn in/pianka
View GitHub Profile
@seanpianka
seanpianka / trailing_ws.vim
Last active October 22, 2019 17:17
vim: delete all trailing whitespace from files matching certain patterns using vimscript
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
for suffix in ["py", "js", "css", "cpp", "c", "h", "hpp", "rs", "groovy", "groovy.j2"]
execute 'autocmd BufWrite *.'.suffix.' :call DeleteTrailingWS()'
endfor
for prefix in ["Jenkinsfile"]
execute 'autocmd BufWrite '.prefix.'* :call DeleteTrailingWS()'
@seanpianka
seanpianka / yield_subgroups.py
Last active June 19, 2022 06:33
Python: create sublist by condition (Split a Python list into a list of lists where the lists are split around elements matching a certain criteria)
from itertools import islice, zip_longest
def yield_subgroups(group, subgroup_test):
subgroup = []
for i, j in zip_longest(group, islice(group, 1, None)):
if subgroup_test(i, j):
yield subgroup
subgroup = []
else:
@seanpianka
seanpianka / json_utils.go
Created December 2, 2019 15:48
Dynamically removing keys from an arbitrary JSON object or JSON object array in Go 1.13
import (
"encoding/json"
)
// Given an input slice of bytes representing an arbitrary JSON object and a slice of strings containing keys
// which should not exist in the input JSON object, remove these keys from original object.
func removeKeysFromJSONObject(input *map[string]json.RawMessage, keys []string) {
for _, key := range keys {
delete(*input, key)
}
@seanpianka
seanpianka / database.go
Created December 2, 2019 20:29
Database session middleware for Golang Echo API
const (
DatabaseConfigFile = "database.json"
DatabaseDriver = "mysql"
DatabaseKey = "db"
)
type DatabaseConfig struct {
Driver struct {
Database string `json:"dbname"`
Host string `json:"host"`
@seanpianka
seanpianka / in
Created January 16, 2020 21:10
Run a command within a directory
#!/bin/zsh
# Example: in $dir git status
(source ~/.zshrc; cd $1; ${@:2})