Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
kristopherjohnson / rfc3339.swift
Last active May 2, 2019 01:38
Parsing or formatting an RFC 3339 timestamp using NSDateFormatter
import Foundation
/// Parse RFC 3339 date string to NSDate
///
/// :param: rfc3339DateTimeString string with format "yyyy-MM-ddTHH:mm:ssZ"
/// :returns: NSDate, or nil if string cannot be parsed
public func dateForRFC3339DateTimeString(rfc3339DateTimeString: String) -> NSDate? {
let formatter = getThreadLocalRFC3339DateFormatter()
return formatter.dateFromString(rfc3339DateTimeString)
}
@correia
correia / swift-kvo-example.swift
Last active April 16, 2023 02:38
A quick example for how to use Foundation style KVO from Swift. (Official documentation from Apple is forthcoming.)
//
// Swift-KVO
//
// Created by Jim Correia on 6/5/14.
// Copyright (c) 2014-2015 Jim Correia. All rights reserved.
//
// Update: 6/17/2014
//
// KVOContext has gone away; use the same idiom you'd use from Objective-C for the context
//
@vikrum
vikrum / 95th.py
Created December 31, 2013 21:50
Get 95th percentile from stdin
#!/usr/bin/env python
#
# based on http://stackoverflow.com/a/2753343o
#
# input needs to be presorted
#
import math
import functools
import fileinput
#!/bin/bash
# Add Vagrant's NFS setup commands to sudoers, for `vagrant up` without a password
# Updated to work with Vagrant 1.3.x
# Stage updated sudoers in a temporary file for syntax checking
TMP=$(mktemp -t vagrant_sudoers)
cat /etc/sudoers > $TMP
cat >> $TMP <<EOF
# Allow passwordless startup of Vagrant when using NFS.
@praeclarum
praeclarum / Layout.cs
Created March 16, 2013 05:23
A C# syntax for NSLayoutConstraints.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using MonoTouch.UIKit;
namespace Async.iOS
{
public static class Layout
{
@tony4d
tony4d / p4merge4git.md
Created August 24, 2012 19:00
Setup p4merge as a visual diff and merge tool for git
@n1k0
n1k0 / gist:1501173
Created December 20, 2011 10:44 — forked from fbuchinger/gist:1501115
PhantomJS: Capturing single dom elements as png files
var page = new WebPage(),
address, output, size;
//capture and captureSelector functions adapted from CasperJS - https://github.com/n1k0/casperjs
capture = function(targetFile, clipRect) {
var previousClipRect;
var clipRect = {top: 0, left:0, width: 40, height: 40};
if (clipRect) {
if (!isType(clipRect, "object")) {
throw new Error("clipRect must be an Object instance.");
@kylebarrow
kylebarrow / example.html
Created June 23, 2011 06:30
Prevent links in standalone web apps opening Mobile Safari
<!DOCTYPE html>
<head>
<title>Stay Standalone</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<script src="stay_standalone.js" type="text/javascript"></script>
</head>
<body>
<ul>
<li><a href="http://google.com/">Remote Link (Google)</a></li>
@atheken
atheken / JSUnitTest.js
Created September 26, 2010 13:00
JavaScript Unit Test Creator
/*
via: http://javascriptweblog.wordpress.com/2010/09/20/auto-generating-javascript-unit-tests/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+JavascriptJavascript+(JavaScript,+JavaScript)
*/
var tester = {
testing: [],
console: window.console || {log: function(a) {window.status = a}, warn: alert},
defineBaseTests: function() {
this.baseTestBefore = [this.argumentsDefinedTest, this.thisBindingTest];
this.baseTestAfter = [this.returnTest];
@atheken
atheken / 0_ProductModel.cs
Created July 22, 2010 00:21
Multiple snippets of how to use NoRM to do common tasks, originally authored by: Anirudh Sanjeev (http://github.com/ninjagod)
//This is a model that will be used in each of the examples below.
public class Product
{
public Product()
{
// Default values are to be set here
Shipping = new Address();
}
public ObjectId _id{get;set;}
public double Price{get;set;}