Skip to content

Instantly share code, notes, and snippets.

View cbowns's full-sized avatar

Christopher Bowns cbowns

View GitHub Profile
@nikolay-n
nikolay-n / defsmon.py
Last active October 29, 2022 14:26
Defaults Monitor - tool to sniff defaults keys and values using unified log
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
'''
Defaults Monitor - tool to sniff defaults keys and values using unified log
to launch use standard python 2.7, eg python2.7 ./defsmon.py
'''
import os
@jkreileder
jkreileder / whoop-goldencheetah.py
Last active November 20, 2023 17:38
Python 3 script to export WHOOP Strap recovery data for use with Golden Cheetah
#!/usr/bin/env python3
import requests # for getting URL
import json # for parsing json
from datetime import datetime # datetime parsing
import pytz # timezone adjusting
import csv # for making csv files
import os
#################################################################
@rafmagana
rafmagana / unwatch-repos.js
Last active May 19, 2021 23:05
Unwatch multiple repositories at once in GiHub
/* USAGE
Go to https://github.com/watching
Paste this function in the console
e.g. unwatchRepos("rails|node|go")
That unwatches repos containing rails, node or go in the repo link.
*/
var unwatchRepos = (pattern) => {
var list = document.getElementsByClassName('repo-list')[0]
var rows = list.getElementsByClassName('js-subscription-row')
@steipete
steipete / UITableViewMore.m
Last active January 29, 2018 14:19
Using the "More" button. Of course the simple way that Apple uses in Mail/iOS is not public. rdar://16600859
- (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"More";
}
- (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"I wanted to be a pretty public API, but then time ran out and they forgot me...");
// Hide the More/Delete menu.
[self setEditing:NO animated:YES];
}
@steipete
steipete / UIView+PSPDFKitAdditions.h
Last active August 26, 2022 09:00
Simple solution that allows to block the parent layoutSubview-triggering, see https://gist.github.com/steipete/9723421. In short, changing a frame of a subview outside of layoutSubviews will trigger the parent's layoutSubviews. Sometimes this is not what we want, especially when you consider performance. In my case (http://pspdfkit.com) this was…
@interface UIView (PSPDFKitAdditions)
// Allows to change frame/bounds without triggering `layoutSubviews` on the parent.
// Not needed for changes that are performed within `layoutSubviews`.
- (void)pspdf_performWithoutTriggeringSetNeedsLayout:(dispatch_block_t)block;
@end
#import "UIView+PSPDFKitAdditions.h"
@steipete
steipete / Macros.h
Last active January 6, 2024 07:24
Declare on your main init that all other init methods should call. It's a nice additional semantic warning. Works with Xcode 5.1 and above. Not tested with earlier variants, but should just be ignored. A reference to this macro shortly appeared in https://developer.apple.com/library/ios/releasenotes/ObjectiveC/ModernizationObjC/AdoptingModernObj…
#ifndef NS_DESIGNATED_INITIALIZER
#if __has_attribute(objc_designated_initializer)
#define NS_DESIGNATED_INITIALIZER __attribute((objc_designated_initializer))
#else
#define NS_DESIGNATED_INITIALIZER
#endif
#endif
@steipete
steipete / gist:9021032
Created February 15, 2014 15:43
Run Script that converts TODO or FIXME or ??? into a warning. Super useful.
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"
static void PSPDFFixCenteringInPrinterBrowserViewController(void) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Patch the `UIPrinterSearchingView` class so we get a sane label placement in iOS 7.
Class printerSearchingViewClass = NSClassFromString([NSString stringWithFormat:@"UI%@Searching%@", @"Printer", @"View"]);
if (printerSearchingViewClass) {
SEL customLayoutSubviewsSEL = NSSelectorFromString(@"pspdf_layoutSubviews");
id customLayoutSubviews = ^(UIView *_self) {
((void( *)(id, SEL))objc_msgSend)(_self, customLayoutSubviewsSEL); // call original.
@try {
/**
Provides the ability to verify key paths at compile time.
If "keyPath" does not exist, a compile-time error will be generated.
Example:
// Verifies "isFinished" exists on "operation".
NSString *key = SQKeyPath(operation, isFinished);
// Verifies "isFinished" exists on self.
@lennypham
lennypham / gist:7026020
Created October 17, 2013 14:31
Macro for converting hex color values into a UIColor object.
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]