Skip to content

Instantly share code, notes, and snippets.

View mieko's full-sized avatar

Mike Owens mieko

View GitHub Profile
# Extracted from the following library
# http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/
#--
# Utility for creating Google Maps Encoded GPolylines
# License: You may distribute this code under the same terms as Ruby itself
# Author: Joel Rosenberg
class DouglasPeucker
# The minimum distance from the line that a point must exceed to avoid
# elimination under the DP Algorithm.
@mieko
mieko / chronic_scan.rb
Created May 16, 2011 04:20
Scan free-form text for human-reabible dates (according to Chronic)
require 'chronic'
module Chronic
class << self
def scan(text)
return enum_for(:scan, text) unless block_given?
# words is lossless. We need to be able to join('') this and get
# the original string back
words = scan_by_re(text, /\s+/).to_a
@mieko
mieko / CCTableView.cpp
Created September 11, 2012 09:00
CCTableView with variable-size cells
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2012 Mike Owens <mike@filespanker>
Copyright (c) 2010 Sangwoo Im
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@mieko
mieko / build-libcurl.sh
Created September 24, 2012 02:16
curl-ios-build-scripts version with armv7s
#!/bin/bash
# Modification of https://github.com/brunodecarvalho/curl-ios-build-scripts
VERSION="7.27.0"
LIBNAME="libcurl"
LIBDOWNLOAD="http://curl.haxx.se/download/curl-${VERSION}.tar.gz"
ARCHIVE="${LIBNAME}-${VERSION}.tar.gz"
# Enabled/disabled protocols (the fewer, the smaller the final binary size)
PROTOCOLS="--enable-http --disable-rtsp --disable-ftp --disable-file --disable-ldap --disable-ldaps \
# This implementation replaces rails-ujs's :confirm behavior, from a
# browser-provided, window.confirm() to a nice bootstrap dialog.
# This is based upon the technique and code described here:
#
# http://rors.org/demos/custom-confirm-in-rails
#
# Special handling of delete actions, better tab behavior,
# and DOM cleanup was added.
describe "The raise method" do
it "should clear $! and $@ if no exception is active" do
$!.should be_nil
$@.should be_nil
end
it "sets $! and $@ during the body of each rescue clause" do
begin
raise "ERROR"
rescue
@mieko
mieko / gist:10397663
Created April 10, 2014 16:05
Enumerator specs
opal_filter "Enumerator" do
fails "Enumerator#each yields each element of self to the given block"
fails "Enumerator#each calls #each on the object given in the constructor by default"
fails "Enumerator#each calls #each on the underlying object until it's exhausted"
fails "Enumerator#each calls the method given in the constructor instead of #each"
fails "Enumerator#each calls the method given in the constructor until it's exhausted"
fails "Enumerator#each raises a NoMethodError if the object doesn't respond to #each"
fails "Enumerator#each returns self if not given arguments and not given a block"
fails "Enumerator#each returns the same value from receiver.each if block is given"
fails "Enumerator#each passes given arguments at initialized to receiver.each"
def f
yield "trol"
yield "olol"
yield "lolo"
end
var f = function() {
continuation = {};
continuation = {
next: function() {
@mieko
mieko / output_safety.rb
Last active August 29, 2015 13:59
Rails-style ERB output escaping for Opal
# Implement automatic output escaping for ERB. It works a lot like Rails
#
# Check out this article by Yehuda Katz to get the idea:
# http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/
#
# Effectively any generated output is escaped unless it is html_safe?
#
# Nothing is safe except a few built-in classes, and Dirt::SafeString.
#
# You can generate a Dirt::SafeString from any object by calling #html_safe.
module Dirt
# This is the simplest inflector that would be useful. It doesn't have a list
# of any preloaded irregulars (e.g., Person -> People).
#
# Use Dirt::Inflector::irregular! to add your special cases.
#
# You can create an Inflector with #new, as expected, but the system has
# a default inflector, which is accessed via .instance. Calling methods
# on the class delegates to the default instance.
#