Skip to content

Instantly share code, notes, and snippets.

View prestonp's full-sized avatar
😍
you had me at hello world

Preston Pham prestonp

😍
you had me at hello world
View GitHub Profile
@prestonp
prestonp / readme.md
Created July 28, 2022 18:46
project guidelines

Some thoughts on building software

  • For http services, instrument trace ids asap. New requests should either generate a randomized trace uid and store it in context or inherit one from a header
  • Always set up structured logging so that you can index and query by various properties
  • Set up global exception handling
  • Set up testing asap, even if project is early stage, it is easier to build for testing from the start rather than cobbling afterwards when there are possible roadblocks like global state, singletons, brittle interfaces and dependencies.
  • The higher up the callstack, the more abstraction and declarative a component should be. For example, things written inside the main() should be high level and semantic. More specific code can be more imperative, but it helps to have readability from the top of the program so that the big picture/taxonomy of components is readily apparent.
  • Unix philosophy is paramount and applies to many other contexts
  • Database migration on start up is a simple way of tac
@prestonp
prestonp / psuedocode
Created December 15, 2021 06:36
advent of code 2021 day 15
# assuming positions are 2-tuple of row, column coordinates
def shortest_risk(cave, risk_total = 0, current_position)
if is_exit(cave, current_position):
return risk_total + cave[current_position]
new_total = risk_total + cave[current_position]
new_cave = mark_cave_visited(cave, current_position)
left = [current_position[0], current_position[1] - 1]
right = [current_position[0], current_position[1] + 1]
@prestonp
prestonp / main.go
Last active December 8, 2020 09:54
quick golang log to file
import (
"fmt"
"log"
"os"
)
func debug(s string, o ...interface{}) {
f, err := os.OpenFile("/tmp/debug.log",
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
@prestonp
prestonp / redux-example.html
Last active May 29, 2018 18:01
redux example
<html>
<body>
<button onclick="s.dispatch('increment')">increment</button>
<button onclick="s.dispatch('decrement')">decrement</button>
<button onclick="unsubscribe()">unsubscribe</button>
<div id="main"></div>
<script>
function Store(reducer) {
this.reducer = reducer;
{
"bad_ips": [
"1.1.1.1",
"2.2.2.2",
"2606:4700:2001:10d:0:0:0:f"
]
}
@prestonp
prestonp / example.sh
Created October 3, 2017 21:27
go quine
go run quine.go > quine2.go
diff quine.go quine2.go
@prestonp
prestonp / org.golang.godoc.plist
Last active March 19, 2021 08:07
Run godoc in the background with launchd on osx
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.golang.godoc</string>
<key>EnvironmentVariables</key>
<dict>
<!-- set your gopath -->
<key>GOPATH</key>
@prestonp
prestonp / til.md
Last active October 31, 2016 17:05

you can mark comments on postgres tables and columns like what-what:

comment on table user is 'this table stores user info';
comment on column user.age is 'user age';

and view them in psql

@prestonp
prestonp / Form.jsx
Last active July 20, 2016 22:15
react validation
class TestForm extends React.Component {
constructor() {
super();
this.state = {
name: '',
address: '',
};
this.nameOnChange = this.nameOnChange.bind(this);
this.addressOnChange = this.addressOnChange.bind(this);