Skip to content

Instantly share code, notes, and snippets.

@pavgup
pavgup / server.py
Created June 16, 2023 20:27
using curl to send a file to a remote machine
# on the remote server you want to use to send a file, you run:
# curl -F "file=@/log.txt" http://100.100.100.100:8000/
# this will create the file log.txt in /tmp that will ideally containt he log.txt from the remote machine
from http.server import SimpleHTTPRequestHandler
import os
class FileUploadHandler(SimpleHTTPRequestHandler):
def do_POST(self):
content_length = int(self.headers['Content-Length'])
@pavgup
pavgup / cipherExtract.sh
Created August 27, 2020 04:24
programmatically extracting a bunch of files that have been mangled with ciphercloud
#/bin/bash
# This script looks for the first argument to be in single quotes and relative to the base (and obviously a ccsecure file!)
# CipherCloud is annoying, but not hard. Lets manipulate this to extract!
open /Applications/CipherCloud.app "$1"
# Lets find the parent directory for each file, to place the extracted file after done
parentdir="$(dirname "$1")"
@pavgup
pavgup / gist:30ba4b025126345cf7572e2835e5a329
Created February 7, 2020 19:49
move files to a hash of their contents
find . -name *.mp4 -exec md5sum '{}' ';' | while read sum file ; do cp "$file" /mnt/tmp-move/"$sum".mp4 ; done
@pavgup
pavgup / config
Created January 30, 2020 19:51
alice config
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRFNU1UQXlOREl4TURVd05Gb1hEVEk1TVRBeU1USXhNRFV3TkZvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBT3hZCnlxdEdseklVd2lYWVBKTGh4MFhsdnNtRUVYS1Zwa3NZMS9ESWdZdUFYWjRBeXk3KzAzcUVmOElUa3BSRVI3ZnQKbEt4cXZ6dmsvd3Mwc2R3UlZRcEhjUUttYUo3Z3l2ZWh4Zkg2Z1lCbWR5TW4rZ0Nwczh1Z3ZSUGNsZi9zc3NDZwo2TmJncUJxQTRVNklQeW9oSWo2T0EwV2FPb01ZRk1XM0FjZ3g0N05tb21HYm9BMG5pRk5vWW43VkNJYTh6U2I5CkdwNTJXb3JXZitCMi9TZm9LQVIzVEhyeWNrK0IzMmVDWkExSDV6bGN4MENrNE1LeXpNS0VKUDR3dEplZkRRNVcKMGhUUSthWEVJMmJwRnBmT3JiSThCTW1vZjladktVTzRkR0NHTEd1MFBXcEFNc0MydnV1K0piOW1lVHhXQkpsSQphRVNRQjFtUTN2MURHZ2Q4ZmtFQ0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFLYXNzK0NYbUVZdEM4dXh6cEFvRG56Tjh5NTAKcUt4RDlHaVFNRU0vRXJhVFp0My9aY3JncURUQlNUUURoN2J1TlRi
@pavgup
pavgup / gist:54211a6104fcf5fe63bf05d72dc1c95d
Last active January 30, 2020 15:33
recursive zip file extraction with dcm dropout? woo!
import zipfile
from pathlib import Path
# Pathlib Friendly (maybe required)
def extract(filename):
z = zipfile.ZipFile(filename)
for file in z.namelist():
# Ignore anything that's not a zip... and lets recurse
if ".zip" in file.lower():
# Create a subdirectory to hold our zip:
# This will use osd.5 as an example
# ceph commands are expected to be run in the rook-toolbox
1) disk fails
2) remove disk from node
3) mark out osd. `ceph osd out osd.5`
4) remove from crush map. `ceph osd crush remove osd.5`
5) delete caps. `ceph auth del osd.5`
6) remove osd. `ceph osd rm osd.5`
7) delete the deployment `kubectl delete deployment -n rook-ceph rook-ceph-osd-5`
8) delete osd data dir on node `rm -rf /var/lib/rook/osd5`
@pavgup
pavgup / gist:826289918d00fd041847d7cb5587854a
Created October 3, 2019 22:34
example of how to request network file storage and how to mount it
➜ ucsf-cdhi-pedfast cat ucsf-cdhi-pefast-cephfs.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ucsf-cdhi-pedfast-fs-pvc
namespace: ucsf-cdhi-pedfast
spec:
accessModes:
- ReadWriteMany
resources:
@pavgup
pavgup / nested-unzip.sh
Created September 16, 2019 13:55
Fusion Export Nested Unzipper
#!/bin/bash
# Nested Unzipping, Updated for MacOS Find Utility
# Pavan Gupta - September 16, 2019
# Drop this script into a directory with your zip file, execute, wait for nested directories
# TODO: Zips with zip files in them having the same name would
# cause unzip to drop files into the same directory causing collisions potentially
function extract(){
unzip $1 -d ${1/.zip/} && eval $2 && cd ${1/.zip/}
@pavgup
pavgup / aws-resource-count-ucsf.sh
Created November 20, 2018 23:29
Updated RedLock Count Resources (command line argument for credentials profile)
#!/bin/bash
aws_regions=(us-east-1 us-east-2 us-west-1 us-west-2 ap-south-1 ap-northeast-1 ap-northeast-2 ap-southeast-1 ap-southeast-2 eu-central-1 eu-west-1 sa-east-1 eu-west-2 ca-central-1)
echo "Total regions: "${#aws_regions[@]}
ec2_instance_count=0;
rds_instance_count=0;
elb_count=0;
elasticache_count=0;
redshift_count=0;
@pavgup
pavgup / move-all-files.sh
Last active September 15, 2018 21:56
Moving all jpegs to a single directory
### The first line simply moves the files using their existing filenames, if there is a complex tree structure with the same filenames, you overrwrite fies
find . -type f -exec file --mime-type {} \; | awk '{if ($NF == "image/jpeg") {split($0,a,":"); print a[1]}}' | xargs -I{} cp '{}' /Users/pavan/Dental/all-images
### The second line adds complexity by grabbing random strings and dropping renaming the copied files randomly:
find . -type f -exec file --mime-type {} \; | awk '{if ($NF == "image/jpeg") {split($0,a,":"); print a[1]}}' | xargs -I{} sh -c 'cp "{}" /Users/pavan/Dental/all-images/$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 64).jpg'