Skip to content

Instantly share code, notes, and snippets.

@jhn--
jhn-- / coords_to_shots.rs
Last active June 9, 2022 11:41
trying out of code (refactor and tinkering) with regards to exercise G of repo ultimate_rust_crash_course
#![allow(unused_variables, unused_mut, dead_code)]
#[derive(Debug)]
enum Shot {
// 3 classifications of accuracy for the Shot
Bullseye,
Hit(f64),
Miss,
}
#!/bin/bash
directories=("/path/to/dir1" "/path/to/dir2")
for i in ${directories[@]};
do
if [ -d $i ]
then
echo "$i is around"
rm -fr $i
@jhn--
jhn-- / process_snapshot.bash
Last active January 27, 2016 10:54
Grabs a list of processes currently running and saves list into /var/log/process_snapshots
#!/bin/bash
#set -x
snapshot(){
now=$(date +%F_%H:%M:%S)
ps -e -o user,uid,pid,ppid,class,rtprio,ni,pri,psr,c,pcpu,pmem,vsz,rss,start,time,etime,stat,wchan=wwwwwwwwwwwwwwwwwwwwww,cmd --sort=user | grep -Evi 'root|bash|ssh' > $where/process_$now.log;
}
go(){
#!/usr/bin/env python
import grp
import json
import logging
import optparse
import os
import pwd
import re
import subprocess
@jhn--
jhn-- / gitpullall.sh
Created December 2, 2015 03:52
bash script to blindly traverse every subfolder and execute a git pull
#!/bin/bash
for i in `find . -maxdepth 1 -mindepth 1 -type d`; do cd $i; git pull; cd ..; done
@jhn--
jhn-- / gfid-resolver.sh
Created December 1, 2015 05:06 — forked from louiszuckerman/gfid-resolver.sh
Glusterfs GFID Resolver Turns a GFID into a real path in the brick
#!/bin/bash
if [[ "$#" < "2" || "$#" > "3" ]]; then
cat <<END
Glusterfs GFID resolver -- turns a GFID into a real file path
Usage: $0 <brick-path> <gfid> [-q]
<brick-path> : the path to your glusterfs brick (required)
@jhn--
jhn-- / gist:4e3e2cbf3d7998a324b7
Last active September 17, 2015 06:41 — forked from bortzmeyer/gist:1284249
The only simple way to do SSH in Python today is to use subprocess + OpenSSH...
#!/usr/bin/python
# All SSH libraries for Python are junk (2011-10-13).
# Too low-level (libssh2), too buggy (paramiko), too complicated
# (both), too poor in features (no use of the agent, for instance)
# Here is the right solution today:
import subprocess
import sys
@jhn--
jhn-- / bankaccounts.py
Last active October 30, 2015 22:01
Silly bank account program
class BankAccount(object):
"""docstring for BankAccount"""
def __init__(self, amount = 0.0):
self.balance = float(amount)
self.history = {}
self.recordhistory("Account Open", amount = self.balance, balance = self.balance)
def __repr__(self):
return repr(self.balance)