Skip to content

Instantly share code, notes, and snippets.

@samba
samba / fortunesay.sh
Created January 7, 2017 00:39
Say (audibly) random quotes/etc from UNIX fortune
#!/bin/sh
curl http://www.coe.neu.edu/cgi-bin/fortune | \
xmllint --nowarning --html --recover --xpath "//pre//text()" - 2>/dev/null | \
say -v Alex
@samba
samba / converse.sh
Last active March 2, 2017 19:24
Scripted conversations in your Mac.
#!/bin/sh
# Execute directly: sh converse.sh script.text
which say || exit 1
cat $@ | grep -v '^#' | tr -s ':' '\t' | while read name content; do say -v $name "$content"; done
@samba
samba / vbox-snapshot.sh
Created December 26, 2016 06:17
VirtualBox Snapshot Kit
#!/bin/sh
export MACHINE_NAME="test machine"
export DATE=`date +"%Y-%m-%d %H:%M:%S"`
take_snapshot () {
while read vmuuid; do
VBoxManage snapshot "${vmuuid}" take "Snapshot ${DATE}"
done
}
@samba
samba / jekyll-redirect.html
Last active November 17, 2016 20:41
Jekyll Redirect page template.
<!DOCTYPE html>
<html lang="en-US">
<meta charset="utf-8">
<title>Redirecting…</title>
<link rel="canonical" href="#{item_url}">
<meta http-equiv="refresh" content="0; url=#{item_url}">
<h1>Redirecting…</h1>
<a href="#{item_url}">Click here if you are not redirected.</a>
<script>
q = (location.search && !location.search.indexOf('?')) ? '' : '?';
@samba
samba / pipesearch.py
Last active July 26, 2016 20:46
Search an event log: JSON structures wrapped in CSV
#!/usr/bin/env python
"""
USAGE:
cat awholebunchoflogfiles*.csv | python pipesearch.py \
'data.someproperty.feature~="(test|other)"' \
'data.someproperty.another^="prefix"' \
'data.someproperty.yetanother$="suffix"' \
'data.someproperty.thatother*="textwithin"'
Filter expressions will be collectively combined as AND-ed together; multiple
@samba
samba / ubuntu-vnc-activate-remote.sh
Last active January 24, 2024 00:56
Activate VNC support in Ubuntu, from command-line (for active sessions)
#!/bin/sh
# This assumes you have access to the system via SSH already, and need
# remote VNC access as the same user, and you want only the primary display.
export DISPLAY=:0
# Encoded password with http://www.motobit.com/util/base64-decoder-encoder.asp
export VNC_PASSWORD="dm5jX3Bhc3N3b3JkNzE=" # vnc_password71
export VNC_PASSWORD="dm5jX3Bhc3M=" # vnc_password (a character limit is enforced?)
# Sadly many common VNC clients don't support encryption.
@samba
samba / compat.sql
Created November 17, 2015 23:32
Redshift Compatibility Functions
/* Functions available in Redshift that can be emulated in Postgres for compatibility.
* This is most applicable when a schema needs to be migrated into a (local) PostgreSQL
* environment for modeling/development. As Redshift is derived from PostgreSQL, many
* DBA and related modeling tools designed for PostgreSQL are _not quite_ viable for
* use with Redshift. These functions attempt to augment native PostgreSQL to allow
* Redshift SQL to run in other Postges environments.
* I'll update this periodically with additional functions as needed.
*/
CREATE FUNCTION public.getdate() returns timestamptz
@samba
samba / README.md
Last active November 4, 2015 06:34
A breadth-first graph search, generates paths with sorted (least-first) cost

Breadth-first Graph Search

Generates least-cost paths from an adjacency list with one cost factor per edge.

Why did @samba write this?

Simply because I needed the refresher, having taken my last Computer Science class nearly a decade ago, and having focused on a different domain of problems in recent years.

I wanted the practice. :)

@samba
samba / pythonrc.py
Last active June 21, 2018 19:09
Python RC with Color Prompt :)
# ~/.pythonrc
import sys
# enable syntax completion via tab
try:
import readline
except ImportError:
print "Module readline not available."
else:
@samba
samba / domain-pattern-check.py
Last active August 29, 2015 14:26
Resolve DNS by regex pattern. e.g. "g[o]{2}gl[aeo].com"
#!/usr/bin/env python
import socket
import argparse
import sys
import re
def test_domain(domain_name):
try:
return bool(socket.gethostbyname(domain_name))