Skip to content

Instantly share code, notes, and snippets.

Torsten Becker torsten

Block or report user

Report or block torsten

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@torsten
torsten / quine.rb
Created Mar 20, 2010
Try it: ruby quine.rb | ruby | ruby | ruby | ruby | ruby
View quine.rb
a,b="a,b=",";puts a+a.inspect+','+b.inspect+b";puts a+a.inspect+','+b.inspect+b
View expanding-json-arrays-to-rows.sql
-- 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 / proxy.rb
Last active Dec 10, 2018
A quick HTTP proxy server in Ruby.
View proxy.rb
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <torsten.becker@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@torsten
torsten / gen_debug_header.py
Created Dec 20, 2011
Wrapping OpenGL calls in error checks
View gen_debug_header.py
#!/usr/bin/env python3
# Originally written by Torsten Becker <torsten.becker@gmail.com> in 2011
import re
gl_function = re.compile(r'^extern\s+(.+)\s+(\w+)\s*\((.+)\)\s*;\s*$')
argument = re.compile(r'(\w+)\s*$')
@torsten
torsten / fix-whitespace.sh
Created Sep 12, 2012
Pre-commit hook script for git to fix whitespace and long lines.
View fix-whitespace.sh
#!/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 / EC2 Instance Types.md
Created Oct 31, 2013
AWS EC2 Instance specs and price in one table: http://git.io/ec2-prices
View EC2 Instance Types.md

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 Dec 2, 2012
iOS: Heuristic to check for non latin languages
View check-non-latin.m
// 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 Oct 30, 2012
Delete all objetcts in a MOC
View delete-all-objects.m
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 Sep 27, 2012
TextMate Command to Open Dash for Selection/Current Word
View OpenDash.tmCommand
<?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 / test-cycle-warnings.m
Created Jul 9, 2012
Retain cylcle warnings
View test-cycle-warnings.m
// 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;
You can’t perform that action at this time.