Skip to content

Instantly share code, notes, and snippets.

@nkavanagh
nkavanagh / DeviceUID.m
Created March 24, 2016 13:01 — forked from miguelcma/DeviceUID.m
iOS Unique Device ID that persists between app reinstalls
/* DeviceUID.h
#import <Foundation/Foundation.h>
@interface DeviceUID : NSObject
+ (NSString *)uid;
@end
*/
// Device.m
@nkavanagh
nkavanagh / FCPrivateBatteryStatus.m
Created March 15, 2016 19:16
How to get raw battery info (mAh remaining, etc.) from iOS using private APIs. For internal testing only, NOT APP STORE DISTRIBUTION!
#import <Foundation/Foundation.h>
#include <dlfcn.h>
NSDictionary *FCPrivateBatteryStatus()
{
static mach_port_t *s_kIOMasterPortDefault;
static kern_return_t (*s_IORegistryEntryCreateCFProperties)(mach_port_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, UInt32 options);
static mach_port_t (*s_IOServiceGetMatchingService)(mach_port_t masterPort, CFDictionaryRef matching CF_RELEASES_ARGUMENT);
static CFMutableDictionaryRef (*s_IOServiceMatching)(const char *name);
@nkavanagh
nkavanagh / rd-profile.py
Created February 5, 2015 20:33
Collect profiling information from `procfs`
#!/usr/bin/env python
# encoding: utf-8
"""
Profile system performance
Created by Niall Kavanagh <[email protected]> on 2/5/2015
"""
from __future__ import print_function
import argparse
import time
@nkavanagh
nkavanagh / fib.dfy
Last active August 29, 2015 14:01
Dafny code to verify a Fibonacci implementation
function method fibn(n: int, f1: int, f2: int): int
requires n >= 0;
decreases n;
{
if n > 1 then fibn(n-1, f2, f1+f2) else f2
}
function method fib(n: int): int
requires n >= 0;
decreases n;
@danielpunkass I think you underestimate how big cities are.
@nkavanagh
nkavanagh / notify.sh
Created February 4, 2014 19:52 — forked from jehiah/notify.sh
#!/bin/bash
#
# *************************************************
# chkconfig: 2345 99 99
# description: notify email address on system boot.
# *************************************************
# Installing:
# 1) save as /etc/rc.d/init.d/notify
# 2) set the desired email address in "MAILADD" variable
# 3) chmod a+w /etc/rc.d/init.d/notify
#!/bin/bash
# Copyright bitly, Aug 2011
# written by Jehiah Czebotar
DATAFILE="/var/tmp/nagios_check_forkrate.dat"
VALID_INTERVAL=600
OK=0
WARNING=1
CRITICAL=2
@nkavanagh
nkavanagh / memcached_sample.sh
Created August 7, 2013 16:48
Very quick and dirty script to sample memcached statistics and log to a CSV file.
#!/bin/bash
tmp="/var/tmp"
scripts=$(dirname $0)
scripts=$(cd "$scripts" && pwd)
datetime=$(date "+%F %T")
output_dir="$scripts"
lockfile="$output_dir/sample.lock"
@nkavanagh
nkavanagh / gist:5824369
Created June 20, 2013 16:38
iOS Macros
#define RGB(r, g, b)
[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define RGBA(r, g, b, a)
[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
@implementation UITextView (RSExtras)
static BOOL stringCharacterIsAllowedAsPartOfLink(NSString *s) {
/*[s length] is assumed to be 0 or 1. s may be nil.
Totally not a strict check.*/
if (s == nil || [s length] < 1)
return NO;