Skip to content

Instantly share code, notes, and snippets.

View Lance-DC's full-sized avatar

Lance Taylor Lance-DC

View GitHub Profile
@Lance-DC
Lance-DC / jq-cheetsheet.md
Created February 15, 2023 14:53 — forked from olih/jq-cheetsheet.md
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

#!/usr/bin/env bash
# This script will download a file from a directory in your Dropbox account.
# You will need to create a Dropbox App with this link: https://www.dropbox.com/developers/apps/create
# then get an Access Token for it. Once you have the token you can add it to the script.
# The file will be downloaded to your current directory and will overwrite any existing file with the same name.
if (($#<2))
then echo "Error! Usage: $(basename $0) <dropbox_dir> <dropboxfile>" && exit 1
fi
@Lance-DC
Lance-DC / serve.py
Created August 14, 2019 18:14 — forked from dustingetz/serve.py
serve static assets for frontend development, with http headers to disable caching
#!/usr/bin/env python
import SimpleHTTPServer
class MyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
@Lance-DC
Lance-DC / check4email.bash
Created April 25, 2019 14:49
Check user input for single valid email address
#!/bin/bash
# Validates user input for a single valid email address
echo -n "Please enter your email address: "
read -r
# use regex to find valid email address formats and store in new variable
userinput=$(echo "$REPLY" | grep -Eo "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b")
# check for no results from grep
if [[ -z "$userinput" ]]
then
@Lance-DC
Lance-DC / read-timeout.bash
Last active March 23, 2019 04:49
Two methods to timeout a read command in a shell script
#!/bin/bash
echo "The first method uses the TMOUT environment variable."
TMOUT=15
echo -n "You have 15 seconds to enter your name: "
read name
if [[ $name != "" ]]
then echo You entered: $name
else echo; echo "Nothing entered in time allowed."
fi
echo "Let's try again. This time using the -t option for read."
@Lance-DC
Lance-DC / essential-vi.md
Last active March 27, 2019 17:23
How to use vi effectively

Essential vi

  1. vi has multiple modes, and it starts in command mode, not editing mode.

In command mode, almost every key on the keyboard is mapped to run a specific command or movement, while other keys reference objects.

  1. Press i to get into insert mode, which allows you to edit the document
  2. Make your edits. Keys will behave as you would expect in any other text editor, including the Delete and Backspace keys.
  3. When you are finished editing, press Esc to return to command mode.
  4. To save and quit, while in command mode type :wq then press Enter. Alternately, if you want to discard your changes and quit, while in command mode type :q! then press Enter.

The : puts you in ex mode (some people call it "last line mode") which allows you to run ex commands as vi was an extension to the older ex editor. The w command writes the changes you made to the disk. (You can use the :w alone to save changes while you are working and keep working.) The q command quits the

Keybase proof

I hereby claim:

  • I am lance-dc on github.
  • I am lancetaylor (https://keybase.io/lancetaylor) on keybase.
  • I have a public key ASD2hOf8uivoOoUGMtf6bZJE_xhgAvNPiMJBwvtN2OOKBgo

To claim this, I am signing this object: