Skip to content

Instantly share code, notes, and snippets.

# 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 ) {
<html>
<head>
</head>
<body>
<div id="fb-root"></div><script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3"; fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script><div class="fb-video" data-allowfullscreen="1" data-href="/lovewhatreallymatters/videos/vb.691679627521105/1097052790317118/?type=3"><div class="fb-xfbml-parse-ignore"><blockquote cite="https://www.facebook.com/lovewhatreallymatters/videos/1097052790317118/"><a href="https://www.facebook.com/lovewhatreallymatters/videos/1097052790317118/">Too Much Cuteness</a><p>All aboard the cute train! :) #LoveWhatMatters Video courtesy of ViralHog</p>Posted by <a href="https://www.facebook.com/lovewhatreallymatters/">Love What Matters</a> on Monday, March 28, 2016</blockquote></div></div>
</body>
</html>
/*
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/Icon-60@2x.png" />
<link rel="apple-touch-icon" sizes="180x180" href="ios/AppIcon.appiconset/Icon-60@3x.png" />
<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/Icon-76@2x.png" />
<link rel="apple-touch-icon" sizes="58x58" href="ios/AppIcon.appiconset/Icon-Small@2x.png" />
@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()) + ":"
@zmcghee
zmcghee / drafthouse_vegan.md
Created April 18, 2012 14:54
Drafthouse - Vegan menu items

I was told by a manager these items are vegan:

  • Red pepper hummus
  • Chips and salsa
  • Nachos no cheese, no sour cream, no chicken... I'm vegetarian and often get the nachos and add green chiles. So delicious and I imagine they would still be good with no cheese. We could also sub tofu.
  • One of the vegetarian pizzas with no cheese. I think the "Big Fat Greek Pizza" has the most veggies.
  • House salad with any of the following dressings: spicy peanut, balsamic vinaigrette, jalapeno-lime vinaigrette, red wine shallot vinaigrette or lemon vinaigrette.
  • Asian salad sub tofu
  • Once Upon a Time in Mexico salad sub tofu and no cotija cheese.
  • Black bean burger with no dijon ailoi (bun is vegan)
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