Skip to content

Instantly share code, notes, and snippets.

@thefotes
thefotes / gist:5956796
Created July 9, 2013 11:56
Put an image on the screen and then allow for a user to drag by way of a touch event. This example comes from the book "iOS Programming: The Big Nerd Ranch Guide, Third Edition" by Joe Conway and Aaron Hillegas.
#import "PMViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface PMViewController ()
{
CALayer *boxLayer;
}
@end
@implementation PMViewController
@thefotes
thefotes / LendingClub.py
Last active August 29, 2015 14:06
Check your Lending Club account and email yourself if you have more than $25
#!/usr/bin/env python
import mechanize
from bs4 import BeautifulSoup
import smtplib
from email.mime.text import MIMEText
URL = 'https://www.lendingclub.com/account/gotoLogin.action'
LENDING_CLUB_EMAIL = ''
LENDING_CLUB_PASSWORD = ''
GMAIL_ADDRESS = ''
@thefotes
thefotes / gist:89f7b0407699073d8815
Created April 9, 2015 15:47
Camel Case String in Objective-C
//
// NSString+CamelCase.m
// CamelCase
//
// Created by Peter Foti on 4/9/15.
// Copyright (c) 2015 Peter Foti. All rights reserved.
//
#import "NSString+CamelCase.h"
@thefotes
thefotes / LineCount
Created April 14, 2015 14:45
Counts number of files in each subdirectory of the current directory
#!/bin/bash
set -e
for d in */; do
count=$(find $d -type f | wc -l)
if [[ $count -eq 1 ]]; then
result="$d $count"
echo $result >> results.txt
fi
@thefotes
thefotes / NSObject+PropertyDictionary.m
Created April 22, 2015 13:54
Returns dictionary with property names as keys, and their values as the object
// NSObject+PropertyDictionary.m
//
// Created by Peter Foti on 4/22/15.
#import "NSObject+PropertyDictionary.h"
#import <objc/runtime.h>
@implementation NSObject (PropertyDictionary)
- (NSDictionary *)toDictionary
@thefotes
thefotes / dupeImports.sh
Created June 28, 2015 19:11
Given a path to an Xcode project, loops through all files and checks to see if any files have been imported more than once in the same file.
#!/bin/bash
set -e
read -e -p "Enter path to Xcode project: " FILES
eval FILES=$FILES
find "$FILES" -type f \( -name "*.h" -or -name "*.m" \) | while read -r f;
do
@thefotes
thefotes / localized.swift
Created January 17, 2016 13:33
Cleaner localized strings with Swift protocols and enums.
import Foundation
// Localized string struct that has single static method which accepts a `Localizeable` value.
struct LocalizedString {
// Usage: LocalizedString.localizedStringForValue(NavBarTitle.Home)
static func localizedStringForValue<T: Localizeable>(localizeableValue: T) -> String {
return NSLocalizedString(localizeableValue.localizedString, comment: localizeableValue.localizedStringComment)
@thefotes
thefotes / ow.sh
Created January 25, 2016 18:46
Checks current directory for either .xcworkspace or .xcodeproj, if it finds xcworkspace opens that, otherwise opens xcodeproj
#!/bin/bash
set -e
xcodeproj=`find . -maxdepth 1 -name "*.xcodeproj"`
proj_name=`echo $xcodeproj | sed 's/.\///g' | sed 's/.xcodeproj//g'`
xcworkspace=`find . -maxdepth 1 -name "$proj_name.xcworkspace"`
if [[ ! -z $xcworkspace && -e $xcworkspace ]]; then
open $xcworkspace
//
// PJNotificationCenter.m
// NotificationSample
//
// Created by Peter Foti on 6/21/16.
// Copyright © 2016 Peter Foti. All rights reserved.
//
#import "PJNotificationCenter.h"
#import "PJNotificationKey.h"
import Foundation
protocol PJPageControlUsable {
var indicatorType: PJPageControl.Indicator { get }
}
protocol PJPageControlDelegate: class {