Skip to content

Instantly share code, notes, and snippets.

View jaminguy's full-sized avatar

Jamin Guy jaminguy

View GitHub Profile
- (UIInterfaceOrientation)orientationByTransforming:(CGAffineTransform)transform fromOrientation:(UIInterfaceOrientation)c
{
CGFloat angle = atan2f(transform.b, transform.a);
NSInteger multiplier = (NSInteger)roundf(angle / M_PI_2);
UIInterfaceOrientation orientation = self.interfaceOrientation;
if (multiplier < 0) {
// clockwise rotation
while (multiplier++ < 0) {
switch (orientation) {
@jaminguy
jaminguy / gist:868a4a3be6a1b5f8c5f1
Created April 7, 2015 02:26
UISegmentedControl in UINavigationBar
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let segmentedControl = UISegmentedControl(items: ["Less Filling", "Tastes Great"])
segmentedControl.addTarget(self, action: "segmentChanged:", forControlEvents: UIControlEvents.ValueChanged)
segmentedControl.selectedSegmentIndex = 0
self.navigationItem.titleView = segmentedControl
}
func segmentChanged(sender: UISegmentedControl) {
@jaminguy
jaminguy / gist:11b1b793eb79a827e169
Created February 6, 2015 14:33
TODOs as warnings
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
git ls-files '*.h' '*.m' '*.swift' -z | \
xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | \
perl -p -e "s/($KEYWORDS)/ warning: \$1/"
@jaminguy
jaminguy / gist:2ca497affc41c4150dc5
Created May 20, 2014 15:03
Load a view from a nib in almost one line
+ (instancetype)newInstance {
id newInstance = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] firstObject];
return [newInstance isKindOfClass:[self class]] ? newInstance : nil;
}
#pragma mark - NSFetchedResultsControllerDelegate methods
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[self.tableView beginUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
robocopy "C:\Users\Public\Public Games" "D:\Backup\Games" /S /Z /PURGE /R:5 /W:5 /V
robocopy "C:\Users\Jamin\Desktop" "D:\Backup\Jamin\Desktop" /S /Z /PURGE /R:5 /W:5 /V
robocopy "C:\Users\Jamin\Downloads" "D:\Backup\Jamin\Downloads" /S /Z /PURGE /R:5 /W:5 /V
robocopy "C:\Users\Jamin\Documents" "D:\Backup\Jamin\Documents" /S /Z /PURGE /R:5 /W:5 /V
robocopy "C:\Users\Jamin\Music" "D:\Backup\Jamin\Music" /S /Z /PURGE /R:5 /W:5 /V
robocopy "C:\Users\Jamin\Pictures" "D:\Backup\Jamin\Pictures" /S /Z /PURGE /R:5 /W:5 /V
robocopy "C:\Users\Jamin\Videos" "D:\Backup\Jamin\Videos" /S /Z /PURGE /R:5 /W:5 /V
robocopy "C:\Users\Jamin\AppData" "D:\Backup\Jamin\AppData" /S /Z /PURGE /R:5 /W:5 /V
pause
@jaminguy
jaminguy / gist:5266853
Created March 28, 2013 21:13
Header dump from an AFNetwork get call from iOS to http://httpecho.heroku.com/headers.json
[
[
"HTTP_ACCEPT",
"*/*"
],
[
"HTTP_HOST",
"httpecho.heroku.com"
],
[
def on_receive(self, response_chunk):
self.response_object += str(response_chunk).strip()
if response_chunk.endswith("\r\n") and self.response_object.strip():
try:
adn_object = self.response_object.strip()
self.publish_message(adn_object)
except Exception as e:
text = "on_receive error {}".format(e)
print text
log.error(text)
{
"match_policy": "include_any",
"clauses": [
{
"operator": "one_of",
"field": "/data/entities/mentions/*/id",
"object_type": "post",
"value": [
"5952",
"26215",
- (void)configureScoreDescriptionText {
if(kloutUser.kscoreDescription) {
CTTextAlignment kAlignment = kCTLeftTextAlignment;
CGFloat lineSpacing = 1.0;
CTParagraphStyleSetting paragraphSettings[] = {
{ kCTParagraphStyleSpecifierAlignment, sizeof(kAlignment), &kAlignment},
{ kCTParagraphStyleSpecifierLineSpacing, sizeof(lineSpacing), &lineSpacing}
};
NSMutableDictionary *stringAttributes = [NSMutableDictionary dictionary];
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(paragraphSettings, sizeof(paragraphSettings));