Skip to content

Instantly share code, notes, and snippets.

View benjaminbojko's full-sized avatar

Benjamin Bojko benjaminbojko

View GitHub Profile
@benjaminbojko
benjaminbojko / gist:3751079
Created September 19, 2012 17:50
Convert NodeJS JSON Date String to Objective C Date
// Modified version of an Apple Docs example that accomodates for the extra milliseconds used in NodeJS/JS dates
// https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1
- (NSDate *)dateForRFC3339DateTimeString:(NSString *)rfc3339DateTimeString {
NSDateFormatter *rfc3339DateFormatter = [[NSDateFormatter alloc] init];
[rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'"];
[rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
// Convert the RFC 3339 date time string to an NSDate.
@benjaminbojko
benjaminbojko / gist:4028025
Created November 6, 2012 22:18
Flip and Reload a single UIView
/// based on http://stackoverflow.com/questions/347721/how-do-i-apply-a-perspective-transform-to-a-uiview
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseIn animations:^{
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -500;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI_2, 0.0f, 1.0f, 0.0f);
[self.view.layer setTransform:rotationAndPerspectiveTransform];
} completion:^(BOOL finished) {
// REFRESH YOUR VIEW HERE
@benjaminbojko
benjaminbojko / .jsbeautifyrc
Last active August 29, 2015 13:56
JS Beautify Settings
{
// Details: https://github.com/victorporof/Sublime-HTMLPrettify#using-your-own-jsbeautifyrc-options
// Documentation: https://github.com/einars/js-beautify/
"html": {
"brace_style": "collapse", // "expand", "end-expand", "expand-strict"
"indent_char": " ",
"indent_scripts": "keep", // "separate", "normal"
"indent_size": 2,
"max_preserve_newlines": 10,
"preserve_newlines": true,
@benjaminbojko
benjaminbojko / gist:f38e88daab3a10b5ee7c
Last active August 29, 2015 14:02
[Cinder] Different Image Sizing Snippets
using namespace ci;
enum Sizing {
//! Native resolution with no scaling
Native,
//! Fit exactly by scaling x/y independently
Fit,
//! Resize to fit at least mSize while maintaining aspect ratio
Aspect,
//! Resize to fit at most mSize while maintaining aspect ratio
@benjaminbojko
benjaminbojko / iOS Background Download Gotchas.md
Last active August 10, 2019 00:38
iOS Background Download Gotchas

iOS Background Download Gotchas

I've been doing some thorough investigations into setting up a solid background download process. Here are some of the gotchas I stumbled upon and wanted to capture:

Background Tasks

  • Only download and upload tasks are allowed to run in the background (no data tasks)
  • Once a download task completes, your app will have to move that task from its temporary location to a permament location (or process the data somehow); The temporary file will be deleted once the URLSession:downloadTask:didFinishDownloadingToURL: delegate method returns.

App Suspension

  • If your app is suspended, it will be re-launched whenever a background task completes
@benjaminbojko
benjaminbojko / .clang-format
Created August 5, 2014 17:34
Clang Format Settings for Xcode iOS Projects
---
BasedOnStyle: Google
PointerBindsToType: false
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
ColumnLimit: 160
UseTab: Never
IndentWidth: 4
TabWidth: 4
AllowAllParametersOfDeclarationOnNextLine: false
@benjaminbojko
benjaminbojko / color-workflow-tools.md
Last active August 29, 2015 14:05
Color Workflow Tools

Color Workflow Tools

No matter how well organized or spec'ed out a PSD is, there's always that point where you have to manually bring colors from design to code. Here are a few tools that have helped me get a seamless 360° workflow for dealing with colors in OS X.

Alfred 2 Colors Workflow

Amazing workflow by Tyler Eich that allows you to preview, modify and convert colors in a bunch of different color spaces and formats (rgb, hsl, hex, ...). Great if you want to convert those hex values to RGB for CSS.

@benjaminbojko
benjaminbojko / UITextView+LayoutHelpers.h
Last active August 29, 2015 14:08
Calculate content size for UITextView
//
// UITextView+LayoutHelpers.h
//
// Created by Benjamin Bojko on 10/24/14.
// Copyright (c) 2014 Benjamin Bojko. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UITextView (LayoutHelpers)
@benjaminbojko
benjaminbojko / LinkedTextView.h
Last active March 21, 2024 18:22
UITextView Subclass to avoid Long-Press Delays with embedded Links
//
// LinkedTextView.h
//
// Created by Benjamin Bojko on 10/22/14.
//
// The MIT License (MIT)
//
// Copyright (c) 2014 Benjamin Bojko
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@benjaminbojko
benjaminbojko / CinderProjectApp.cpp
Created December 17, 2014 23:32
Display RTSP Stream in Cinder using OpenCV
#include "cinder/app/AppNative.h"
#include "cinder/gl/Texture.h"
#include "CinderOpenCV.h"
using namespace ci;
using namespace ci::app;
static std::string const VideoStreamAddress = "rtsp://user:pass@domain.com/path/to/stream";