Skip to content

Instantly share code, notes, and snippets.

View johanforssell's full-sized avatar

Johan Forssell johanforssell

  • NaN
  • Sweden
  • 17:29 (UTC +02:00)
View GitHub Profile
@johanforssell
johanforssell / .bashrc
Created September 28, 2015 17:34
A reasonable bash prompt with colorized git status
function _git_prompt() {
local git_status="`git status -unormal 2>&1`"
if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
if [[ "$git_status" =~ nothing\ to\ commit ]]; then
local ansi=42
elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
local ansi=43
else
local ansi=41
fi
@johanforssell
johanforssell / Microsoft.PowerShell_profile.ps1
Last active September 1, 2015 17:30
Windows Powershell prompt
# You can edit this file with `editor_name $profile`
# I'm using Visual Studio Code, so it's `code $profile`
#
# In order to run this script you need to change the
# execution policy. Run a powershell as admin and do this:
#
# Set-ExecutionPolicy RemoteSigned
#
@johanforssell
johanforssell / gist:ffeaad858bb671be327b
Last active August 29, 2015 14:17
Reset all the iOS simulators you've got
instruments -s devices | \
grep Simulator | \
grep -o "[0-9A-F]\{8\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{4\}-[0-9A-F]\{12\}" | \
xargs xcrun simctl erase
@johanforssell
johanforssell / NSString+Filter
Created December 17, 2014 22:10
NSString category for filtering text
#import <Foundation/Foundation.h>
@interface NSString (Filter)
/// Only allow A-Z, a-z, 0-9 and underscore.
- (BOOL)isAlphanumericOrUnderscore;
@end
@implementation NSString (Filter)
- (BOOL)isAlphanumericOrUnderscore
{
NSMutableCharacterSet *set = [NSMutableCharacterSet alphanumericCharacterSet];
// in a UITableViewController (or any other view controller with a UITableView)
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, 0)]; // You might have to set height to 9999 or very high
header.translatesAutoresizingMaskIntoConstraints = NO;
// [add subviews and their constraints to header]
NSLayoutConstraint *headerWidthConstraint = [NSLayoutConstraint
@johanforssell
johanforssell / gist:94e089707d5823ab1fdf
Last active August 29, 2015 14:07
A useful UITextView subclass
// From https://github.com/Nikita2k/resizableTextView
#import <UIKit/UIKit.h>
// ---------------------------------------
@interface ResizableTextView : UITextView
@end
// ---------------------------------------
@johanforssell
johanforssell / UIView+Hierarchy
Created September 4, 2014 17:45
Simple recursive function for printing a view hierarchy in cocoa touch. Originally from user207616 on Stack Overflow.
// --------------------------------------------------
#import <UIKit/UIKit.h>
@interface UIView (Hierarchy)
- (void)printViewHierarchy;
@end
// --------------------------------------------------
@johanforssell
johanforssell / KiwiBlocksRally
Created February 17, 2014 09:28
Helpful trio of macros to make sure your asynchronous blocks are run in a Kiwi spec file.
#pragma mark - Kiwi Blocks rally
// 1/3: Invoke at start of test
#define BlocksRallyStart(_a) \
NSInteger _blocks_total = _a; __block NSInteger _blocks_counter = 0;
// 2/3: Invoke in each block you're waiting for
#define BlocksRallyCheckpoint \
_blocks_counter += 1;
@johanforssell
johanforssell / gist:8237848
Last active January 2, 2016 02:29
Simple web server which accepts chunked uploads and responds with a dummy json
#!/usr/bin/python
import time
import BaseHTTPServer
import json
from pprint import pprint
HOST_NAME = '192.168.1.89'
PORT_NUMBER = 9494
media_results = {
@johanforssell
johanforssell / gist:5386976
Created April 15, 2013 09:29
Shell-alias 'week' för att kolla med http://vecka.nu vilken vecka det är. Kommer att gå sönder när de designar om sidan.
alias week="curl --silent --url http://vecka.nu | egrep '<div style=\"color: #066EB0; font-family: Arial; font-size: 220pt; line-height: 220pt; font-weight: bold;\">[0-9]*</div>' | sed -e 's/.*>\([0-9]*\)<.*/\1/'";