Skip to content

Instantly share code, notes, and snippets.

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 / 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`)
@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;
# 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')}
def isHardwareAccelerationIsAGoodIdea
/[0-9]+\.[0-9]+/.match(NSProcessInfo.processInfo.operatingSystemVersionString)
.to_s.split('.').map(&:to_i)[1] >= 9
end
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
$ 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.
@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
@madrobby
madrobby / gist:9628514
Last active November 18, 2020 13:00
Ansible actions to install a PostgreSQL 9.3 database server on Ubuntu 12.04
- name: Add PostgreSQL repository
apt_repository: repo='deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' state=present
sudo: yes
- name: Add PostgreSQL repository key
apt_key: url=https://www.postgresql.org/media/keys/ACCC4CF8.asc state=present
sudo: yes
- name: Update apt cache
apt: update_cache=yes
@madrobby
madrobby / gist:9476733
Created March 10, 2014 23:34
Download a single file from a private GitHub repo. You'll need an access token as described in this GitHub Help article: https://help.github.com/articles/creating-an-access-token-for-command-line-use
curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/owner/repo/contents/path