$ cd /var/log
$ ltr
$ cd /var/log
$ less syslog.1 |
grep 'systemd.*Started' |
sed 's/.*Started //' |
sort |
uniq -c |
sort -n
$ less /var/log/syslog |
grep elapsed |
awk -F'elapsed' '{n += $2} END {print n}'
PATH=$HOME/bin:$PATH
$ cd ~
$ git status
On branch master
Your branch is up-to-date
/home/brandon/.gitignore:
*
git add -f bin/new_script
~ ! @ # $ % ^ & * ( ) _ +
` 1 2 3 4 5 6 7 8 9 0 - =
Q W E R T Y U I O P { } |
q w e r t y u i o p [ ] \
A S D F G H J K L : "
a s d f g h j k l ; '
Z X C V B N M < > ?
z x c v b n m , . /
~ ! @ # $ % ^ & * ( ) _ +
` 1 2 3 4 5 6 7 8 9 0 - =
Q W E R T Y U I O P { } |
[ ] \
A S D F G H J K L : "
; '
Z X C V B N M < > ?
, . /
$ ls /usr/bin | head -12
2to3
2to3-2.7
2to3-3.5
411toppm
FvwmCommand
GET
HEAD
POST
X
X11
~ ! @ # $ % ^ & * ( ) _ +
` 1 2 3 4 5 6 7 8 9 0 - =
Q W E R T Y U I O P { } |
[ ] \
A S D F G H J K L : "
; '
Z X C V B N M < > ?
, . /
~ ! @ # $ % ^ & * ( ) _ +
` 1 2 3 4 5 6 7 8 9 0 - =
{ } |
[ ] \
: "
; '
< > ?
, . /
~ ! @ # $ % ^ & * ( ) _ +
` - =
{ } |
[ ] \
: "
; '
< > ?
, . /
~ ! @ # $ % ^ & * ( ) _ +
` - =
{ } |
[ ] \
: "
; '
< > ?
, . /
@ _ +
-
:
, .
$ python -m SimpleHTTPServer
Traceback (most recent call last):
...
socket.error: [Errno 98] Address already in use
# 1.
r = SimpleHTTPRequestHandler
port = 8002
while True:
try:
httpd = HTTPServer(('', port), r)
except socket.error:
port += 1
...
# 2.
webbrowser.open(url)
# Sometimes I accidentally use the public URL
$ git clone https://github.com/my-acct/repo.git
.
.
.
$ git push
Username for 'https://github.com':
Password for 'https://github.com':
remote: Anonymous access denied.
# Because only SSH lets me “push”
github.com/brandon-rhodes/build-butchart-map-index
for line in search_result_html:
if 'results_tn_img' in line:
name = line.split('alt="')[1].split(',')[0]
Emmett Wash, Ariz.
Navajo Mountain, Utah - Ariz.
Mt. Dellenbaugh, Ariz.
Separation Canyon, Ariz.
import csv
r = csv.reader(open('topomaps_all.csv'))
for row in r:
name, scale = row[3], row[5]
if (name, scale) not in targets:
continue
q = Quad(name, scale, ...)
Camp Verde 35.0 -112.0 34.5 -111.5
Blue Spring 36.25 -111.75 36.0 -111.5
Cameron 36.0 -111.5 35.75 -111.25
⋮
import json
j = json.dumps(data)
f = open('quad_data.js', 'w')
f.write('var quad_data = {};\n'.format(j))
var map = L.map('map');
map.fitBounds(lat1, lon1, lat2, lon2);
for (var i = 0; i < quads.length; i++) {
var bounds = [q.lat1, q.lon1, q.lat2, q.lon2];
L.rectangle(bounds, {color: '#ff7800'});
...
# Input 1: trail mileages
South Kaibab Trailhead
1.5 Cedar Ridge
3.0 Skeleton Point
1.4 Tip Off
2.6 CBG Bright Angel Campground
# Input 2: route
route = [
'South Kaibab Trailhead',
'Skeleton Point',
'Tip Off',
'Skeleton Point',
'South Kaibab Trailhead',
]
# Output: miles hiked along route
Miles
hiked
South Kaibab Trailhead 0.0
Cedar Ridge 3.0
Skeleton Point 4.4
Cedar Ridge 5.8
South Kaibab Trailhead 8.8
edges = [
('South Kaibab Trailhead', 'Cedar Ridge', 1.5),
('Cedar Ridge', 'Skeleton Point', 1.5),
('Skeleton Point', 'Tip Off', 1.4),
]
def find_distance(waypoint1, waypoint2):
for w1, w2, distance in edges:
if w1 == waypoint1 and w2 == waypoint2:
return distance
raise ValueError('not found')
edges = [
('South Kaibab Trailhead', 'Cedar Ridge', 1.5),
('Cedar Ridge', 'Skeleton Point', 1.5),
('Skeleton Point', 'Tip Off', 1.4),
]
def find_distance(waypoint1, waypoint2):
for w1, w2, distance in edges:
if w1 == waypoint1 and w2 == waypoint2:
return distance
elif w1 == waypoint2 and w2 == waypoint1:
return distance
raise ValueError('not found')
# New rule: alphabetical order
edges = [
('South Kaibab Trailhead', 'Cedar Ridge', 1.5),
# ^ FIX
('Cedar Ridge', 'Skeleton Point', 1.5),
('Skeleton Point', 'Tip Off', 1.4),
]
edges = [
('Cedar Ridge', 'South Kaibab Trailhead', 1.5),
('Cedar Ridge', 'Skeleton Point', 1.5),
('Skeleton Point', 'Tip Off', 1.4),
]
def find_distance(waypoint1, waypoint2):
waypoint1, waypoint2 = sorted([waypoint1, waypoint2])
for w1, w2, distance in edges:
if w1 == waypoint1 and w2 == waypoint2:
return distance
raise ValueError('not found')
edges = {
'South Kaibab Trailhead': {'Cedar Ridge': 1.5},
'Cedar Ridge': {
'South Kaibab Trailhead': 1.5,
'Skeleton Point', 1.5,
},
'Skeleton Point': {
'Cedar Ridge': 1.5,
'Tip Off', 1.4,
},
'Tip Off': {'Skeleton Point': 1.4},
}
# No loop is required
miles = edges[w1][w2]
edges = {
'South Kaibab Trailhead': {'Cedar Ridge': 1.5},
'Cedar Ridge': {
'South Kaibab Trailhead': 1.5,
'Skeleton Point', 1.5,
},
'Skeleton Point': {
'Cedar Ridge': 1.5,
'Tip Off', 1.4,
},
'Tip Off': {'Skeleton Point': 1.4},
}
# Maybe they use indexing
for i in range(len(route) - 1):
print(route[i], route[i+1])
# Carrying state
previous_waypoint = route[0]
for waypoint in route[1:]:
print(previous_waypoint, waypoint)
previous_waypoint = waypoint
# Instead of:
South Kaibab Trailhead
Bright Angel Campground
# I had to list every single waypoint:
South Kaibab Trailhead
Cedar Ridge
Skeleton Point
Tip Off
Bright Angel Campground
South Kaibab Trailhead
Bright Angel Campground
↓
South Kaibab Trailhead
Cedar Ridge
Skeleton Point
Tip Off
Bright Angel Campground
def find_path(start, end):
visit_next = [(0.0, start)]
while True:
visit_next.sort()
miles, w = visit_next.pop(0)
for miles2, w2 in waypoints_connected_to(w):
visit_next.append((miles + miles2, w2))
def find_path(start, end):
visit_next = [(0.0, start)]
while True:
visit_next.sort()
miles, w = visit_next.pop(0)
for miles2, w2 in waypoints_connected_to(w):
if w2 == end:
return
visit_next.append((miles + miles2, w2))
def find_path(start, end):
visit_next = [(0.0, start)]
while True:
visit_next.sort()
miles, w = visit_next.pop(0)
for miles2, w2 in waypoints_connected_to(w):
if w2 == end:
return # WRONG
visit_next.append((miles + miles2, w2))
def find_path(start, end):
visit_next = [(0.0, start)]
while True:
visit_next.sort()
miles, w = visit_next.pop(0)
if w == end:
return # RIGHT
for miles2, w2 in waypoints_connected_to(w):
visit_next.append((miles + miles2, w2))
def find_path(start, end):
visit_next = [(0.0, start)]
visited_already = {start}
while True:
visit_next.sort()
miles, w = visit_next.pop(0)
if w in visited_already: continue
if w == end: return
for miles2, w2 in waypoints_connected_to(w):
visit_next.append((miles + miles2, w2))
visited_already.add(w2)
def find_path(start, end):
visit_next = [(0.0, start)]
visited_already = {start}
while True:
visit_next.sort()
miles, w = visit_next.pop(0)
if w in visited_already: continue
if w == end: return
for miles2, w2 in waypoints_connected_to(w):
visit_next.append((miles + miles2, w2))
visited_already.add(w2) # WRONG
def find_path(start, end):
visit_next = [(0.0, start)]
visited_already = {start}
while True:
visit_next.sort()
miles, w = visit_next.pop(0)
if w in visited_already: continue
visited_already.add(w) # RIGHT
if w == end: return
for miles2, w2 in waypoints_connected_to(w):
visit_next.append((miles + miles2, w2))