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 / gist:ad5d1a3f9a026e34c44c
Last active May 13, 2024 11:40
mov to webm osx
@prestonp
prestonp / query.sql
Created October 16, 2014 17:21
postgres update return new values and old values
-- returning updated values and old values by using a sub-expression
update orders
set type = 'delivery'
where id = 3767
returning id, type, (
select type from orders where id = 3767
) as old_type;
@prestonp
prestonp / pg-change-timezone.md
Last active October 21, 2022 16:26
Change timezone in pg

Changing timezone in postgres

To change your server’s timezone per session you can use the following query:

set timezone TO 'GMT';

If you need to permanently update the timezone, find your postgresql.conf file in psql:

@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 / 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 / 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"
]
}