Skip to content

Instantly share code, notes, and snippets.

@jalex19100
jalex19100 / active_connection.sh
Created February 9, 2024 22:40
List active Linux TCP connections with only grep and awk
grep -v "rem_address" /proc/net/tcp | awk 'function hextonum(str, ret, n, i, k, c) {if (str ~ /^0[xX][0-9a-fA-F]+$/) {str = substr(str, 3);n = length(str);ret = 0;for (i = 1; i <= n; i++) {c = substr(str, i, 1);c = tolower(c);k = index("123456789abcdef", c);ret = ret * 16 + k}} else ret = "NOT-A-NUMBER";return ret} {y=hextonum("0x"substr($2,index($2,":")-2,2));x=hextonum("0x"substr($3,index($3,":")-2,2));for (i=5; i>0; i-=2) {x = x"."hextonum("0x"substr($3,i,2));y = y"."hextonum("0x"substr($2,i,2));} print y":"hextonum("0x"substr($2,index($2,":")+1,4))" "x":"hextonum("0x"substr($3,index($3,":")+1,4));}'
@jalex19100
jalex19100 / .zprofile
Created December 5, 2023 00:01
dot zprofile snippets (MacOS)
alias dockandbash='docker run --rm -ti --entrypoint /bin/bash '
alias forward80='socat tcp-l:80,fork,reuseaddr tcp:127.0.0.1:8080'
alias cleardns='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder'
alias clearaws='unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN'
alias aws_whoami='aws sts get-caller-identity'
alias aws_config_mgr_parameters="aws ssm get-parameters-by-path --path /ced/live/ --recursive | jq \'.Parameters[] | select(.Name) | {name: .Name, value: .Value}\'"
alias psa='ps auxww|grep '
alias hog='du -I".." -sk .* *|sort -n'
alias ll='ls -la'
alias tf='terraform'
#!/bin/bash
# https://raygun.com/blog/git-aliases/
# unstage files
git config --global alias.unstage 'reset HEAD --'
# stash changes including untracked files
git config --global alias.stash-unstaged 'stash -k -u'
# switch to previous branch
@jalex19100
jalex19100 / aws user-data to change default ssh port
Last active August 17, 2021 09:01
User-Data script for AWS, to change the default SSHD port from 22 to 2222, or 443, the same port HTTPS uses.
#!/bin/bash -ex
perl -pi -e 's/^#?Port 22$/Port 2222/' /etc/ssh/sshd_config
service sshd restart || service ssh restart
@jalex19100
jalex19100 / split_on_delimiter.sh
Created June 24, 2021 21:58
Split on Delimiter in bash
# https://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash
#!/usr/bin/env bash
IN="example@example;struff@stuff"
# Do something with each element separated by ;
IFS=';' read -ra ADDR <<< "$IN"
for i in "${ADDR[@]}"; do
# process "$i"
done
@jalex19100
jalex19100 / treat_touch_events_as_mouse_events.js
Created March 19, 2019 17:31
Treat touch events as mouse events. Useful for legacy code that you cannot change but could load a small piece to support touch events.
/* First we need to listen to touch events and call a function 'touch2Mouse' each time a touch event is fired:
*/
document.addEventListener("touchstart", touch2Mouse, true);
document.addEventListener("touchmove", touch2Mouse, true);
document.addEventListener("touchend", touch2Mouse, true);
/* The following function will initiate and fire mouse events (event.initMouseEvent), for each touch events type we'll fire the equivalent mouse event :
*/
Touchstart => Mousedown
Touchend => Mouseup
@jalex19100
jalex19100 / rust_info.md
Last active February 19, 2020 19:10
Rust Resources
@jalex19100
jalex19100 / self-destruct.js
Created January 22, 2014 17:47
Self-Destruct JavaScript function - executes the contents of the function once, but does nothing on any subsequent calls. Pretty straightforward.
var selfDestructMessage = function(element) {
// Do some stuff
selfDestructMessage = function(element) { /* Replace myself with an empty block */ }
};
@jalex19100
jalex19100 / git_last_commit.sh
Last active October 9, 2018 16:09
Show last commit on all git projects within a dir
# usage <scriptname> <directory below to look in>
find $1 -depth 2 -type d -name .git -execdir git log -1 --format=%cd" `pwd`" \;
@jalex19100
jalex19100 / open_fh_by_pid.sh
Created October 9, 2018 14:12
List open file count for all processes by PID
for i in `ps ax| cut -f1 -d\ |sort |uniq`;do echo -n "$i "; lsof -p $i|wc -l; done| sort -k 2