Skip to content

Instantly share code, notes, and snippets.

@madrobby
madrobby / unicorn
Created March 26, 2014 21:30
Unicorn init.d script (for Ubuntu 12.04 LTS)
#! /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
$ 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.
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
def isHardwareAccelerationIsAGoodIdea
/[0-9]+\.[0-9]+/.match(NSProcessInfo.processInfo.operatingSystemVersionString)
.to_s.split('.').map(&:to_i)[1] >= 9
end
# 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 August 29, 2015 14:01
RubyMotion vs. Objective-C showdown
-(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 15:07
Monkey-patch that fixes Rails 2.3's `link_to` helper with method "delete" and fragment caching (just put the file in `config/initializers`)
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 June 24, 2014 12:20
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.
document.addEventListener('dragover', function(e){
e.preventDefault();
e.stopPropagation();
}, false);
document.addEventListener('drop', function(e){
e.preventDefault();
e.stopPropagation();
}, false)
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')