Skip to content

Instantly share code, notes, and snippets.

View shollingsworth's full-sized avatar

Steven Hollingsworth shollingsworth

  • SkySafe.io
  • United States
  • X @_stevo
View GitHub Profile
@shollingsworth
shollingsworth / gist:f34205663345e2b31682
Created October 12, 2014 15:58
bash find files in current directory sorted by last modified time
#find and sort by modified time
find . -type f -printf "%T@::%t::%p\n" | sort -n
#Grab the last 5 modified files
find . -type f -printf "%T@::%t::%p\n" | sort -n | awk -F '::' '{print $3}' | tail -n5
@shollingsworth
shollingsworth / RedCache.php
Last active August 29, 2015 14:07
initial Redis Thinger (RedCache)
<?php
/**
* RedCache : Redis Cacher Interface
* @version 2014-10-20 13:16
* @author Steven Hollingsworth <steven.hollingsworth@fresno.gov>
*/
/** Set Constants and default path for all includes */
if(!@include_once("{$_SERVER['PHP_REPORT_BASE_DIR']}/include/_constants.php")) { print "Could not Load standard include file. Bailing...\n<br>"; exit(99); }
@shollingsworth
shollingsworth / gist:80eab8ec07ae9edffe97
Created August 3, 2015 14:03
find all file extension types in current directory
find -type f | while read i; do bn=$(basename ${i}); echo ${bn##*.}; done | tr 'A-Z' 'a-z' | sort | uniq
hello_world/
echo "hello world"
current_working_directory/
pwd
list_files/
ls
print_file_contents/
cat access.log
last_lines/
tail -n5 access.log
@shollingsworth
shollingsworth / .vimrc
Created July 12, 2017 20:38
my vimrc script editing environment wrappers
autocmd FileType * exe('let comp_cmd="!~/.vim/bin/build_' . &filetype . '.sh ' . expand("%:p") . '"')
autocmd FileType * exe('let run_cmd="!~/.vim/bin/build_' . &filetype . '.sh ' . expand("%:p") . ' \|less -cN"')
map z :exec comp_cmd<enter><enter>
map R :exec run_cmd<enter><enter>
@shollingsworth
shollingsworth / duration_string_to_seconds.sh
Created December 21, 2017 19:09
convert duration string like: 2d3h5m30s into seconds only (bash)
#!/usr/bin/env bash
test_str="1h5m"
test_str="5d3h2m50v" #bad
test_str="5d3h2m50s"
declare -A keys
keys[d]=$((60 * 60 * 24))
keys[h]=$((60 * 60))
keys[m]=60
keys[s]=1
@shollingsworth
shollingsworth / duration_string_to_seconds.py
Created December 21, 2017 19:10
convert duration string like: 2d3h5m30s into seconds only (python)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
test_str = "1h5m"
test_str = "5d3h2m50s"
keys = {
'd' : 60 * 60 * 24,
'h' : 60 * 60,
'm' : 60,
@shollingsworth
shollingsworth / slack-create-pyclass.py
Last active June 26, 2018 05:25
Create a slack data object given the raw json output ` ./slack-create-pyclass.py -f user.json User`
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import argparse
import json
import select
import sys
LOG = logging.getLogger()
LOG.setLevel(logging.DEBUG)
@shollingsworth
shollingsworth / glucose_brain_burn_rate.py
Last active November 30, 2018 02:52
Convert weight in lbs to stats about glucose replacement for your brain.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Convert weight in lbs to stats about glucose replacement for your brain."""
# After reading reading "Thinking, Fast and Slow"
# by Daniel Kahneman
#
# Based docs from https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3900881/
# and
# https://www.nutritionix.com/food/light-corn-syrup
from __future__ import unicode_literals
@shollingsworth
shollingsworth / loopback_file_demo.sh
Created September 6, 2019 18:47
MagicRescue Demo for RootAccess Sept 2019
#!/bin/bash
size_mb="50"
dest_file=$(mktemp)
mount_dir=$(mktemp -d)
dd if=/dev/urandom of=${dest_file} bs=1M count=${size_mb}
echo "destfile ${dest_file} crated"
lodev=$(losetup --show -f ${dest_file})
echo "loopback ${lodev} created"
mkfs.ext4 ${lodev}