Skip to content

Instantly share code, notes, and snippets.

View pykong's full-sized avatar
🎯
Focusing

Ben Felder pykong

🎯
Focusing
View GitHub Profile
@pykong
pykong / set_env_var.sh
Last active May 9, 2023 12:06
Script to permanently set environment variables under Linux (Ubuntu 16.04 and later). Run as sudo. Usage: sudo set_env_var.sh key value
#!/bin/bash
# run under sudo
# script for permanently setting environment variables, found here:
# https://stackoverflow.com/questions/13046624/how-to-permanently-export-a-variable-in-linux
add_env_var()
{
KEY=$1
VALUE=$2
echo "export "$KEY"="$VALUE>>~/.bashrc
import shlex
from dataclasses import dataclass
from pathlib import Path
from subprocess import check_call
from typing import Final, Optional, Sequence
IMG_EXTS: Final[Sequence[str]] = (
".png",
".jpg",
".svg",

Erasing SSD

  1. Boot with a live USB stick.
  2. Get name of SSD by running lsblk
  3. Run this command:
sudo hdparm --user-master u --security-set-pass 1234 /dev/sda &&
sudo hdparm --user-master u --sanitize-crypto-scramble 1234 /dev/sda

Troubleshooting:

@pykong
pykong / open_in_sublime_merge.nemo_action
Last active December 22, 2019 16:20
Put under ~/.local/share/nemo/actions/
[Nemo Action]
Name=Open in Sublime Merge
Comment=Open in Sublime Merge
Exec=/opt/sublime_merge/sublime_merge -n %F
Icon-Name=sublime-merge
Selection=any
Extensions=dir
Quote=double
@pykong
pykong / open_in_sublime_text.nemo_action
Last active December 22, 2019 16:20
Put under ~/.local/share/nemo/actions/
[Nemo Action]
Name=Open in Sublime Text 3
Comment=Open in Sublime Text 3
Exec=subl -n %F
Icon-Name=sublime-text
Selection=any
Extensions=dir
Quote=double
Mimetypes=text/plain
Dependencies=subl
@pykong
pykong / pywatch.sh
Last active October 24, 2019 13:37
Execute python script on file change in a directory. Useful when coding to instantly get output from the modified code. Setup: 1) Install inotify: sudo apt-get install inotify-tools 2) Make script executable chmod +x pywatch.sh 3) Make script global
#!/bin/bash
echo watch activated
inotifywait -qmre modify . | while read f
do
python $1
done

Transforming Code into Beautiful, Idiomatic Python 3

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Adapted from Alen K's original transcript to Python 3.6+ syntax by myself.

Looping over a range of numbers

Don't use a password. Generate a passphraseless SSH key and push it to your VM.
If you already have an SSH key, you can skip this step… Just hit Enter for the key and both passphrases:
$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
@pykong
pykong / faker.cs
Created April 27, 2018 09:58
https://github.com/diogolmenezes/Faker PM> Install-Package FakerTest
public class User
{
public string Name { get; set; }
public string Email { get; set; }
public int Age { get; set; }
public DateTime CreatedAt { get; set; }
}
// creating one fake user
var user = new Faker<User>().Create();
// create new object
contact_existing = Mapper.Map<ContactDTO, Contact>(contact_dto);
// update existing object
contact_existing = Mapper.Map<ContactDTO, Contact>(contact_dto, contact_existing);