Skip to content

Instantly share code, notes, and snippets.

View tsleyson's full-sized avatar

Trisdan Leyson tsleyson

  • The greatest city that ever was or will be
View GitHub Profile
@tsleyson
tsleyson / convert_webm_to_mp4.bas
Created January 2, 2019 05:11
Command to convert all .webm files to mp4, skipping those with already exist as mp4
for f in *.webm; do
ffmpeg -n -i "${f}" "${f%.webm}.mp4"
done
@tsleyson
tsleyson / format_date.sh
Created March 19, 2018 21:44
Formatting the output of the Unix date command
# Outputs the date in the format "2018-03-19 14:43:13".
date +"%Y-%m-%d %H:%M:%S"
@tsleyson
tsleyson / removeprefix.sh
Created February 15, 2018 17:52
Rename files in directory with some prefix to remove the prefix
# It doesn't seem to work if you put the prefix in quotes.
# The wildcard expansion doesn't pan out.
for file in The\ prefix\ *; do
mv "$file" "${file#The\ prefix\ }"
done
# You can do this inside instead if you want to remove
# a suffix.
mv "$file" "${file%\ the\ suffix}"
@tsleyson
tsleyson / clear-git-branches.sh
Created February 14, 2018 23:22
Command to delete all local git branches
# I assigned this to an alias in .bash_profile.
# It gets rid of all your local git branches except for master and prod.
# I had to use command grep because I like to have alias grep='grep --color=auto -n -E'
# in my bash profile so I always have colors and extended regexes, but I don't want line numbers
# for this. (Adding that to the alias probably wasn't a good idea anyway.)
git branch | command grep -Ev '(master|prod)$' | xargs git branch -D
@tsleyson
tsleyson / find-duplicate-lines.sh
Created September 26, 2017 22:58
Bash commands to find and list duplicated lines in a file
#!/usr/bin/bash
echo $1
sort $1 | uniq -c | grep -v '^ *1'
@tsleyson
tsleyson / reseq.el
Last active September 14, 2017 23:46
Emacs functions for searching for a regex in a region and dumping the results in a temp buffer
;; This function stolen from https://emacs.stackexchange.com/a/7150/12219
(defun re-seq (regexp string)
"Get a list of all regexp matches in a string"
(save-match-data
(let ((pos 0)
matches)
(while (string-match regexp string pos)
(push (match-string 0 string) matches)
(setq pos (match-end 0)))
matches)))
@tsleyson
tsleyson / curl_json.sh
Created August 31, 2016 17:24
cURL: Post json while sending an authentication cookie
curl -H "Content-Type: application/json" -b auth.txt <your url> -d @/path/to/file/containing/json
@tsleyson
tsleyson / file_from_first_match.sh
Created August 10, 2016 22:35
How to get all the lines of a file starting from the first one that matches a regex, up to the end
tail -n $(grep -n -m 1 "regex to match" "source file" | cut -d : -f1) "source file" > "dest file"
# The above throws away the first line that matches the regex. This will keep that line:
tail -n $(( $(grep -n -m 1 "regex to match" "source file" | cut -d : -f1) - 1)) "source file" > "dest file"
@tsleyson
tsleyson / hideHotNetworkQuestions
Created February 6, 2015 03:46
The Hot Network questions sidebar on Stack Exchange is a constant distraction to me, so hide it with this tiny Greasemonkey script
// ==UserScript==
// @name hideHotNetworkQuestions
// @namespace leyson
// @description Hides hot network questions on Stack Exchange
// @include *.stackexchange.com/*
// @version 1
// @grant none
// ==/UserScript==
document.getElementById("hot-network-questions").style.visibility = "hidden";
/* KarpRabin.java
A Java implementation of the Karp-Rabin seminumerical string
matching algorithm.
See CLRS Section 32.2.
*/
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
public class KarpRabin {