惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
V2EX
大猫的无限游戏
大猫的无限游戏
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Jina AI
Jina AI
GbyAI
GbyAI
云风的 BLOG
云风的 BLOG
B
Blog RSS Feed
Last Week in AI
Last Week in AI
The Cloudflare Blog
V
Visual Studio Blog
P
Proofpoint News Feed
博客园 - 叶小钗
L
LangChain Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Recorded Future
Recorded Future
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
Y
Y Combinator Blog
罗磊的独立博客
雷峰网
雷峰网
博客园 - 【当耐特】
Microsoft Security Blog
Microsoft Security Blog
L
LINUX DO - 热门话题
Cisco Talos Blog
Cisco Talos Blog
L
Lohrmann on Cybersecurity
Martin Fowler
Martin Fowler
Spread Privacy
Spread Privacy
MongoDB | Blog
MongoDB | Blog
Engineering at Meta
Engineering at Meta
C
Cybersecurity and Infrastructure Security Agency CISA
小众软件
小众软件
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Recent Announcements
Recent Announcements
T
Threat Research - Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
量子位
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
宝玉的分享
宝玉的分享
D
DataBreaches.Net
T
The Exploit Database - CXSecurity.com
Vercel News
Vercel News
IT之家
IT之家
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Troy Hunt's Blog
aimingoo的专栏
aimingoo的专栏

Rc-2020 on Julia Evans

Day 57: Trying to set up GitHub Actions Day 56: A little WebAssembly Day 53: a little nginx, IPv6, and wireguard Day 52: testing how many Firecracker VMs I can run Day 51: Fixed my logging and made a couple of puzzles Day 50: Building some tarballs for puzzles, and trying to make a kernel boot faster Day 49: making the VMs boot faster Day 48: Another Go program, and a little vim configuration Day 47: Using device mapper to manage Firecracker images Day 46: debugging an iptables problem Day 44: Building my VMs with Docker Day 43: Building VM images Day 42: Writing a Go program to manage Firecracker VMs Day 41: Trying to understand what a bridge is Day 40: screen flickering & a talk about containers Day 39: Customizing gotty's terminal Day 38: Modifying gotty to serve many different terminal applications at once Day 37: A new laptop and a little Vue Day 35: Launching my VMs more reliably Day 34: Learning about qemu Day 32: A Rails model that doesn't use the database with ActiveHash Day 24: a short talk about blogging myths, and a debugging tip Day 23: a little Rails testing Day 22: getting OAuth to work in Rails Day 21: wrangling systemd & setting up git deploys to a VM Day 19: Clustering faces (poorly) using an autoencoder Day 20: trying to figure out how Google Cloud IAM works Day 18: an answer to an autoencoder question Day 17: trying to wrap my head around autoencoders Day 13: BPTT, and debugging why a model isn't training is hard Day 11: learning about learning rates Day 10: Training an RNN to count to three Day 9: Generating a lot of nonsense with an RNN Day 8: Start with something that works Day 5: drawing lots of faces with sketch-rnn Day 3: an infinitely tall fridge Day 2: Rails associations & dragging divs around Day 1: a confusing Rails error message I'm doing another Recurse Center batch!
Day 33: pairing is magic and beautiful git diffs
Julia Evans · 2021-01-07 · via Rc-2020 on Julia Evans

a silly Rails login bug (or: pairing is magic)

On Wednesday morning suddenly I wasn’t able to login in my dev environment, even though it was working in prod and it had worked the day before and I thought I hadn’t made any changes to my login code.

The error was really weird though – it was telling me that it was expecting a provider column in my users table (for the OAuth provider), and there wasn’t one! How could this be?? I was sure hadn’t made any changes to that table.

I felt really frustrated so I asked if someone wanted to pair with me on it. Mikkel agreed to pair with me, and in about 10 minutes we established that:

  • the production database had a provider column and the dev database didn’t
  • running git log -S provider showed that I had in fact deleted the provider column from my dev schema a few hours before at some point, which I definitely did not remember doing, but, ok

I’m always amazed by how quickly pairing can turn “UGH THIS IS TERRIBLE” into solving the problem really quickly.

This was super easy to fix, I just added the offending columns back and everything was good. Hooray!

I’m still not 100% sure how/why this happened (I think something was wrong in my Rails migrations for an unknown reason, and when I ran rake db:migrate to recreate my dev database it broke my schema)

git trick 1: git log -S

I ran git log -S provider to find every commit that had added/removed the string provider and Mikkel was like WHAT IS THAT??? Pairing is magic!

On Zulip after we ended up discussing the difference between git log -S and git log -G. I learned that git log -S doesn’t actually search diffs to find diffs containing the string, instead it just counts occurrences of the string and reports when the count was changed.

So I learned something too!

git trick 2: beautiful diffs with delta

I told Kamal about this git log -S thing, and he showed me some other git thing on this computer where you can git log just changes to a specific function. But I got distracted from what he was telling me because I noticed that he had these INCREDIBLY BEAUTIFUL DIFFS in his terminal, that looked like this:

So I was like KAMAL WHAT IS THAT?!?!?!
This is called delta. It’s pretty easy to install and I configured it by adding these things to my ~/.gitconfig. It has a million options that I didn’t really look into but now my diffs are BEAUTIFUL. (that screenshot is actually from my computer)

[core]
	attributesfile = ~/.gitattributes

[interactive]
    diffFilter = delta --color-only

[delta]
    features = side-by-side line-numbers
    whitespace-error-style = 22 reverse
syntax-theme = GitHub

git trick 3: git log –patch

I also learned that you can get a diff with your git log with git log --patch.

This was cool to know because I’ve been copying and pasting commit IDs from git log and doing git show COMMIT_ID to look at a diff for like 7 years.

Python’s pathlib is nice

My actual goal for the day was to write a Python script to generate my cloud-init.yaml file by syncing some files from a local directory.

This post is long enough already and it’s not too interesting, so I’ll just say that I learned about the pathlib module and I thought it was nice nice. A few things you can do with a path:

path = "/home/bork/"
textfile = path.joinpath('x.txt') # /home/bork/x.text
textfile.read_text() # read the contents as a string
textfile.read_bytes() # read the contents as binary
textfile.relative_to(path) # 'x.txt', lets you get the relative version of a path

a working directory context manager

In my Python script, I wanted to do a bunch of things where I changed to a directory, did some things, and then changed back. This felt like a context manager to me, so I googled “python working directory context manager” and found one in a github gist.

It always brings me a lot of joy when I think of a little bit of simple code that I want to exist and I can kind of just summon it with a Google search.

It was really simple so I just copied it into my code:

import os
from contextlib import contextmanager
@contextmanager
def working_directory(path):
    prev_cwd = os.getcwd()
    os.chdir(path)
    try:
        yield
    finally:
        os.chdir(prev_cwd)

and then I could use it:


with working_directory(directory.joinpath('files')):
    synced = sync_files(cloud_init_yaml['write_files'])
    cloud_init_yaml['write_files'] = list(synced)