Skip to content

Instantly share code, notes, and snippets.

# LINKS:
* http://www.math.harvard.edu/computing/perl/oneliners.txt
* https://gist.github.com/mischapeters/1e8eef09a0aafd4f24f0
# random line from file
perl -e 'srand;' -e 'rand($.) < 1 && ($it = $_) while <>;' -e 'print $it' file.csv
#NOTE: the above is easier with the following bash command
shuf -n 1 file.csv
@kirkins
kirkins / .bashrc
Last active July 2, 2017 04:03
Vim replace DATE with date/time in Jekyll post template
# function to create a blog post, with date in name, and a timestamp
function blog() {
BLOG_DIRECTORY="/home/philip/Projects/notes/_posts/"
TEMPLATE=".template"
cp ${BLOG_DIRECTORY}${TEMPLATE} $BLOG_DIRECTORY`date +%Y-%m-%d`-$1.md
vi ${BLOG_DIRECTORY}"`date +%Y-%m-%d`"-$1.md -c ":%s/DATE/\=strftime(\"%y-%m-%d %H:%M:%S\")/g"
}
@kirkins
kirkins / .travis.yml
Created June 30, 2017 19:21
Travis Cli Spell Check
language: node_js
node_js:
- '0.10'
before_install:
- npm install -g grunt-cli
script:
- grunt
branches:
only:
- gh-pages
@kirkins
kirkins / comments.html
Created July 1, 2017 19:16
Jekyll Comments Powered by Github
// Change references to my github repo to your own
<script>
// use of ajax vs getJSON for headers use to get markdown (body vs body_htmml)
// todo: pages, configure issue url, open in new window?
var CurrentPage = 0;
function ParseLinkHeader(link)
{
var entries = link.split(",");
@kirkins
kirkins / .bashrc
Created July 4, 2017 13:02
Bash command to install with pip and save to requirments
pip_install_save() {
package_name=$1
requirements_file=$2
if [[ -z $requirements_file ]]
then
requirements_file='./requirements.txt'
fi
sudo pip install $package_name && pip freeze | grep -i $package_name >> $requirements_file
}
@kirkins
kirkins / .bashrc
Created July 4, 2017 13:03
Quick commands for removing docker images and containers
# command to remove all containers and images, with y/N prompt
rmdocker() {
read -r -p "Are you sure you want to remove all docker data? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)
docker volume rm $(docker volume ls -q)
docker network rm $(docker network ls -q)
@kirkins
kirkins / for_each_branch.sh
Created July 5, 2017 19:30
R10K Helper - apply function to each branch
#!/usr/bin/env bash
for branch in $(git for-each-ref --format='%(refname)' refs/heads/); do
git checkout "$branch"
# run commands on branch here
done
@kirkins
kirkins / fast_fibonacci.rb
Last active December 31, 2018 03:06
Notes for SICP problems in ruby
def fibonacci(n)
fib_iter(1, 0, n)
end
def fib_iter(a, b, n)
n == 0 ? b : fib_iter((a+b), a, (n-1))
end
@kirkins
kirkins / .bashrc
Created July 24, 2017 18:52
Volume command line shortcut
# Get audio level or set audio level
function volume() {
if [ $# -eq 0 ]
then
awk -F"[][]" '/dB/ { print $2 }' <(amixer sget Master)
else
amixer -D pulse sset Master $1%
fi
}
# output to a video file
ffmpeg -re -f video4linux2 -i /dev/video0 out.mp4
# output format flash to local live stream
# this requires RTMP server to be running
ffmpeg -re -f video4linux2 -i /dev/video0 -f flv rtmp://localhost/live/test