Skip to content

Instantly share code, notes, and snippets.

View spazm's full-sized avatar

Andrew Grangaard spazm

View GitHub Profile
spazm / 00_about.mkd
Last active April 25, 2023 19:57
Add trigger to update last modified column in postgres

Automated last updated columns -- postgresql


Create an updated_at timestamp column that is automatically updated whenever row values are changed in a postgresql database.


  • Modifying a column when a row is changed requires a BEFORE UPDATE TRIGGER on row updates.
  • A trigger can call a procedure
  • A function can create a trigger programatically.
spazm /
Last active October 13, 2021 07:31
Jacoby's Ladder
#!/usr/bin/env python3
import re
from pprint import pprint
def main():
begin = "cat"
end = "bar"
word_len = len(begin)
graph = build_graph(get_words(word_len))
spazm /
Last active May 4, 2020 02:43
Ransom Note (leetcode)
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; otherwise, it will return false.
Each letter in the magazine string can only be used once in your ransom note.
You may assume that both strings contain only lowercase letters.
canConstruct("a", "b") -> false
canConstruct("aa", "ab") -> false
spazm /
Last active May 1, 2020 21:03
code puzzles
// Provided code
// Definition for a binary tree node.
#[derive(Debug, PartialEq, Eq)]
pub struct TreeNode {
val: i32,
left: Option<Rc<RefCell<TreeNode>>>,
right: Option<Rc<RefCell<TreeNode>>>,
impl TreeNode {
spazm /
Last active April 30, 2019 01:01
matching brackets rust code. Attempt #2
pub fn brackets_are_balanced(string: &str) -> bool {
// second attempt/idea:
// push opening brace onto array
// pop array on close and check for match
// pop on empty => false
// not empty at end => false
// third attempt:
// make a hashmap of open/close remove code duplication in the
// close bracket logic
// Is this really the best way to make a fixed hashmap? Also, we
use itertools::Itertools;
use std::collections::HashMap;
/// Split a string into substrings of length sub_size
/// Final element may be shorter than sub_size
fn sub_strings(source: &str, sub_size: usize) -> Vec<String> {
spazm / ssh-rc
Last active January 23, 2019 20:15
ssh rc file ( `.ssh/rc` ) that symlinks ssh auth sock to a known location.
if [ -n "$SSH_AUTH_SOCK" ] ; then
if [ -L $MY_SSH_AUTH_SOCK ] && [ -e $MY_SSH_AUTH_SOCK ]; then
[ -n "$DEBUG" ] && echo "SSH_AUTH_SOCK is still valid"
[ -n "$DEBUG" ] && echo "linking SSH_AUTH_SOCK to $MY_SSH_AUTH_SOCK"
spazm / .vimrc
Last active October 21, 2020 18:42
vimrc code for setting light/dark from environment variable and zsh aliases to set the ENV
" check ITERM_PROFILE for 'DARK' or 'LIGHT' substrings, set background to match.
set background=dark
set background=light
spazm / 0: create the mapping
Last active August 17, 2016 23:49
elasticsearch: strings in integer field
curl -XPUT "https://localhost:9200/int_vs_str_test" -d '{"mappings": { "foo" : { "properties": { "label_id": { "type": "integer"}}}}}'
spazm /
Last active January 29, 2016 05:29
Check if git branch could be successfully merged via fast-forward.
set -e
# Check if HEAD and REF can be related by a fast-forward merge.
# Requires that either HEAD or REF be the merge-base between the two branches
usage () {
cat << EOM
$0 -v -h REF
Checks if HEAD and REF can be fast-forwared to each other.