Skip to content

Instantly share code, notes, and snippets.

View danhodge's full-sized avatar

Dan Hodge danhodge

View GitHub Profile
# just show the IP address
% dig <DNS_NAME> +short
@danhodge
danhodge / go.go
Last active November 13, 2024 14:39
Go Notes
// types and literals
// defines a new type (note - this is not a type alias, type aliases are a different thing)
type Thing int32
// this function only accepts arguments of type Thing, int32 arguments are not allowed by the compiler
func justThings(t Thing) {
// do stuff
}
@danhodge
danhodge / pytest.py
Last active September 21, 2023 14:35
Pytest Notes
# filter tests by name (works for standalone test functions or method names on a test class)
#
# pytest <test_file.py> -k test_foo
# pytest <test_file.py> -k 'test_foo or test_bar'
# run the same test multiple times with different parameters
@pytest.mark.parametrize("p1, p2", [(1, 2), (3, 4), (5,6)])
def test_foo(p1, p2):
assert bar(p1) == p2
@danhodge
danhodge / python.py
Last active September 14, 2024 02:12
Python Notes
# debugging
import pdb
pdb.set_trace()
# override a class method in a subclass (Python 2.x)
class Foo(object):
@classmethod
def baz(cls, x):
return x + 3
@danhodge
danhodge / macos.txt
Last active October 31, 2022 13:37
Mac OS Tips
Creating an Animated Gif Screen Recording
1. CMD+SHIFT+5 -> choose "Record Selected Portion"
2. Position box of region of screen being recorded
3. Hit Record
4. CMD+SHIFT+5 -> hit "Stop" button
4. Use Gifski application to convert movie file into animated gif
Find out which process is listening on <PORT>
sudo lsof -nP -i4TCP:<PORT> | grep LISTEN
@danhodge
danhodge / excon.rb
Last active February 25, 2021 22:32
# Excon exposes defaults for injecting configuration parameters
Excon.defaults[:mock] = true
Excon.defaults.delete(:mock)
# Excon stubbing
# first parameter - Hash of expected request attributes (all are optional)
# second parameter - Hash of response attributes
# if second parameter is omitted, a block can be provided a Proc object
Excon.stub({ method: :post, path: exp_path, headers: exp_headers, query: exp_query, body: exp_body }, { status: 200 })
To _not_ transitively update the dependencies of a gem when doing a bundle update, use --conservative
% bundle update --conservative <gem>
Install gems to a different path
bundle install --path .
Override a deployment packaged bundle (i.e. add new gems to a bundle already packaged for deployment)
bundle install --no-deployment
@danhodge
danhodge / notes.txt
Last active March 29, 2021 01:05
TypeScript Notes
Install
% npm install -g typescript
Start a new node.js project
% npm init
% npm install typescript -s
Add "tsc" script to package.json
"scripts": {
"tsc": "tsc"