Skip to content

Instantly share code, notes, and snippets.

View snosrap's full-sized avatar

snosrap snosrap

View GitHub Profile
@snosrap
snosrap / pandoc_filter_basehref.py
Created December 27, 2022 08:05
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
BASEURL = "https://example.com"
def basehref(key, value, format, meta):
if key == "Image":
[[id, classes, attrs], children, [src, title]] = value
#!/bin/bash
for f in "$@"
do
BASENAME=`basename "$f"`
/usr/sbin/cupsfilter "$f" > "${f}.pdf" 2> "/tmp/${BASENAME}.stderr.txt"
done
@snosrap
snosrap / HTMLTableElement.prototype.fp_toTable.html
Last active September 21, 2022 01:26
Convert HTMLTableElement (with rowSpan and colSpan) into a JavaScript Array
<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++) {
#!/usr/bin/python
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
snosrap / FPNetServiceTXTRecord.h
Last active December 18, 2017 22:57
Adds a `fp_TXTRecord` category to NSNetService to allow for more natural access to TXT record data.
#import <Foundation/Foundation.h>
@interface FPNetServiceTXTRecord : NSObject
@property NSNetService *netService;
- (NSString *)objectForKeyedSubscript:(NSString *)key;
@end
@interface NSNetService (FPNetServiceAddtions)
- (FPNetServiceTXTRecord *)fp_TXTRecord;
@end
@interface FPDistributedNotificationCenter : NSObject
@end
@implementation FPDistributedNotificationCenter
- (id)init {
if(self = [super init]) {
[NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(receivedDistributedNotification:) name:nil object:nil];
}
return self;
}
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]);
}
}
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
if([view isKindOfClass:UITableViewHeaderFooterView.class]) {
((UITableViewHeaderFooterView *)view).textLabel.text = [self tableView:tableView titleForHeaderInSection:section];
}
}
// 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];
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