Skip to content

Instantly share code, notes, and snippets.

View MSch's full-sized avatar

Martin Schürrer MSch

View GitHub Profile
require 'rubygems'
require 'sinatra'
require 'dm-core'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
# Don't use this in production code! Extending lots of objects during runtime
# will have a negative impact on performance/memory because ruby clears out
# the method cache.
@MSch
MSch / SingletonInitializer.m
Created April 26, 2011 22:56 — forked from AlanQuatermain/SingletonInitializer.m
An implementation of a Singleton accesAn implementation of a Singleton accessor routine. Removes the (one if-statement) overhead of calling dispatch_once after the first time by method swizzling sharedInstance for a method without dispatch_once
#import <dispatch/dispatch.h>
#import <objc/runtime.h>
@implementation MySingleton
static MySingleton * __singleton = nil;
+ (MySingleton *) sharedInstance_accessor
{
return ( __singleton );
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
@MSch
MSch / xcode_auto_versioning.rb
Created May 24, 2011 19:56 — forked from bgreenlee/xcode_auto_versioning.rb
Xcode Auto-Versioning: Updates your Info.plist's CFBundleVersion with the current git tag and/or sha.
# Xcode Auto-Versioning
#
# Updates your Info.plist's CFBundleVersion with the current git tag and/or sha.
#
# based on https://github.com/elliottcable/xcode-git-versioner
#
# Usage:
# 1. Right-click the target you want to add the versioning phase to (usually the target that builds your app)
# 2. Select: Add -> New Build Phase -> New Run Script Build Phase
# 3. Specify /usr/bin/env ruby as the shell for the script
class Exception
alias_method :_message, :message
def message
"#{_message}\t\n#{backtrace.join("\t\n")}"
end
end
@MSch
MSch / build-phase.sh
Created October 20, 2011 17:47 — forked from aquarius/gist:1295218
Runs script build phase "Add git ref/tag to Info.plist"
defaults write "${TARGET_BUILD_DIR}"/"${CONTENTS_FOLDER_PATH}"/Info GitVersion `git describe --always --tags --dirty`
@MSch
MSch / gist:2633653
Created May 8, 2012 08:48 — forked from steipete/gist:1205760
dispatch_reentrant
// checks if already in current queue, prevents deadlock
void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_block_t block) {
if (dispatch_get_current_queue() == queue) {
block();
}else {
dispatch_sync(queue, block);
}
}
// problem:
self.collectionView = ({
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds
collectionViewLayout:flowLayout];
collectionView.delegate = self;
collectionView.dataSource = self;
collectionView;
@MSch
MSch / thread.rb
Last active January 2, 2016 09:09
module ActiveRecord
class Connection
def connect
Thread.current.thread_variable_set(:connection_id, 123)
end
end
end
module Sequel
class Connection
defmodule Mix.TasksServer do
@moduledoc false
use GenServer.Behaviour
def start_link() do
:gen_server.start_link({ :local, __MODULE__ }, __MODULE__, :ok, [])
end
def clear_tasks() do
call :clear_tasks