Skip to content

Instantly share code, notes, and snippets.

View jonlabelle's full-sized avatar

Jon LaBelle jonlabelle

View GitHub Profile
@jonlabelle
jonlabelle / show.sh
Last active July 12, 2022 15:48
Bash functions to output colorized messages in the terminal, according to context.
# show a cyan `OK!`, or arg `1` message
function show_info()
{
local msg="OK!"
if [ ! -z "$1" ]; then
msg="$1"
fi
echo -e "\033[0;36m${msg}\033[0m"
}
@jonlabelle
jonlabelle / update-sublime-packages.sh
Last active December 26, 2015 04:28
A Bash function that updates Sublime Text packages which aren't under package control, and have git repositories.
# update all non-sublime package control packages (osx)
function update_sublimetext_packages()
{
echo ""
echo "==> Updating Sublime Text Packages"
echo ""
local cwd=$(pwd)
local subl_pkgs_dir=~/Library/Application\ Support/Sublime\ Text\ 3/Packages
local repo=
@jonlabelle
jonlabelle / datauri.sh
Last active June 18, 2016 18:17
Bash function that creates a data URI scheme for a file.
#!/usr/bin/env bash
# generate data uri scheme for file
function datauri()
{
local mimeType=$(file -b --mime-type "$1")
if [[ $mimeType == text/* ]]; then
mimeType="${mimeType};charset=utf-8"
fi
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')"
@jonlabelle
jonlabelle / rp.py
Last active December 25, 2015 05:49
Return the canonical path (real path) of the specified filename, eliminating any symbolic links encountered in the path.
#!/usr/bin/env python
import os.path as filepath
import sys
from optparse import OptionParser
def main():
parser = OptionParser(
prog='rp', usage="%prog [path]\n\nReturn the canonical path of the specified filename\n\n [path]\tpath of file to check\n\n when *no args* are passed, the current working directory\n will be set as [path].")
@jonlabelle
jonlabelle / atomic_time.py
Last active December 25, 2015 03:39
Fetch atomic time for your current locale in Python.
#!/usr/bin/env python
import re
import urllib2
def fetch_data():
return str(urllib2.urlopen('http://time.is').read())
@jonlabelle
jonlabelle / mdpreview.sh
Last active December 23, 2015 19:09
A simple Sublime Text Build System for Markdown source.
#!/usr/bin/env bash
#
# Sublime Text 2|3 Markdown Build System
#
# This Sublime Text 2|3 build system simply takes Markdown source as an
# arg(1) and parses the HTML for previewing in a browser window.
#
# **Requirements**
#
# - Sublime Text 3 <http://www.sublimetext.com>
@jonlabelle
jonlabelle / strip_tag_attribs.md
Last active May 9, 2026 19:07
This Regular Expression removes all attributes and values from an HTML tag, preserving the tag itself and textual content (if found).

Strip HTML Attributes

<([a-z][a-z0-9]*)[^>]*?(/?)>
token explanation
< match < at beginning of tags
( start capture group $1 - tag name
[a-z] match a through z
@jonlabelle
jonlabelle / sublime-text-shortcuts.txt
Last active December 21, 2015 12:19
Sublime Text keyboard shortcuts.
-----------------------------------------------------------------------------
General
-----------------------------------------------------------------------------
Command palette:
cmd + shift + p
Go to method:
cmd + r
@jonlabelle
jonlabelle / m3u.py
Last active December 17, 2022 17:34
Generate an mp3 playlist file (.m3u), sorted by album track number.
#!/usr/bin/env python
import os
import sys
import glob
from mutagen.mp3 import MP3
from mutagen.easyid3 import EasyID3
#
# MP3 playlist generator
@jonlabelle
jonlabelle / laravel4-log-sql-queries-and-url.php
Created July 8, 2013 18:06
Laravel 4: Log all SQL queries and request URL. You can add it in `app/routes.php`.
Event::listen('illuminate.query', function($sql)
{
Log::info('Request URL: '.Request::url() .' Query: '.$sql);
});