Skip to content

Instantly share code, notes, and snippets.

View software-mariodiana's full-sized avatar

Mario Diana software-mariodiana

View GitHub Profile
@software-mariodiana
software-mariodiana / JNAWindowsRegistry.java
Last active September 20, 2022 12:23
Accessing the Windows registry via Java, using JNA.
import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.WinReg;
/*
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
@software-mariodiana
software-mariodiana / detect_notch.m
Last active June 10, 2022 00:23
Objective-C method to detect whether the iOS device has a "notch," à la iPhone X.
#import <LocalAuthentication/LocalAuthentication.h>
/**
* Return YES if iOS device has a notch; NO, otherwise.
*/
- (BOOL)hasDeviceNotch
{
if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)) {
return NO;
}
@software-mariodiana
software-mariodiana / Xcode-nullability
Last active November 30, 2021 02:17
Turn off nullability warnings in Xcode. These warning are added so that Objective-C code will be compatible with Swift. However, with respect to Objective-C code, they are a whole lot of clutter.
In the Build Settings tab of a project's target, find the custom compile flag
key for the following entry:
Other Warning Flags
Set that flag's value to:
-Wno-nullability-completeness
See: https://stackoverflow.com/a/37691096/155167
@software-mariodiana
software-mariodiana / http_errors.ts
Created July 21, 2021 19:34
TypeScript function mapping HTTP error codes to their descriptions.
const lookupHTTPError = (code: number): string => {
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
const HTTPErrorCodes: { [key: number]: string } = {
400: 'Bad Request',
401: 'Unauthorized',
402: 'Payment Required',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
406: 'Not Acceptable',
@software-mariodiana
software-mariodiana / UIImageFixIOS13Bug.m
Last active June 25, 2021 00:29
We swizzle in a fix for the iOS 13 RouteMe/Mapbox (legacy) tiling bug via a category on UIImage.
#import "UIImage+FixIOS13Bug.h"
#import <objc/runtime.h>
/**
* Fix UIImage -drawRect: bug in iOS 13 that impacts RouteMe library tiling.
*
* SEE: https://forums.developer.apple.com/thread/120526
*/
@implementation UIImage (FixIOS13Bug)
#import "MDXEllipseView.h"
@interface MDXEllipseView ()
@property (nonatomic, strong) UIColor* mdx_backgroundColor;
@end
IB_DESIGNABLE
@implementation MDXEllipseView
- (void)setBackgroundColor:(UIColor *)backgroundColor
@software-mariodiana
software-mariodiana / dispatch_time_example.m
Last active March 22, 2021 18:07
Apple documentation lacks milliseconds. This example illustrates use.
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
@autoreleasepool {
// Arg 2 is nanoseconds.
//
// https://developer.apple.com/documentation/dispatch/1420519-dispatch_time
dispatch_time_t now = dispatch_time(DISPATCH_TIME_NOW, 0);
@software-mariodiana
software-mariodiana / gist:7217067cd73a3186daec9b3aebaf6e9b
Created January 16, 2021 16:58 — forked from djaiss/gist:85a0ada83e6bca68e41e
Block Twitter/Facebook in your /etc/hosts
# Block Facebook IPv4
127.0.0.1 www.facebook.com
127.0.0.1 facebook.com
127.0.0.1 login.facebook.com
127.0.0.1 www.login.facebook.com
127.0.0.1 fbcdn.net
127.0.0.1 www.fbcdn.net
127.0.0.1 fbcdn.com
127.0.0.1 www.fbcdn.com
127.0.0.1 static.ak.fbcdn.net
@software-mariodiana
software-mariodiana / development_podfile
Created January 2, 2021 23:39
Integrating a CocoaPod downloaded locally to the same parent directory as its client project. Here, the pod incorporates a 3rd-party library which must be accounted for.
# Uncomment the next line to define a global platform for your project
platform :ios, '10.2'
target 'MapboxPodClient' do
# Comment the next line if you don't want to use dynamic frameworks
#use_frameworks!
# Pods for MapboxPodClient
pod 'Mapbox-iOS-SDK', :path => '../mapbox-ios-sdk-legacy', :share_schemes_for_development_pods => true
@software-mariodiana
software-mariodiana / date_surprise.m
Last active December 3, 2020 10:07
Date localization does unexpected things if all you're familiar with is U.S. dates.
// iPhone settings: "Denmark" for region and "Buddhist" for calendar.
NSDate* now = [NSDate date];
NSDateFormatter* df = [[NSDateFormatter alloc] init];
df.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
df.timeStyle = NSDateFormatterMediumStyle;
df.dateStyle = NSDateFormatterShortStyle;
// Date: 30/10/2563 BE, 14.32.18
NSLog(@"Date: %@", [df stringFromDate:now]);