Skip to content

Instantly share code, notes, and snippets.

View Splat's full-sized avatar

Ryan Donahue Splat

  • Earth
View GitHub Profile
# 9 out of 10 microbenchmarks agree: implicit return smokes explicit return
require 'benchmark'
def explicit
return 1
end
def implicit
1
end
@Splat
Splat / gist:c5ac481c004400b1c435
Last active August 29, 2015 14:04
Cloudmine example of an application using push notifications from a shared application with multiple data stores, IDs and Keys.
//
// AppDelegate.m
// CarsGalore
//
// Copyright (c) 2014 Cloudmine. All rights reserved.
//
// This is a sample application which shows how to have users and data
// in one app but push notifications are coming from a shared app that
// is responsible for sending multiple applications notifications.
@Splat
Splat / AppDelegate
Created July 17, 2014 15:22
Cloudmine example of an application using push notifications from a shared application with multiple data stores, IDs and Keys.
//
// AppDelegate.m
// CarsGalore
//
// Copyright (c) 2014 Cloudmine. All rights reserved.
//
// This is a sample application which shows how to have users and data
// in one app but push notifications are coming from a shared app that
// is responsible for sending multiple applications notifications.
@Splat
Splat / escapist.js
Created August 29, 2014 14:11
quick and dirty regex replacement for html and xml encoding.
function Escapist() {
}
// escapeXml escapes XML, but not HTML because HTML does not know & apos;.
// However most browsers also support & apos; in HTML documents.IE is not most browsers.
Escapist.prototype.escapeHTML = function (str) {
var htmlCharMap = {
'<': '&lt;',
'>': '&gt;',
@Splat
Splat / Mongo-River-Elasticsearch-Init
Created February 4, 2015 21:31
Initialization of mongo using to elasticsearch
sudo apt-get update
sudo apt-get install openjdk-6-jre-headless -f
sudo apt-get install curl
sudo apt-get install unzip
sudo apt-get install openssh-server
sudo curl -OL http://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.8.zip
sudo unzip elasticsearch-* && rm elasticsearch-*.zip
cd elasticsearch-0.19.8
sudo mkdir /usr/local/elasticsearch
@Splat
Splat / s3.sh
Last active August 29, 2015 14:20 — forked from chrismdp/s3.sh
# You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
# This is how I upload my new Sol Trader builds (http://soltrader.net)
# Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
S3KEY="my aws key"
S3SECRET="my aws secret" # pass these in
function putS3
{
path=$1
using System;
using System.Drawing;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using MonoTouch.CoreGraphics;
public class SplatClearToolbar: UIToolbar
{
UIViewController vc;
@Splat
Splat / MonoTouch UITextField with DoneButton for NumberPad
Last active December 11, 2015 05:09
MonoTouch/iOS number pad keyboard needs a UIToolbar to include a button to resign the first responder of a UITextField because it doesn't include any built in way. This is a custom sub-classed UITextField which given a keyboard type that is a number pad will format a toolbar with a done button.
using System;
using MonoTouch.UIKit;
using System.Drawing;
public class CustomTextField : UITextField
{
public CustomTextField (UIKeyboardType keyboardType) {
// iPad doesn't really need it.
if (keyboardType == UIKeyboardType.NumberPad && DeviceHelper.IsIPhone()) {
UIToolbar numPadToolBar;
@Splat
Splat / monotouch_image_normalization
Last active December 17, 2015 02:19
Monotouch normalize image to orientation for shipping to external applications | servers which may not respect the EXIF data.
public static UIImage RotateImage (this UIImage image)
{
if (image.Orientation == UIImageOrientation.Up) return image;
UIGraphics.BeginImageContextWithOptions(image.Size, false, image.CurrentScale);
iimage.DrawAsPatternInRect(new RectangleF(0, 0, image.Size.Width, image.Size.Height));
UIImage normalizedImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return normalizedImage;
}
@Splat
Splat / activity-alertview
Created September 17, 2013 13:28
Given iOS7 no longer recommends or renders added subviews to the screen... And given that many people added activity indicators to alert view to block the applications main thread while blocking operations are ongoing... This takes an alert message and displays the message along with marching ants to indicate something is going on.
NSTimer timer;
UIAlertView alertView = new UIAlertView ("test", "Testing the animation\n ", null, null, new string[] {});
alertView.Presented += (object sender, EventArgs e) => {
using (var pool = new NSAutoreleasePool())
{
timer = NSTimer.CreateRepeatingScheduledTimer(1, delegate {
if (alertView.Message.EndsWith("..."))
{
string newMessage;
newMessage = alertView.Message.Remove (alertView.Message.Length - 3);