Skip to content

Instantly share code, notes, and snippets.

View enquora's full-sized avatar

David Richardson enquora

  • Enquora Data Services
View GitHub Profile
@enquora
enquora / CGRectAspectFit.m
Created April 17, 2021 01:53 — forked from lanephillips/CGRectAspectFit.m
Objective-C code to fit a CGRect inside or outside another CGRect while maintaining aspect ratio. The fitted rectangle is centered on the target rectangle.
CGFloat ScaleToAspectFitRectInRect(CGRect rfit, CGRect rtarget)
{
// first try to match width
CGFloat s = CGRectGetWidth(rtarget) / CGRectGetWidth(rfit);
// if we scale the height to make the widths equal, does it still fit?
if (CGRectGetHeight(rfit) * s <= CGRectGetHeight(rtarget)) {
return s;
}
// no, match height instead
return CGRectGetHeight(rtarget) / CGRectGetHeight(rfit);
@enquora
enquora / gist:d12ce5a3abafebf91fe23b04884138c5
Created March 21, 2021 19:20
xcode environment variables
In many case, it's possible to provide different values when compiling to different architectures or different variant : MYSETTING_ppc, MYSETTING_x86, MYSETTING_normal, MYSETTING_debug, MYSETTING_normal_ppc.
Variables containing useful paths :
Local applications folder : LOCAL_APPS_DIR (defaults to /Applications)
Local utilities folder : LOCAL_ADMIN_APPS_DIR (defaults to /Applications/Utilities)
Local library folder : LOCAL_LIBRARY_DIR (defaults to /Library)
User folder : HOME (defaults to ~)
User applications folder : USER_APPS_DIR (defaults to ~/Applications)
User library folder : USER_LIBRARY_DIR (defaults to ~/Library)
Developer folder : DEVELOPER_DIR (defaults to /Developer)
Project base : PROJECT_DIR
@enquora
enquora / openresty.service
Created August 5, 2020 19:55 — forked from HauptJ/openresty.service
OpenResty Systemd service file
# Stop dance for OpenResty
# A modification of the Nginx systemd script
# Source: https://www.digitalocean.com/community/tutorials/how-to-use-the-openresty-web-framework-for-nginx-on-ubuntu-16-04
# =======================
#
# ExecStop sends SIGSTOP (graceful stop) to the Nginx process.
# If, after 5s (--retry QUIT/5) OpenResty is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if OpenResty is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
@enquora
enquora / pocket_exporter.py
Created July 6, 2020 15:45 — forked from jasonrdsouza/pocket_exporter.py
Export archived article data from Pocket
'''This script can be used to export data from Pocket (getpocket.com)
Uses include migrating to a different "read it later" service, saving
specific articles to another service, backing up your reading history,
and more.
Currently it can be used to export links and metadata for archived
articles with a given tag, which are more recent than a given timestamp.
An example use case is to export all articles you have tagged as
"to-export", which are newer than 10 days old. The timestamp functionality
@enquora
enquora / 2fa
Created April 3, 2020 04:42 — forked from MineRobber9000/2fa
2-factor authentication terminal app in Python
#!/usr/bin/env python
import os, os.path, stat, sys, base64
# TOTP lib inlined
import time, hmac, base64, hashlib, struct
def pack_counter(t):
return struct.pack(">Q", t)
@enquora
enquora / export_github_issues.py
Created December 3, 2019 07:09 — forked from msztolcman/export_github_issues.py
Export GitHub issues and comments to a csv files
#!/usr/bin/env python -tt
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
import os, os.path
import sys
import re
import time
from pprint import pprint
@enquora
enquora / etc-pf.anchors-emerging-threats
Created September 21, 2019 03:49 — forked from ikawnoclast/etc-pf.anchors-emerging-threats
Mac OS X pf firewall: Avoiding known bad guys, a blog post on ikawnoclastic thoughts
table <emerging_threats> persist file "/etc/emerging-Block-IPs.txt"
block log from <emerging_threats> to any
@enquora
enquora / JsonPlistConverter.py
Created September 7, 2019 04:22 — forked from pokstad/JsonPlistConverter.py
Convert between JSON and Plist Files
#!/usr/bin/env python
import plistlib
import json
import tkFileDialog
import re
import sys
file_to_open = tkFileDialog.askopenfilename(message="Select an existing plist or json file to convert.")
converted = None
@enquora
enquora / index.html
Created May 29, 2019 22:39 — forked from mattattui/index.html
Decimal alignment w/jQuery
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Decimal alignment test</title>
<script src="//code.jquery.com/jquery-2.1.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery.column.min.js" type="text/javascript" charset="utf-8"></script>
</head>
@enquora
enquora / simple_caverphone.py
Created May 14, 2019 22:35 — forked from kastnerkyle/simple_caverphone.py
Implementation of the Caverphone algorithm for phonetic shrinkage / substitution http://ntz-develop.blogspot.ca/2011/03/phonetic-algorithms.html
from collections import OrderedDict
import itertools
import re
# order of rules is very important
# this + ordered dict guarantees iteration order
def add_to(od, tups):
for tup in tups:
od.update({tup[0]: tup[1]})
return od