Skip to content

Instantly share code, notes, and snippets.

@vsudilov
vsudilov / gist:a0f721b3249a7f4a6f94
Created May 29, 2014 15:31
grep over only certain file patterns
find directory/ -name 'glob_pattern' -exec grep -q 'search_pattern ' {} \; -print
@vsudilov
vsudilov / gist:926bf47a5245c0bacab1
Last active August 29, 2015 14:01
ssh 2-hop tunnel via localhost SOCKS
#SOCKS5 proxy via localhost:7070
#Tunnel over :9998
#host1: gateway machine
#host2: firewalled (destination) machine
ssh -f -N -L 9998:host2:22 host1; ssh -f -N -D 7070 localhost -p 9998
@vsudilov
vsudilov / gist:ba05178f31079957e855
Created May 12, 2014 18:09
filesystem over ssh tunnel through gateway (ssh+sshfs)
ssh -f -N -L 1233:remote.host:22 gateway.host
sshfs -p 1233 vsudilov@localhost:/nfs_mount /local/mountpoint -o reconnect
@vsudilov
vsudilov / find.py
Created May 9, 2014 15:10
Recursive find filename without glob (python)
#import fnmatch
#import os
matches = []
for root, dirnames, filenames in os.walk('/path/'):
for filename in fnmatch.filter(filenames, '*.py'):
matches.append(os.path.join(root, filename))
@vsudilov
vsudilov / mkdir_p.py
Created May 9, 2014 14:43
mkdir -p (python)
#import os,errno
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else: raise
@vsudilov
vsudilov / CD.py
Created May 9, 2014 14:42
Change directory context (python)
class cd:
"""
Context manager for changing the current working directory
with cd('/path'):
open('file_in_path')
"""
def __init__(self, newPath):
self.newPath = newPath