Skip to content

Instantly share code, notes, and snippets.

View benjaminbojko's full-sized avatar

Benjamin Bojko benjaminbojko

View GitHub Profile
@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 / 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 / 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";
@benjaminbojko
benjaminbojko / ProjectConfig.props
Created December 21, 2018 21:53
VS CinderPath Property Sheet
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="CreateUserConfig; AddCinderDir">
<ImportGroup Label="PropertySheets" />
<ItemDefinitionGroup />
<PropertyGroup Label="FileReferences">
<!-- Default Cinder path relative to this file; Override in custom props file -->
<CinderDir>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..'))</CinderDir>
<UserFile>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\UserConfig.props'))</UserFile>
</PropertyGroup>
@benjaminbojko
benjaminbojko / glm_quat_angle_test.h
Last active August 24, 2017 17:06
GLM Quaternion angleAxis to angle vs roll
vector<float> degs = {60, 120, 180, 240, 300, 360, 420, 480, -60, -120, -180, -240, -300, -360, -420, -480};
// angleAxis -> angle
for (float deg : degs) {
float rad = glm::radians(deg);
glm::quat rot = glm::angleAxis(rad, glm::vec3(0, 0, 1));
std::cout << "angleAxis -> angle: " + to_string(deg) + " deg -> " + to_string(glm::degrees(glm::angle(rot))) + " deg" << std::endl;
}
// angleAxis -> roll
@benjaminbojko
benjaminbojko / AnimOperators.h
Last active July 27, 2017 00:14
Cinder Animation Operators
#pragma once
#include "cinder/Tween.h"
//==================================================
// Anim<T> + T
//
template<typename T>
inline T operator + (const ci::Anim<T> & tween, const T & value) {
@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 / 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 / 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.