This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table <emerging_threats> persist file "/etc/emerging-Block-IPs.txt" | |
block log from <emerging_threats> to any |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |