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 / 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',
#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 / split_string.m
Created November 23, 2020 23:34
Split an NSString into an NSArray of its characters.
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSString* s = @"antidisestablishmentarianism";
unichar* buffer = (unichar *)malloc(sizeof(unichar) * [s length]);
[s getCharacters:buffer range:NSMakeRange(0, [s length])];
NSMutableArray* temp = [NSMutableArray arrayWithCapacity:[s length]];
@software-mariodiana
software-mariodiana / iso_8601_category.m
Last active October 30, 2020 16:45
Category on NSDate to print timestamp in ISO-8601 format.
#import <Foundation/Foundation.h>
@interface NSDate (ISO8601)
- (NSString *)mdx_canonicalTimestamp;
@end
@implementation NSDate (ISO8601)
- (NSString *)mdx_canonicalTimestamp
{
@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]);
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
@interface MyParent : NSObject
- (NSInteger)fetchNumber;
@end
@implementation MyParent
- (NSInteger)fetchNumber
- (UIImage *)imageFromWand:(MagickWand *)wand
{
const char* map = "ARGB";
NSInteger w = MagickGetImageWidth(wand);
NSInteger h = MagickGetImageHeight(wand);
NSInteger size = strlen(map) * w * h * sizeof(char);
void* buffer = (void *)malloc(size);