Skip to content

Instantly share code, notes, and snippets.

@shang-lin
shang-lin / pwnedornot.py
Created May 24, 2018 22:18
Check if your password is in haveibeenpwned.com's database of compromised passwords
#!/usr/bin/env python3
""" Checks if a password has been pwned using the haveibeenpwned.com API.
"""
import getpass
import hashlib
import requests
def get_matching_list(hash_prefix):
@shang-lin
shang-lin / create_email_list.sh
Created November 24, 2015 18:52
Construct a comma-separated email list that can be copied and pasted into the to, cc, or bcc field.
# myfile.csv is a CSV export of a Google sheet. that contains name, email, and affiliation .
# The first three lines are headings and boilerplate. "-n +4" tells tail to only display line 4 and later.
# The cut command extracts the second column (email addresses) using ',' as the delimiter.
# tr transforms the newlines into commas to create a comma-separated list of only email addresses.
tail -n +4 myfile.csv | cut -d ',' -f 2 | tr '\n' ','
@shang-lin
shang-lin / add_file_sizes
Created January 5, 2015 06:33
How to obtain file sizes from ls output on the command line
# ls -s displays the size of files, in blocks, followed by the file name.
# For convenience, I am setting the block size to 1024 bytes, or 1 kilobyte.
# The output of ls -s is piped to an awk command that incrementally adds the file sizes and displays the total.
ls --block-size=1024 -s /path/to/files | awk '{ total += $1 }; END { print total }'
@shang-lin
shang-lin / shell_tricks.md
Last active December 19, 2015 22:09
This is my own command line-fu: one-liners on the Bash CLI that I find useful.

Formatting strings

printf "%s %d %d %d\n" "Testing" 1 2 3

Output:

Testing 1 2 3

Remove whitespace

@shang-lin
shang-lin / git_recipes.md
Last active December 19, 2015 18:28
Git Recipes

Git Recipes

Removing a file from the repository

git rm filename

Removing a file from the repository but keeping the copy in the current working directory

git rm --cached filename

Removing the entire history of a file

@shang-lin
shang-lin / how_to_access_google_cache.md
Last active December 16, 2015 10:48
Access Google's cached version of a web page.

Google search results used to include a link to a cached version, but alas, that is no more. What should you do if a page has disappeared or changed? Try this URL to search the Google cache:

http://webcache.googleusercontent.com/search?q=cache:http://example.com/

Replace example.com with the actual URL you want.

@shang-lin
shang-lin / rm_empty_files.pl
Created December 27, 2012 21:49
Remove empty files from a directory given as a command line argument.
# Deletes empty (size 0) files from the directory provided as a command-line
# argument. Currently does not descend into subdirectories.
# Created August 2005.
# author: Shang-Lin Chen
use File::stat;
use File::Copy "move";
$num_args = @ARGV;
@shang-lin
shang-lin / clear_ipc.sh
Created November 20, 2012 19:44
Remove a user's IPC shared memory, semaphores, and message queues
#!/bin/bash
# clear_ipc
#
# Delete the IPC objects created by a user. The user and IPC type are specified on the command
# line.
#
# usage: clear_ipc username type
USERNAME=$1
@shang-lin
shang-lin / perl_file.pl
Last active October 10, 2015 20:08
Perl by Example
# Demo of how to process files in Perl.
# Replace with the actual name of the file.
my $file_name = "myfile.txt";
# Open the input file read-only.
open(IN, "<$file_name") or die "Cannot open $file_name\n";
# Open the output file for writing.
open(OUT, ">outputfile.txt") or die "Cannot open output file\n";