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 / 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})
@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 / 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 / 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 / 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 / intellij-vuejs-module-not-installed-error.txt
Last active March 12, 2022 08:05
JetBrains WebStorm vue.js, "Module is not installed", fix "@" in imports
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000556284/comments/360000146344
Specify the absolute path to `node_modules/@vue/cli-service/webpack.config.js` as a webpack config under `Languages & Frameworks / Javascript / Webpack`.
@seanpianka
seanpianka / setup_mac.sh
Last active September 1, 2019 12:42
Bash script to install everything needed for my Mac, save my configuration files
#!/bin/bash
SPECTACLE_VERSION="1.2"
RDM_VERSION="2.2"
install_brew=false
install_utils=true
install_dev_tools=true
install_webdev_tools=true
@seanpianka
seanpianka / vim-grep.zsh
Last active August 26, 2019 22:18
Combine vim and grep to quickly open files containing expression/pattern in vim
# vim-grep, open all files containing grepped string
function vim-grep {
GREP_OPTIONS="-rnw $1 -e $2"
for var in "${@:3}";
do
GREP_OPTIONS+=" --include \"$var\""
done
vim $(eval "grep $GREP_OPTIONS" | cut -f1 -d: | uniq | tr "\n" " ")
@seanpianka
seanpianka / .tmux.conf
Created August 13, 2019 18:08
tmux configuration file
bind J resize-pane -D 5
bind K resize-pane -U 5
bind H resize-pane -L 5
bind L resize-pane -R 5
bind M-j resize-pane -D
bind M-k resize-pane -U
bind M-h resize-pane -L
bind M-l resize-pane -R
@seanpianka
seanpianka / https_redirect.config
Created June 15, 2019 21:00
apache compression, https forward, cache expiration/cache control
files:
"/etc/httpd/conf.d/ssl_rewrite.conf":
mode: "000644"
owner: root
group: root
content: |
RewriteEngine On
<If "-n '%{HTTP:X-Forwarded-Proto}' && %{HTTP:X-Forwarded-Proto} != 'https'">
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</If>