Skip to content

Instantly share code, notes, and snippets.

View zmcghee's full-sized avatar

Zack McGhee zmcghee

View GitHub Profile
# Recursively find EPS files and convert them to PDF
find . -type f -name '*.eps' -print0 | while IFS= read -r -d '' file; do
pstopdf "$file"
done
# Recursively find PDF files and convert them to EPS
find . -type f -name '*.pdf' -print0 | while IFS= read -r -d '' file; do
sips -s format png --deleteColorManagementProperties --out "${file}.png" "$file"
done
@zmcghee
zmcghee / close_open_html_tags.php
Last active July 6, 2016 21:30
Repair open HTML tags in a PHP string
<?php
/**
* Find unclosed HTML tags in a string and repair them.
* For example:
* $str = '<p>Hi, I\'m <b><a href="mailto:za ... ">Zack</a>';
* echo close_open_html_tags( $str );
* would show '<p>Hi, I\'m <b><a href="mailto:za ... ">Zack</a></b></p>'
*/
function close_open_html_tags( $str ) {
/*
Based on https://developers.google.com/speed/docs/insights/OptimizeCSSDelivery
Further reading:
Preventing a Flash of Invisible Text
https://www.filamentgroup.com/lab/font-events.html
Detecting a stylesheet has loaded
https://viget.com/inspire/js-201-run-a-function-when-a-stylesheet-finishes-loading
@zmcghee
zmcghee / mobile-app-icon-tags.html
Last active August 29, 2015 14:21
Mobile app icon tags
<link rel="icon" sizes="192x192" href="nice-highres.png" />
<link rel="icon" sizes="128x128" href="niceicon.png" />
<link rel="apple-touch-icon" href="ios/AppIcon.appiconset/[email protected]" />
<link rel="apple-touch-icon" sizes="180x180" href="ios/AppIcon.appiconset/[email protected]" />
<link rel="apple-touch-icon" sizes="76x76" href="ios/AppIcon.appiconset/Icon-76.png" />
<link rel="apple-touch-icon" sizes="152x152" href="ios/AppIcon.appiconset/[email protected]" />
<link rel="apple-touch-icon" sizes="58x58" href="ios/AppIcon.appiconset/[email protected]" />
@zmcghee
zmcghee / get_spreadsheet_id.py
Last active August 29, 2015 14:21
Fetch the first sheet of a Google Sheet file and work with it in Python.
def get_spreadsheet_id(user_input):
"""Accepts any form of Google Sheet URL or just the raw ID"""
if user_input.__contains__("spreadsheets/d"):
parts = user_input.split("/", 7)
if parts[4] == 'd':
return parts[5]
raise Exception("Couldn't get spreadsheet ID")
return user_input
if __name__ == "__main__":
@zmcghee
zmcghee / timestamp.js
Created June 4, 2013 21:31
JavaScript date format from UNIX timestamp
function date_str_from_unix(unix_timestamp) {
// var my_date_str = date_str_from_unix(1370383708);
// my_date_str returns "2013-06-04 17:08"
var leading_zero = function(i) {
return i.toString().length < 2 ? "0" + i : i
}
var date = new Date(unix_timestamp * 1000);
var date_str = date.getFullYear() + "-" + leading_zero(date.getMonth() + 1)
+ "-" + leading_zero(date.getDate()) + " "
+ leading_zero(date.getHours()) + ":"
from django.test.simple import DjangoTestSuiteRunner
class NoDbDjangoTestSuiteRunner(DjangoTestSuiteRunner):
def setup_databases(self, **kwargs):
return [], []
def teardown_databases(self, old_config, **kwargs):
pass
@zmcghee
zmcghee / nycreleases.txt
Created December 29, 2011 19:01
Breakdown of movies released commercially in NYC since '98
1998: 471
1999: 472
2000: 461
2001: 453
2002: 489
2003: 480
2004: 549
2005: 592
2006: 643
2007: 647
@zmcghee
zmcghee / lilsb.py
Created December 19, 2011 15:38
Grab lyrics from the song generator at phantomlyrics.org to tweet
"""
Script to grab lyrics from the song generator at phantomlyrics.org,
take 5 random verses from which you can choose, and make them ready
for Twitter.
"""
from httplib import HTTPConnection
from random import choice as random_choice
from sys import exit
from urllib import urlencode
@zmcghee
zmcghee / FakeQuerySet.py
Created June 30, 2011 10:43
Fake Django QuerySet
from django.db.models.query import EmptyQuerySet
class FakeQuerySet(EmptyQuerySet):
"""Turn a list into a Django QuerySet... kind of."""
def __init__(self, model=None, query=None, using=None, items=[]):
super(FakeQuerySet, self).__init__(model, query, using)
self._result_cache = items
def count(self):
return len(self)