>>> from urllib.parse import urljoin
>>> urljoin('http://example.com/', '1')
'http://example.com/1'
>>> urljoin('http://example.com/', '2629:1828:4025')
'2629:1828:4025'
Better not try to urljoin anything with a colon in it!

Adventures in Computer Programming – bakert@gmail.com
>>> from urllib.parse import urljoin
>>> urljoin('http://example.com/', '1')
'http://example.com/1'
>>> urljoin('http://example.com/', '2629:1828:4025')
'2629:1828:4025'
Better not try to urljoin anything with a colon in it!
I was encountering a situation where big aggregating queries that took seconds on local were taking minutes or even hours on prod. After trying about a million things this Stack Exchange post finally cleared things up.
Setting innodb_buffer_pool_size = 5G in MariaDB’s configuration and restarting instantly changed the queries to taking seconds. The default is 128M which is … not useful 🙂
Save this as “ssh” somewhere on your $PATH ahead of /usr/bin/ssh and make it executable
#!/bin/sh
HOSTNAME=$(echo $@ | sed 's/.*@//')
set_theme () {
osascript -e "tell application \"Terminal\" to set current settings of first window to settings set \"$1\""
}
on_exit () {
set_theme "Solarized Light"
}
trap on_exit EXIT
case $HOSTNAME in
# These all do the same thing but we could have different themes for different locations
hb|pd|decksite) set_theme "Solarized Dark" ;;
*) set_theme "Solarized Dark" ;;
esac
/usr/bin/ssh "$@"
Previously:
July 2019,
July 2022
# Respectively, fully-qualified hostname, Bonjour hostname, the user-friendly computer name you see in Finder, flush the DNS cache … $ sudo scutil --set HostName agrajag.bluebones.net $ sudo scutil --set LocalHostName agrajag $ sudo scutil --set ComputerName agrajag $ dscacheutil -flushcache
"trim_trailing_white_space_on_save": true in sublime prefs, install Package Control, install Solarized Theme).$ ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/u/bin/subl{ "keys": ["super+shift+i"], "command": "exclude_ignored" }{ "keys": ["super+shift+w"], "command": "toggle_setting", "args": { "setting": "word_wrap" } }"font_face": "Fira Code".$ defaults write com.apple.finder CreateDesktop false$ killall Finderbrew install mariadbbrew install npm brew install apache2. Docker Desktop (below) uses port 8080 so edit /opt/homebrew/etc/httpd/httpd.conf to use port 8081 and remember that you did it.brew install php. Enable in Apache with LoadModule, FilesMatch and DirectoryIndex directives as per homebrew output and brew services restart apache2.brew install ghbrew install composernpm install -g rtm-clidefaults write -g ApplePressAndHoldEnabled -bool falsegit clone important repos (ff, pd, server)ln -s ~/ff/src/www /opt/homebrew/var/www/ffGRANT ALL ON ff.* TO ff@localhost IDENTIFIED BY *REDACTED*Harvard’s CS50 course available to take entirely for free online.
“rust cargo unable to update registry attempted ssh-agent authentication, but no usernames succeeded: `git`”
I got this error trying to cargo build with a new dependency in the manifest. Fixed with:
eval `ssh-agent -s` ssh-add cargo build
Via github.com/rust-lang/cargo/issues/3381#issuecomment-308460530
Also known as Noughts and Crosses.
A Rust program to generate all terminal positions of the game of Tic-Tac-Toe. Rotations, transpositions, games-still-in-progress and impossible board states are not shown.
use std::collections::HashMap; const EMPTY: char = ' '; const X: char = 'X'; const O: char = 'O'; type Boards = HashMap; type Board = [[char; 3]; 3]; type Representations = [String; 8]; trait BoardMethods { fn display(&self) -> String; fn is_terminal(&self) -> bool; fn representation(&self) -> String; fn all_representations(&self) -> Representations; fn rotate(&self) -> Board; fn transpose(&self) -> Board; } trait BoardsMethods { fn contains(&self, b: Board) -> bool; fn insert_board(&mut self, b: Board); } fn main() { test(); let empty_board: Board = [[EMPTY; 3]; 3]; let mut final_boards: Boards = HashMap::new(); let boards: Vec = all_boards(empty_board, X); for board in boards { if board.is_terminal() && !final_boards.contains(board) { final_boards.insert_board(board); } } println!("{} unique terminal boards found\n", final_boards.len()); for (_, board) in final_boards { println!("{}", board.display()); } } fn all_boards(board: Board, to_play: char) -> Vec { let to_play_next: char = if to_play == X { O } else { X }; let mut boards: Vec = Vec::new(); for x in 0..board.len() { let row = board[x]; for y in 0..row.len() { if board[x][y] == EMPTY { let mut b: Board = board.clone(); b[x][y] = to_play; boards.push(b); if !b.is_terminal() { boards.append(&mut all_boards(b, to_play_next)); } } } } return boards; } impl BoardMethods for Board { fn display(&self) -> String { let mut s = String::new(); for row in self { for square in row { s.push('|'); s.push(*square); } s.push_str("|\n"); } return s; } fn is_terminal(&self) -> bool { for i in 0..3 { if self[i][0] != EMPTY && self[i][0] == self[i][1] && self[i][1] == self[i][2] { return true; } if self[0][i] != EMPTY && self[0][i] == self[1][i] && self[1][i] == self[2][i] { return true; } } if self[0][0] != EMPTY && self[0][0] == self[1][1] && self[1][1] == self[2][2] { return true; } if self[0][2] != EMPTY && self[0][2] == self[1][1] && self[1][1] == self[2][0] { return true; } for row in self { for square in row { if *square == EMPTY { return false; } } } return true; } fn all_representations(&self) -> Representations { let mut r: Representations = Default::default(); r[0] = self.representation(); r[1] = self.rotate().representation(); r[2] = self.rotate().rotate().representation(); r[3] = self.rotate().rotate().rotate().representation(); r[4] = self.transpose().representation(); r[5] = self.rotate().transpose().representation(); r[6] = self.rotate().rotate().transpose().representation(); r[7] = self.rotate().rotate().rotate().transpose().representation(); return r; } fn representation(&self) -> String { let mut s = String::new(); for row in self { for square in row { s.push(*square); } } return s; } fn rotate(&self) -> Board { let mut b: Board = [[EMPTY, EMPTY, EMPTY]; 3]; for x in 0..self.len() { let row = self[x]; for y in 0..row.len() { b[x][y] = self[row.len() - y - 1][x]; } } return b } fn transpose(&self) -> Board { let mut b: Board = [[EMPTY, EMPTY, EMPTY]; 3]; for x in 0..self.len() { let row = self[x]; for y in 0..row.len() { b[y][x] = self[x][y]; } } return b; } } impl BoardsMethods for Boards { fn contains(&self, board: Board) -> bool { for repr in board.all_representations() { if self.contains_key(&repr) { return true; } } return false; } fn insert_board(&mut self, b: Board) { self.insert(b.representation(), b); } } fn test() { test_rotate(); test_transpose(); } fn test_rotate() { // XXX _OX // OOO => _OX // ___ _OX let b: Board = [[X, X, X], [O, O, O], [EMPTY, EMPTY, EMPTY]]; let rotated: Board = b.rotate(); assert!(rotated[0] == [EMPTY, O, X]); assert!(rotated[1] == [EMPTY, O, X]); assert!(rotated[2] == [EMPTY, O, X]); } fn test_transpose() { // X_O XO_ // OX_ => _X_ // __X O_X let b: Board = [[X, EMPTY, O], [O, X, EMPTY], [EMPTY, EMPTY, X]]; let transposed: Board = b.transpose(); assert!(transposed == [[X, O, EMPTY], [EMPTY, X, EMPTY], [O, EMPTY, X]]); }
Updated from three years ago: https://bluebones.net/2019/07/set-up-a-new-mac/
"trim_trailing_white_space_on_save": true in sublime prefs, install Package Control, install Solarized Theme).$ ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/u/bin/subl{ "keys": ["alt+shift+i"], "command": "exclude_ignored" }"font_face": "Fira Code".$ defaults write com.apple.finder CreateDesktop false$ killall Finderbrew install mariadbbrew install npm brew install gimme-aws-creds brew install awscli brew install kubectlbrew install sopsbrew install kubectxbrew install apache2brew install phpnpm install -g rtm-clidefaults write -g ApplePressAndHoldEnabled -bool falseLook up on the remote which branches have been deleted there and remove them from local.
git remote update origin --prune
git branch -vvv | grep gone | cut -d' ' -f3 | xargs -I{} git branch -D '{}'