Skip to content

Instantly share code, notes, and snippets.

@ozouai
ozouai / SuffxCode.m
Last active June 9, 2016 10:30
Determine English Ordinal Suffix from NSDate
// Omar Zouai | https://omarzouai.com/
-(NSString*) suffixForDate:(NSDate*) date {
NSDateFormatter *monthDayFormatter = [[NSDateFormatter alloc] init];
[monthDayFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[monthDayFormatter setDateFormat:@"d"];
int date_day = [[monthDayFormatter stringFromDate:date] intValue];
NSString *suffix = @"th";
if(date_day <=10 || date_day >=20) {
int singleDay = (date_day%10);
if(singleDay == 1) suffix = @"st";
@ozouai
ozouai / HTMLtoAttributedString.m
Last active June 24, 2017 03:48
Turns HTML into an attributed string with a custom font and paragraph spacing
// Omar Zouai | https://omarzouai.com/
- (NSMutableAttributedString*)htmlToAttributed:(NSString*)html font:(UIFont*)font paragraphSpacing:(CGFloat)pSpacing {
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute:@(NSUTF8StringEncoding)} documentAttributes:nil error:nil];
[string beginEditing];
NSMutableParagraphStyle *pStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
[pStyle setParagraphSpacing:pSpacing];
[string enumerateAttributesInRange:NSMakeRange(0, string.length) options:nil usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) {
UIFont *theFont = [attrs objectForKey:@"NSFont"];
@ozouai
ozouai / node-forge.d.ts
Last active September 2, 2016 05:53
Typings for Node-Forge
declare module "node-forge" {
export namespace pki {
export class Key {
e: any;
n: any;
}
export class PrivateKey extends Key {
d: any;
}
@ozouai
ozouai / GeneratePinAsync.js
Last active May 8, 2017 04:44
Node SecurePIN
var securePin = require("secure-pin");
securePin.generatePin(4, function(pin) {
console.log(pin);
});
@ozouai
ozouai / _model.yml
Created July 4, 2017 18:37
ModelType Example
---
Name: ModelType Test
Heads:
Java: |
// This is the head for the java file
package com.modeltype.Test;
MongooseTS: |
// This is the head for the mongoose file
import * as crypto from "crypto";
@ozouai
ozouai / strongswan- unifi-l2tp-proposals.txt
Created December 26, 2019 00:29
StrongSwan Unifi L2TP Proposals
phase 1: 3des-sha1-modp1024
phase 2: aes256-sha1-modp1024
@ozouai
ozouai / pf.conf
Last active February 14, 2020 05:36
/etc/pf.conf for Mac OS X
# Ruleset to block all incoming traffic on WiFi
block in on en0
pass out on en0 keep state
# Rules to allow DHCP (you won't get an address without these)
pass in on en0 proto udp from any port 68
pass in on en0 proto udp from any port 67
# Rules for Bonjour (uncomment these to allow Bonjour to work)
# Bonjour is needed for AirPlay, Home Sharing, Printer Discovery, etc.
# You can constrict this to your home network by changing any to your home network (E.x. 192.168.1.0/24)