Skip to content

Instantly share code, notes, and snippets.


snosrap snosrap

View GitHub Profile
snosrap /
Created Dec 27, 2022
python pandoc filter to add a base href/url to each image src
#!/usr/bin/env python3
from urllib.parse import urljoin
from pandocfilters import toJSONFilter, Image
def basehref(key, value, format, meta):
if key == "Image":
[[id, classes, attrs], children, [src, title]] = value
for f in "$@"
BASENAME=`basename "$f"`
/usr/sbin/cupsfilter "$f" > "${f}.pdf" 2> "/tmp/${BASENAME}.stderr.txt"
snosrap / HTMLTableElement.prototype.fp_toTable.html
Last active Sep 21, 2022
Convert HTMLTableElement (with rowSpan and colSpan) into a JavaScript Array
View HTMLTableElement.prototype.fp_toTable.html
<script type="text/javascript">
HTMLTableElement.prototype.fp_toTable = function(nullvalue = null) {
var columnCount = Array.from(this.rows).map(row => Array.from(row.cells).reduce((sum, cell) => sum + cell.colSpan, 0)).reduce((max, row) => Math.max(max, row), 0);
var itemCount = Array.from(this.rows).reduce((rsum, row) => rsum + Array.from(row.cells).reduce((csum, cell) => csum + (cell.colSpan * cell.rowSpan), 0), 0);
var rowCount = itemCount / columnCount;
var items = Array.apply(null, Array(itemCount));
tds = Array.from(this.getElementsByTagName('td'));
for(var i=0, ii=0; i<tds.length; i++, ii=items.indexOf(undefined, i)) {
items[ii] = tds[i].innerText;
for(var j=0;j<tds[i].colSpan;j++) {
import sys, zlib, re
def print_streams(bytes, start=0):
r = re.compile("BT.*?\((.*?)\)[\s]*?Tj.*?ET", re.DOTALL)
while True:
start = bytes.find("stream", bytes.find("FlateDecode", start)) + len("stream")
if start < len("stream"): return
end = bytes.find("endstream", start)
snosrap / FPNetServiceTXTRecord.h
Last active Dec 18, 2017
Adds a `fp_TXTRecord` category to NSNetService to allow for more natural access to TXT record data.
View FPNetServiceTXTRecord.h
#import <Foundation/Foundation.h>
@interface FPNetServiceTXTRecord : NSObject
@property NSNetService *netService;
- (NSString *)objectForKeyedSubscript:(NSString *)key;
@interface NSNetService (FPNetServiceAddtions)
- (FPNetServiceTXTRecord *)fp_TXTRecord;
View FPDistributedNotificationCenter
@interface FPDistributedNotificationCenter : NSObject
@implementation FPDistributedNotificationCenter
- (id)init {
if(self = [super init]) {
[NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(receivedDistributedNotification:) name:nil object:nil];
return self;
View getservbyname.m
struct servent *s = getservbyname("http", NULL);
if(!!s) {
NSLog(@"%s %i %s", s->s_name, CFSwapInt16BigToHost(s->s_port), s->s_proto);
for(size_t i=0; !!s->s_aliases[i]; i++) {
NSLog(@"%lu\t%s", i, s->s_aliases[i]);
View UnUppercaseTableView.m
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
if([view isKindOfClass:UITableViewHeaderFooterView.class]) {
((UITableViewHeaderFooterView *)view).textLabel.text = [self tableView:tableView titleForHeaderInSection:section];
View NSUserDefaults+ParameterlessOptions.m
// Enable parameterless options (e.g., `-verbose`) to be passed in as command line arguments.
NSMutableDictionary *arguments = [[NSUserDefaults.standardUserDefaults volatileDomainForName:NSArgumentDomain] mutableCopy];
for(NSString *arg in NSProcessInfo.processInfo.arguments)
if([arg hasPrefix:@"-"] && [arguments objectForKey:[arg substringFromIndex:1]] == nil)
[arguments setObject:@YES forKey:[arg substringFromIndex:1]];
[NSUserDefaults.standardUserDefaults removeVolatileDomainForName:NSArgumentDomain]; // remove to prevent NSInvalidArgumentException (per documentation)
[NSUserDefaults.standardUserDefaults setVolatileDomain:arguments forName:NSArgumentDomain];
View CBUUIDNames.m
for(int i=0;i<256;i++) {
CBUUID *u = [CBUUID UUIDWithString:[NSString stringWithFormat:@"18%02X", i]];
if(![u.UUIDString isEqualToString:u.description])
NSLog(@"%@\t%@", u.UUIDString, u.description);
// 1800 Generic Access Profile
// 1801 Generic Attribute Profile
// 1805 Current Time
// 1808 Glucose