Skip to content

Instantly share code, notes, and snippets.

const cities = ['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris']
// Initially I misunderstood the problem and assumed that the letters
// could be reconfigured in any order to be a match
function sameLetters(city1, city2) {
if (city1.length !== city2.length) return false
for (let i = 0; i < city1.length; ++i) {
if (!city2.includes(city1[i])) return false
city2 = city2.replace(city1[i], '')
}
@larryprice
larryprice / autopgsqlbackup
Last active November 9, 2017 18:15 — forked from matthewlehner/autopgsqlbackup
Auto PostgreSQL backup script.
#!/bin/bash
#
# PostgreSQL Backup Script Ver 1.0
# http://autopgsqlbackup.frozenpc.net
# Copyright (c) 2005 Aaron Axelsen <axelseaa@amadmax.com>
#
# This script is based of the AutoMySQLBackup Script Ver 2.2
# It can be found at http://sourceforge.net/projects/automysqlbackup/
#
# The PostgreSQL changes are based on a patch agaisnt AutoMySQLBackup 1.9
@larryprice
larryprice / migrate.sh
Created October 4, 2017 13:17
svn-migration
#!/bin/bash
# Arguments: $1 is a directory where the SVN repository already exists
# $2 is the remote SVN repo URL
# $3 is the URL to the Gitlab site
# $4 is the token used to access the Gitlab site
# $5 is the Gitlab namespace id new repos will reside in
# $6 is the base Gitlab SSH URL (including namespace name)
PROJECTS=`ls $1`
@larryprice
larryprice / INFO.md
Created April 10, 2017 16:59
Migrating libertine repos from bzr to git
  1. Needed to patch fastimport (see fastimport.patch)
  2. Switch to bzr directory
  3. git init
  4. bzr fast-export --plain . | git fast-import
  5. rm -rf .bzr
  6. git log --format=%H --first-parent > hashes
  7. tac hashes | tail -n +2 > reversed_hashes
  8. Determine initial commit (we'll refer to it as $initial_commit)
  9. git checkout $initial_commit
  10. `git checkout -b top-level-commits
#!/usr/bin/python3
# Copyright (C) Larry Price 2016
# GPLv3
from pexpect import spawnu as spawn, EOF
import subprocess
import sys
import time
@larryprice
larryprice / stdin_thief.py
Last active August 17, 2016 19:10
Light script to demonstrate lxc.attach_wait hoarding stdin even after it's finished
#!/usr/bin/env python3
import lxc
import time
import os
CONTAINER_NAME='xenial'
CONTAINER_PATH='%s/.cache/libertine-container' % os.environ["HOME"]
def lxc_work():
@larryprice
larryprice / dining_philosophers.go
Last active March 4, 2016 20:23
Dining philosophers with channels
package main
import (
"fmt"
"time"
)
type Philosopher struct {
Name string
}
@larryprice
larryprice / dining_philosophers.go
Last active March 4, 2016 20:30
Dining philosophers with mutexes in go
package main
import (
"fmt"
"sync"
"time"
)
type Philosopher struct {
Name string
@larryprice
larryprice / salesman.go
Last active January 28, 2016 15:05
Traveling salesman in go
package main
import (
"bufio"
"fmt"
"math"
"math/rand"
"os"
"strconv"
"strings"
package main
import (
"fmt"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
Fetch(url string) (body string, urls []string, err error)