Skip to content

Instantly share code, notes, and snippets.

@seanlilmateus
seanlilmateus / chronic.rb
Created October 13, 2012 18:40
Chronic like natural language date parser with foundation on Macruby
#!/usr/bin/env macruby -wKU
framework 'Foundation'
p myDate = NSDate.dateWithNaturalLanguageString("tomorrow", locale:nil)
p myDate = NSDate.dateWithNaturalLanguageString("last monday", locale: nil)
p myDate = NSDate.dateWithNaturalLanguageString("this tuesday at 5:00 o'clock pm", locale: nil)
p myDate = NSDate.dateWithNaturalLanguageString("may 27th", locale: nil)
p myDate = NSDate.dateWithNaturalLanguageString("6/4/2012", locale: nil)
@kattrali
kattrali / ruby_cfstringtransform.rb
Created September 18, 2012 09:14
Fun with RubyMotion! An extension of the Ruby String class to support transliteration using CFStringTransform()
# encoding: UTF-8
class String
# Extend string to include transliterations to different orthographies
# from Latin character set or the reverse (`to_latin`)
#
# Supported Orthographies:
# Arabic, Cyrillic, Greek, Hangul, Hiragana, Katakana, Latin, Thai
#
class MyViewController < UIViewController
include ViewTags
#by convention, these views will have tags that correspond to the order you specify them in
# :date_label:1, :name_label:2
has_view :date_label, :name_label
def loadView
views = NSBundle.mainBundle.loadNibNamed "myview", owner:self, options:nil
self.view = views[0]
@marcedwards
marcedwards / high-dpi-media.css
Last active March 2, 2025 20:24
A CSS media query that captures almost all high DPI aware devices.
/* ---------------------------------------------------------- */
/* */
/* A media query that captures: */
/* */
/* - Retina iOS devices */
/* - Retina Macs running Safari */
/* - High DPI Windows PCs running IE 8 and above */
/* - Low DPI Windows PCs running IE, zoomed in */
/* - Low DPI Windows PCs and Macs running Firefox, zoomed in */
/* - Android hdpi devices and above */
@hookercookerman
hookercookerman / restkit.rb
Created July 31, 2012 10:36
Working RestKit Mapping RubyMotion
class Photo
attr_accessor :max_id_str
URL = ""
def self.load
manager.loadObjectsAtResourcePath URL, objectMapping:mapping, delegate:self
end
def self.manager
@shayarnett
shayarnett / README
Created May 10, 2012 13:13
Snippet generator for RubyMotion ctags
Generate ctags with `rake ctags`
Run snipper.rb
Put resulting ruby.snippets file where your snippet plugin can pick it up. (I'm using snipmate)
@wojtekmach
wojtekmach / account_test.rb
Created May 3, 2012 09:45
Writing MiniTest extensions
require 'minitest/autorun'
module MiniTest::Assertions
def assert_changes(obj, method, exp_diff)
before = obj.send method
yield
after = obj.send method
diff = after - before
assert_equal exp_diff, diff, "Expected #{obj.class.name}##{method} to change by #{exp_diff}, changed by #{diff}"
@nacho4d
nacho4d / NSTask sample
Created April 8, 2012 13:25
NSTask sample
#import <Foundation/Foundation.h>
void doTaskAndCapture(void);
void doTaskAndCapture()
{
@try
{
// Set up the process
NSTask *t = [[[NSTask alloc] init] autorelease];
[t setLaunchPath:@"/bin/ls"];
@ordinaryzelig
ordinaryzelig / minitest_spec_expectations.md
Last active June 4, 2025 17:59
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@rosskarchner
rosskarchner / gist:1001799
Created June 1, 2011 04:43
Script that adds OpenMeta tags to Pukka cache
#! /usr/bin/python
#requires: openmeta command line tool, openmeta python library
from glob import glob
from plistlib import readPlistFromString
import shlex, subprocess, openmeta
get_xml="plutil -convert xml1 -o - %s"