Skip to content

Instantly share code, notes, and snippets.

Thomas Fuchs madrobby

Block or report user

Report or block madrobby

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
@madrobby
madrobby / unicorn
Created Mar 26, 2014
Unicorn init.d script (for Ubuntu 12.04 LTS)
View unicorn
#! /bin/sh
# File: /etc/init.d/unicorn
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
View gist:9863623
$ rake test:run
(in /Users/thomasfuchs/Projects/prototype)
Started tests in Google Chrome.
Finished in 2.0e-06 seconds.
0 tests, 0 assertions, 0 failures, 0 errors.
Started tests in Chromium.
View gist:156123706bb20c09c851
def decideIfHardwareAccelerationIsAGoodIdea
version = NSProcessInfo.processInfo.operatingSystemVersionString
begin
version = /[0-9]+\.[0-9]+/.match(version).to_s.split('.').map(&:to_i)
NSLog "Turning hardware acceleration on (#{version})"
@hw_accel = version[1] >= 9
rescue
NSLog "Couldn't parse operatingSystemVersionString: #{version}"
@hw_accel = false
end
View gist:bfdf61ede39448ef1e2f
def isHardwareAccelerationIsAGoodIdea
/[0-9]+\.[0-9]+/.match(NSProcessInfo.processInfo.operatingSystemVersionString)
.to_s.split('.').map(&:to_i)[1] >= 9
end
View gist:0ec071b9bdb9309a1440
# a single method signature in AppKit
initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:
# a JavaScript unit testing framework
function(a,b,c,d,e,f){c=d=e=0;for(f in a)try{a[f](function(g,h){g?c++:(d++,b(f,'F',h))})}catch(i){e++;b(f,'E',i)}b(c+'A',d+'F',e+'E')}
@madrobby
madrobby / gist:9f134c440bd6524e7e7a
Last active Aug 29, 2015
RubyMotion vs. Objective-C showdown
View gist:9f134c440bd6524e7e7a
-(BOOL)appIsPresentInLoginItems
{
NSString *bundleID = @"blah";
NSArray * jobDicts = nil;
jobDicts = (NSArray *)SMCopyAllJobDictionaries( kSMDomainUserLaunchd );
if ( (jobDicts != nil) && [jobDicts count] > 0 ) {
BOOL bOnDemand = NO;
@madrobby
madrobby / fix_link_to_delete.rb
Created May 20, 2014
Monkey-patch that fixes Rails 2.3's `link_to` helper with method "delete" and fragment caching (just put the file in `config/initializers`)
View fix_link_to_delete.rb
View gist:0caa0a78445f41de422a
irb(main):001:0> A = [1,2,3].freeze
=> [1, 2, 3]
irb(main):002:0> A[2] = 5
TypeError: can't modify frozen array
from (irb):2:in `[]='
from (irb):2
@madrobby
madrobby / gist:8dc43c58114466d6a894
Created Jun 24, 2014
Code to prevent drag/drop in a Webview inside a Mac app. You can throw this in a `<script>` tag first thing inside the `<body>`. Users will no longer be able to accidentally break your app by dropping something (like a web page URL) onto it.
View gist:8dc43c58114466d6a894
document.addEventListener('dragover', function(e){
e.preventDefault();
e.stopPropagation();
}, false);
document.addEventListener('drop', function(e){
e.preventDefault();
e.stopPropagation();
}, false)
View gist:e78cd94e7d4ad374e0ac
def format_date_range(from, to)
to = from if to.nil?
return '' if from.nil? && to.nil?
from, to = to, from if to < from
if from == to
from.strftime('%B %e, %Y')
elsif from.year == to.year && from.month == to.month &&
from.beginning_of_month == from && to.end_of_month == to
from.strftime('%B %Y')
You can’t perform that action at this time.