Skip to content

Instantly share code, notes, and snippets.

View drosenstark's full-sized avatar

Dan Rosenstark drosenstark

View GitHub Profile
@drosenstark
drosenstark / git-rbranch
Created February 8, 2015 07:26
Dan's Git Rbranch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD);
echo "git-rbranch: Creating local branch $1"
git checkout -b $1 # make the branch locally
echo "git-rbranch: Pushing $1 to the server"
git push origin $1 #push it to the server
echo "git-rbranch: Checking out $CURRENT_BRANCH again"
git checkout $CURRENT_BRANCH # switch to $1
echo "git-rbranch: Setting origin/$1 as the tracking branch"
git branch -f $1 origin/$1 # branch to $1, using origin/$1 as the tracking branch
echo "git-rbranch: Checking out $1 with the right origin"
@drosenstark
drosenstark / git-commit2
Created February 8, 2015 07:29
Git Commit2
tempFile='/eraseme/git-commit-template'
git config commit.template "$tempFile"
rm $tempFile
branch=$(git symbolic-ref HEAD|sed s#refs/heads/##) exec 3<> "$tempFile" && awk -v TEXT="$branch" 'BEGIN {print TEXT}{print}' "$tempFile" >&3
git add .
git commit -a
read -p "Press enter to push to server..."
git push
@drosenstark
drosenstark / GameLoop.swift
Created February 17, 2015 20:20
Gameloop in Swift
import UIKit
class GameLoop : NSObject {
var doSomething: () -> ()!
var displayLink : CADisplayLink!
var frameInterval : Int!
init(frameInterval: Int, doSomething: () -> ()) {
self.doSomething = doSomething
@drosenstark
drosenstark / gist:a9c479978fb83f2181a0
Created February 17, 2015 20:27
Box in Square in Cartography, Autolayout for Swift
let percent = 0.3
layout(red, green) { red, green in
red.center == red.superview!.center
red.size == red.superview!.size
green.center == red.superview!.center
// lower priority
green.width == red.width * percent ~ 100
green.height == red.height * percent ~ 100
@drosenstark
drosenstark / DRTabBarController.h
Last active August 29, 2015 14:16
Drop in replacement for UITabBarController that plays well with UINavigationController as parent
//
// Created by Dan Rosenstark on 2/28/15.
// Copyright (c) 2015 Confusion Studios LLC. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface DRTabBarController : UIViewController <UITabBarDelegate>;
@property (nonatomic, strong) NSArray *viewControllers;
@property (nonatomic, strong) UITabBar *tabBar;
@drosenstark
drosenstark / ObjectOrText.swift
Created May 27, 2015 17:20
Sometimes you need one of these, one of those, or nothing... this is an example of that case.
enum ObjectOrString {
case Object(NSObject)
case Text(String)
case Empty
func object() -> NSObject? {
switch self {
case let .Object(obj): return obj
default: return nil
}
@drosenstark
drosenstark / gist:4f55fc409cf6c0f8836a
Created June 30, 2015 22:53
Right-Aligned Callout Div, HTML Only
<div style="margin-left: auto; width: 150px; border:3px solid black; padding: 10px; text-align: center; background-color: #d3d3d3">
Put some stuff in here
</div>
@drosenstark
drosenstark / NDate<->String
Last active August 29, 2015 14:24
NSDate to String, String to Date in Swift
// this could be a global formatter available to these other two
let formatter = NSDateFormatter();
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZ";
// since we lose something going to string and back, this does both passes for the current date/time
func now() -> NSDate {
return stringToDate(dateToString(NSDate()))
}
func dateToString(date:NSDate) -> String {
@drosenstark
drosenstark / everwatch-turbo.rb
Last active September 2, 2015 23:55
Everwatch :: Show Evernote Markdown in Marked
#!/usr/bin/env ruby
# encoding: UTF-8
# everwatch.rb by Brett Terpstra, 2011
# Watch Evernote for updates and put the current content of the editor into a preview file for Marked.app
# <http://markedapp.com>
# Modified by dan@rosenstark.com, 2015-08-24, Evernote 6.0.16
# TO LAUNCH USE (if in ~/scripts):
# ~/scripts/everwatch-turbo.rb &
require 'digest/sha2'
require 'fileutils'
@drosenstark
drosenstark / Donut.swift
Last active April 6, 2019 11:59
(thanks to Paintcode) Draw a hollow circle in swift, or just a piece of one... angle starts at bottom and rotates around clockwise.
class func drawHollowCircle(circleColor: UIColor, rect: CGRect, startAngle: CGFloat = 1, endAngle: CGFloat = 360, outerRingProportion: CGFloat = 1, innerRingProportion: CGFloat = 0.5, drawShadow : Bool) {
//// Variable Declarations
let startAngleCalced: CGFloat = -startAngle + 270
let endAngleCalced: CGFloat = -endAngle + 270
let innerRingDiameter: CGFloat = rect.size.width * innerRingProportion
let innerRingOffset: CGFloat = 0.5 * (rect.size.width - innerRingDiameter)
let innerRingRect = CGRectMake(innerRingOffset, innerRingOffset, innerRingDiameter, innerRingDiameter)
let outerRingDiameter: CGFloat = rect.size.width * outerRingProportion
let outerRingOffset: CGFloat = 0.5 * (rect.size.width - outerRingDiameter)