Skip to content

Instantly share code, notes, and snippets.

@torsten
torsten / chrome-dot-url-opener.user.js
Created January 31, 2011 20:06
Greasemonkey script, enables Google Chrome to handle .URL files.
// ==UserScript==
// @name .URL file opener for Google Chrome
// @namespace http://torstenbecker.eu/
// @match file://*.URL
// @match file://*.url
// @author Torsten Becker
// @description Enables Chrome to handle .URL files (internet shortcuts, usually created on Windows) and navigates to their referenced location.
// ==/UserScript==
// Installation notes:
@torsten
torsten / proxy.rb
Last active March 12, 2023 21:44
A quick HTTP proxy server in Ruby.
#!/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 / 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 / quine.rb
Created March 20, 2010 16:01
Try it: ruby quine.rb | ruby | ruby | ruby | ruby | ruby
a,b="a,b=",";puts a+a.inspect+','+b.inspect+b";puts a+a.inspect+','+b.inspect+b
@torsten
torsten / gen_debug_header.py
Created December 20, 2011 19:43
Wrapping OpenGL calls in error checks
#!/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 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 / 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>