Skip to content

Instantly share code, notes, and snippets.

View MSch's full-sized avatar

Martin Schürrer MSch

View GitHub Profile
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 / fix_model_name.rb
Created June 21, 2013 18:23
If you prefer to keep your models namespaced then ActiveModel::Naming really makes that harder for you than it would have to be.
module MyApp::ModelNameFix
def model_name
@_model_name ||= ActiveModel::Name.new(self, nil, self.name.sub(/^#{self.parent.name}::/, ''))
end
def namespaced_model_name
@_namespaced_model_name ||= ActiveModel::Name.new(self)
end
# Work with Draper
<msch> RhodiumToad: so the simple advice is, "always use timestamptz, never timestamp"?
<RhodiumToad> when storing a future time, the way to decide is this:
<RhodiumToad> there are a few apps where timestamp without time zone has its uses.
<RhodiumToad> e.g. things like calendaring / scheduling which are dealing mostly in future times
<RhodiumToad> does it matter how many seconds/minutes/hours there are between now and then,
<RhodiumToad> or does it matter what the clock on the wall will read then
<RhodiumToad> in the first case you need timestamptz, in the second case, timestamp without time zone,
<RhodiumToad> possibly with a separate field (possibly in some other table) storing the timezone name
<RhodiumToad> otherwise, you run into the same problem that many calendaring apps did when the US DST rules were changed
@MSch
MSch / Clear.m
Created November 8, 2012 11:07
class-dump Clear for Mac
/*
* Generated by class-dump 3.3.4 (64 bit).
*
* class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2011 by Steve Nygard.
*/
#pragma mark Named Structures
struct CGAffineTransform {
double _field1;
During the last months, development on Vico has mostly stalled. This is frustrating for many users, and for me, as I no longer can spend as much time on Vico as I'd like. My plans for Vico is grander than that.
Therefore I'm releasing the source code on github and encourage the community to contribute and help build a truly kick-ass editor.
Vico will be removed from the App Store. Being there in the first place has been problematic, and the sandboxing requirement makes it finally incompatible. A new build is available on thedownload page without any trial restrictions.
If you want to get involved with Vico, I'm looking forward to see you here on the mailing list.
@MSch
MSch / awesome.rb
Created June 3, 2012 17:55
Ruby 1.9 enumerator chaining
[1,2,3].map.with_index { |x, i| puts "#{x} #{i}"; x+1 }
# 1 0
# 2 1
# 3 2
# => [2, 3, 4]
[1,2,3].each.with_object("q") { |x, obj| puts "#{x} #{obj}"; obj << x.to_s }
# 1 q
# 2 q1
class Base
something_something :mappings
self.mappings = {}
end
class FirstChild < Base
self.mappings[:foo] = :bar
end
class SecondChild < Base
@MSch
MSch / dnsmasq.conf
Created May 10, 2012 08:46
dnsmasq configuration for tunlr.net/pandora.com
# Configuration file for dnsmasq.
#
# Format is one option per line, legal options are the same
# as the long options legal on the command line. See
# "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details.
# The following two options make you a better netizen, since they
# tell dnsmasq to filter out queries which the public DNS cannot
# answer, and which load the servers (especially the root servers)
# unnecessarily. If you have a dial-on-demand link they also stop
@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:
@MSch
MSch / bookmarklet.js
Created April 30, 2012 10:54
qando mobile bookmarklet
javascript:d=new Date();document.location='http://m.qando.at/de/get_route.ft?from=DEINE STRASSE 12&time[0]='+d.getHours()+'&time[1]='+d.getMinutes()+'&date[0]='+d.getDate()+'&date[1]='+(d.getMonth()+1)+'&date[2]='+d.getFullYear()