Skip to content

Instantly share code, notes, and snippets.

View jamesandariese's full-sized avatar

James Andariese jamesandariese

View GitHub Profile
@jamesandariese
jamesandariese / tmux-create-window-for-many-hosts-tj-edition
Last active September 9, 2015 18:05
tmux-create-window-for-many-hosts-tj-edition
#!/bin/sh
# A split window generator for tmux.
# Copyright 2014, James Andariese
# For what it's worth.
# MIT license.
# If things go wrong, it tends to leave either a single or many windows open with your local shell.
# I don't fix that because I don't care even a little bit.
# Don't do things wrong and be prepared to hit control D if you do. The cost of fixing is greater.
@jamesandariese
jamesandariese / bigawk.sh
Created March 6, 2015 05:45
Awk for apache logs, time stuff, too.
# awk field separator for a slightly customized apache access log (the :443 is the custom part)
awk -F ':443 |" |[][]| - - | [0-9][0-9]* "-"'
# For your average apache log with square brackets around the date, this will give you the log
# entries for the seconds around the entries you pipe into awk at the beginning
# replace BADNESS_HERE with whatever you want to find seconds around.
#
# NOTE: this can also be used to find things that happened within the seconds around 5 minutes
# before the event by changing s/$/p1-p2+p/ to s/$/300-p1-p2+p/ and other interesting
@jamesandariese
jamesandariese / README
Created March 7, 2015 04:54
Quick rockin' ssh tunnel!
You have a VPN to work.
You have a gateway host you're required to ssh through.
You have a mac.
You want SSHing to be fast, if possible.
10.0.0.10 is a fill in for the bastion host.
My name is James. Your name probably isn't.
10.11.12.13 is a fill in for my desktop.
If you're not connected to the VPN, it will just try and connect directly.
@jamesandariese
jamesandariese / dc.dc
Last active August 29, 2015 14:19
DC stuff
[Zd!=z]sz # delete top of stack
# perform a loop over all numbers running b
[lbx1+lax]sa # loop forever running b each time
[lpx]sb # logic goes here
1
lax
import string as Q,re ,re ,re ,re ,re ,re ,re ,re ,re ,re ,re ,re ,re ,re ,re
T = Q.maketrans( '0123456789.?)}]>#:,!({[<@;' ,'9876543210,!({[<@;.?)}]>#:' )
R ,_ ,_ ,_ ,_ ,_= re.compile ( '^(([a-zA-Z]+)|([0-9]+|.))(.*)$') ,1 ,1 ,1 ,1 ,1
def twist ( S ,r = ('' ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1)[ 0 ]):
S ,_ ,_ ,_ ,_ ,_ ,_ ,_ ,_ ,_ =' '.join ( S.split()) ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1
while S and ( 1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ) :
m ,_,_ ,_ ,_ ,_ ,_ ,_ ,_ ,_ ,_ ,Y= R.match(S),1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1
r +=(( (m.group ( 2 )or'' ).swapcase()[ : :-1 ]+ ( m.group ( 3 ) or'' ) ) )\
.translate ( * ( T ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1)[0:1] )
S=m.group ( (4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ) [ 0 ])
@jamesandariese
jamesandariese / fizzbuzz.c
Created April 18, 2015 03:03
dense fizzbuzz in C with no branches
#include <stdio.h>
int main() {
for (int i=1;;i++) printf("FizzBuzz\n\0 Buzz\n\0 Fizz\n\0 %d\n"+(0-i%3&16|0-i%5&32),i);
}
@jamesandariese
jamesandariese / decodesnmpdate.sh
Created April 24, 2015 00:44
decode snmp date from hex string
date -d "`grep -oE '[0-9A-F][0-9A-F]( [0-9A-F][0-9A-F]){10}' | sed -e 's/^/16i /' -e 's#$# Ai r 100* + sZ a sz Zd!=z ss 9 ss sM sh sd sm r 256* + sY [0]sN [[]]sB lZ 1000lZ<N 999lZ>B lz[ ] ls 10ls<N 9ls>B [:] lM 10lM<N 9lM>B [:] lh 10lh<N 9lh>B [ ] ld 10ld<N 9ld>B [/] lm 10lm<N 9lm>B [/] lY nnnnnnnnnnnnnnnnnnnn 10an f#'|dc`" "$@"
@jamesandariese
jamesandariese / fizzbuzz.py
Created August 24, 2015 21:53
Fizzbuzz in python
[print({0:'FizzBuzz',32:'Fizz',16:'Buzz'}.get(0-n%3&16|0-n%5&32,n)) for n in range(1,101)]
#
# 0001
# 1111
# 1100 & 1000 = 1000
#
# 1 & 1 = 1
# 1 & 0 = 0
# 0 & 0 = 0
@jamesandariese
jamesandariese / enumerate_users.sh
Created August 24, 2015 21:58
Iterate over possibly enabled users on remote host
#!/bin/sh
ssh -l root "$1" awk -F: "'\$2 ~ /^[^!*]/ {print \$1}'" /etc/shadow
for f in `ssh -l root "$1" cat /etc/passwd | cut -d ':' -f 1,6`;do
if ssh -l root "$1" [ -e "${f#*:}/.ssh/authorized_keys" ];then
echo "${f%:*}"
fi
done
@jamesandariese
jamesandariese / hash_file_by_name.py
Last active August 27, 2015 20:35
hash file by name
def hash_file_by_name(fn):
hash = hashlib.sha256()
with open(fn) as f:
block = f.read(1024*1024)
hash.update(block)
return hash.hexdigest()