Skip to content

Instantly share code, notes, and snippets.

@BenWard
BenWard / pinboard-full.js
Created January 29, 2011 07:47
A smarter bookmarklet for Pinboard.in; wraps selected text in <blockquote> tags, keeps variables out of the global scope, supports filling tags from rel="tag" markup in the page, and titles from hAtom entry titles.
(function() {
// Change `silent` to true to invoke the promptless, self-closing
// version of the bookmarklet.
var silent = false;
var url = location.href;
var title = document.title;
// Look for a single hAtom entry on the page, and iff one is found, extract
// the entry-title in place of the document title:
// Original code from http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
}
}
@rmetzler
rmetzler / snippet.rb
Created April 4, 2011 11:25
rake tasks for git
require 'readline'
def git_branch
`git branch | grep "*"`.strip[2..-1]
end
def compare_git_ver
m = /git version (\d+).(\d+).(\d+)/.match(`git version`.strip)
return true if m[1].to_i > 1
return false if m[1].to_i < 1
@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"
@ordinaryzelig
ordinaryzelig / minitest_spec_expectations.md
Last active December 10, 2022 13:34
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
@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"];
@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}"
@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)
@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
@marcedwards
marcedwards / high-dpi-media.css
Last active November 19, 2023 12:56
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 */