Skip to content

Instantly share code, notes, and snippets.

View danhodge's full-sized avatar

Dan Hodge danhodge

View GitHub Profile
@danhodge
danhodge / gpg.sh
Last active May 10, 2021 14:23
GPG Notes
# You need to add a GPG public key to your local keyring before you can use it (located in ~/.gnupg)
# You can specify a custom keyring file using the option --keyring <full_path_to_keyring>
# For commands that operate on the keyring (such as import, list, etc.) you also need to include --no-default-keyring to
# tell GPG to not look at/modify the default keyring
gpg --import <key>
# Generate key and add it to your default keyring
gpg --gen-key
# Encrypt - selects the key based on the recipient email (will be shown when you import the key)
# Basic Usage
# 1. SSH into remote host
# 2. $ screen
# 3. run commands
# 4. C-a C-d (detach)
# Write stdout to a logfile
# screen -L
# Attach to the existing session
@danhodge
danhodge / node.js
Last active October 5, 2021 02:02
node.js notes
// using the debugger
// 1. start with node inspect <script>
// 2. add debugger statement(s) in code
// 3. when execution stops on a debugger statement, use the repl command to get into a repl
// 4. use c <ENTER> to continue execution
// using the debugger + Jest
// 1. start with: node inspect $(npm bin)/jest <test.ts> --runInBand
// 2. same as steps 2-4 above
@danhodge
danhodge / notes.elm
Last active October 1, 2019 03:34
Elm Notes
-- JSON decoding
import Json.Decode
type alias Document = { message : String }
-- a decoder of type String that decodes the "message" field
message = Json.Decode.field "message" Json.Decode.string
-- a decode of type Document
doc = Json.Decode.map Document message
@danhodge
danhodge / aws.rb
Last active September 24, 2020 12:59
AWS SDK for Ruby Tips
# When using stubbed responses & a proc, you must explicitly pass in a proc - the implicit block parameter is ignored
# works
client.stub_responses(:get_object, proc { |context| { body: StringIO.new("Hi") } })
# does not work
client.stub_responses(:get_object) do |context|
# will never get here b/c the implicit block parameter is ignored
{ body: StringIO.new("HI") }
end
@danhodge
danhodge / git.md
Last active November 22, 2021 13:31
Git notes

Show Branches with Unpushed Commits

git log --branches --not --remotes --no-walk --decorate --oneline

Sync Local Branch with Remote After A Force Push To Remote

(or after your working copy of a branch gets out of sync with the remote branch for any reason)

git fetch
@danhodge
danhodge / emacs.el
Last active July 17, 2019 13:52
Emacs LISP Notes
; Use this to drop into a debugger when a error occurs: M-x toggle-debug-on-error
; Trying to figure out how namespaced elisp functions work: https://www.greghendershott.com/2017/02/emacs-themes.html
(defun dh/foo (x)
"adds 4 to x"
(+ x 4))
(dh/foo 1)
(defun dh/bar (x, fn)
"adds 5 to fn(x)"
(+ 5 (fn x)))
@danhodge
danhodge / rspec.rb
Last active May 27, 2020 19:42
RSpec tips and tricks
# Run specs with a given random seed
# rspec --seed <seed>
# Returning different values from consecutive stub invocations
allow(thing).to receive(:message).and_return(1, 2, 3, 4)
# Yielding multiple times from a test double
allow(thing).to receive(:each).and_yield(1).and_yield(2).and_yield(3).and_yield(4)
# Lightweight custom matcher
@danhodge
danhodge / sumo.md
Last active July 21, 2023 02:34
Sumo Logic query examples

Setting the source

_sourceName=*service* _sourceName=*service*env_name

JSON parsing

... | json auto | json auto field=message

JSON + where

... | WHERE field_name = <value>

@danhodge
danhodge / ssh.txt
Last active November 6, 2019 21:54
SSH notes
Establish a local SSH tunnel to a remote server
$ ssh -f <user>@<ip> -L <local_port>:<ip>:<remote_port> -N
Generate a SSH public/private key pair (4096 bits, with no comment at the end of the public key)
$ ssh-keygen -b 4096 -C ""
Extract the public key from a private key
$ openssl rsa -in private_key.pem -pubout # PEM formatted
$ ssh-keygen -y -f private_key.pem # SSH formatted