Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am torsten on github.
  • I am torsten (https://keybase.io/torsten) on keybase.
  • I have a public key whose fingerprint is E054 EF92 AC0F B3E7 9BA3 5F8A 6B9B FA0C CE67 02B9

To claim this, I am signing this object:

@torsten
torsten / expanding-json-arrays-to-rows.sql
Last active April 8, 2021 15:35
Expanding JSON arrays to rows with SQL on RedShift: All queries to reproduce the technique from my blog post https://torsten.io/stdout/expanding-json-arrays-to-rows
-- Related blog post to this Gist:
-- https://torsten.io/stdout/expanding-json-arrays-to-rows
-- Run these commands on a interactive RedShift session:
CREATE TEMP TABLE clusters AS (
SELECT 1 AS id, '[1, 2]' AS node_sizes UNION ALL
SELECT 2 AS id, '[5, 1, 3]' AS node_sizes UNION ALL
SELECT 3 AS id, '[2]' AS node_sizes
);
@torsten
torsten / EC2 Instance Types.md
Created October 31, 2013 13:29
AWS EC2 Instance specs and price in one table: http://git.io/ec2-prices

Combine http://aws.amazon.com/ec2/pricing/ and http://aws.amazon.com/ec2/instance-types/#selecting-instance-types into one f*cking table.

Type | Arch | vCPU | ECU | Mem | Storage | EBS-optimized | Network | Price ------|------|------|------|-----|-----|---------|---------------|---------------------|-------- General ||||||||| t1.micro | 32/64 | 1 | Variable | 0.615 | EBS only | - | Very Low | $0.020 m1.small | 32/64 | 1 | 1 | 1.7 | 1 x 160 | - | Low | $0.065 m1.medium | 32/64 | 1 | 2 | 3.75 | 1 x 410 | - | Moderate | $0.130 m1.large | 64 | 2 | 4 | 7.5 | 2 x 420 | Yes | Moderate | $0.260

@torsten
torsten / check-non-latin.m
Created December 2, 2012 20:35
iOS: Heuristic to check for non latin languages
// clang -framework Foundation check-non-latin.m && ./a.out
#import <Foundation/Foundation.h>
int main (int argc, char const *argv[])
{
@autoreleasepool
{
NSDictionary *langToText = @{@"arabic": [NSString stringWithUTF8String:"العربي"],
@"japanese": [NSString stringWithUTF8String:"日本"],
@torsten
torsten / delete-all-objects.m
Created October 30, 2012 17:19
Delete all objetcts in a MOC
NSArray *entities = self.managedObjectContext.persistentStoreCoordinator.managedObjectModel.entities;
for (NSEntityDescription *desc in entities)
{
NSFetchRequest *allObjectsRequest = [NSFetchRequest fetchRequestWithEntityName:desc.name];
NSError *fetchError;
NSArray *allObjects = [self.managedObjectContext executeFetchRequest:allObjectsRequest error:&fetchError];
if (allObjects)
{
@torsten
torsten / OpenDash.tmCommand
Created September 27, 2012 16:52
TextMate Command to Open Dash for Selection/Current Word
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>open "dash://${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}"</string>
<key>input</key>
<string>none</string>
@torsten
torsten / fix-whitespace.sh
Created September 12, 2012 13:58
Pre-commit hook script for git to fix whitespace and long lines.
#!/bin/sh
# Pre-commit hook for git which removes trailing whitespace, converts tabs to spaces, and enforces a max line length.
if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
@torsten
torsten / test-cycle-warnings.m
Created July 9, 2012 16:50
Retain cylcle warnings
// Illustrates that not all causes of retain cycles are detected by clang. Compile with:
// clang -fobjc-arc -Wall -framework Foundation test-cycle-warnings.m && ./a.out
#import <Foundation/Foundation.h>
@interface Foo : NSObject
typedef void (^Block)();
@property (readwrite, copy) Block asd;
@torsten
torsten / annti_blockSelf.m
Created June 12, 2012 13:50
Experiment if __block causes a retain.
// Run with:
// clang -fobjc-arc -Wall -framework Foundation blockself.m && ./a.out
// Further reading:
// http://www.mikeash.com/pyblog/friday-qa-2009-08-14-practical-blocks.html
// http://clang.llvm.org/docs/AutomaticReferenceCounting.html#misc.blocks
// http://developer.apple.com/library/mac/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html
#import <Foundation/Foundation.h>
@torsten
torsten / BetterTestCase.m
Created May 15, 2012 08:50
Bugfix for SenTestCase when using base classes for test cases.
// OCUnit/SenTestCase's vanilla testInvocations method does not produce a unique list of methods
// when you inherit from a common test base class. Currently it will call the same test methods
// multiple times, depending on the number of base classes.
//
// To prevent these duplicate test method calls, override testInvocations like this.
//
// Written in 2012 by Torsten Becker <torsten.becker@gmail.com>
@interface BetterTestCase : SenTestCase