Skip to content

Instantly share code, notes, and snippets.

View chourobin's full-sized avatar

Robin Chou chourobin

View GitHub Profile
@chourobin
chourobin / json_struct_example
Created January 20, 2014 01:28
Example creating structs on the fly
// http://play.golang.org/p/TVFHKUHO2p
package main
import "fmt"
import "encoding/json"
func main() {
type error struct {
Message string `json:"message"`
@chourobin
chourobin / screenshot.m
Created December 8, 2013 20:36
Screenshot of view controller
- (UIImage *)screenshot
{
CGRect rect = CGRectMake(0, 88.0, self.view.frame.size.width, self.view.frame.size.height - 88.0);
UIGraphicsBeginImageContextWithOptions(rect.size, self.view.opaque, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, -rect.origin.x, -rect.origin.y);
[self.view.layer renderInContext:context];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NB: Originally courtesy of http://blog.taggesell.de/index.php?/archives/73-Managing-Amazon-EC2-SSH-login-and-protecting-your-instances.html
Managing Amazon EC2 - SSH login and protecting your instances
How to log into your freshly fired-up instances and how to secure ssh access
(works under Linux and Mac OS, under Windows with Cygwin)
First time you want to log into a newly started instance you appear to have the chicken-and-egg problem: how to log in when you do not know the root password? Luckily Amazon devised a comfortable way to circumvent this: your Key Pairs. these are not to be confused with the „Access Key IDs“ on the Access Identifier web page and they are neither the X509 certificates. These Key pairs are automatically generated the first time you log into the web console and you can only download its private part. Store it in your ~/.ssh directory. In case you missed the download or don't know where you've put it AND you don't have any instances running, just generate and download a new one.
//
// FileFunctionLevelFormatter.h
// Stylist
//
// Created by Robin Chou on 10/23/14.
// Copyright (c) 2014 Voila. All rights reserved.
//
#import "DDLog.h"
@chourobin
chourobin / bump_build.sh
Last active December 20, 2015 01:09
My custom bump build number script
# Using HEX builds (e.g. 1A12)
#!/bin/sh
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
dec=$((0x$buildNumber))
buildNumber=$(($dec + 1))
hex=$(printf "%X" $buildNumber)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $hex" "$INFOPLIST_FILE"
# Using numerical builds
# Uncrustify 0.60
newlines = auto
input_tab_size = 4
output_tab_size = 4
string_escape_char = 92
string_escape_char2 = 0
tok_split_gte = false
utf8_bom = ignore
utf8_byte = false
utf8_force = false
@chourobin
chourobin / configure_sublime.sh
Last active December 19, 2015 14:09
Install mHTML and mCSS TextMate bundles in ST
# Install SublimeText
# ST2
cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages
# ST3
cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages
# Install mCSS
git clone git://github.com/minimaldesign/mCSS.tmbundle.git "mCSS.tmbundle"
@chourobin
chourobin / sublime_settings.json
Last active December 19, 2015 14:09
Sublime Text 2 Prefs
{
"color_scheme": "Packages/Theme - Flatland/Flatland Dark.tmTheme",
"hot_exit": false,
"ignored_packages":
[
"Vintage"
],
"remember_open_files": false,
"tab_size": 2,
"theme": "Flatland Dark.sublime-theme",
@implementation UITextView (RSExtras)
static BOOL stringCharacterIsAllowedAsPartOfLink(NSString *s) {
/*[s length] is assumed to be 0 or 1. s may be nil.
Totally not a strict check.*/
if (s == nil || [s length] < 1)
return NO;