Skip to content

Instantly share code, notes, and snippets.

View kristopherjohnson's full-sized avatar
💭
Huh?

Kristopher Johnson kristopherjohnson

💭
Huh?
View GitHub Profile
@kristopherjohnson
kristopherjohnson / PrettyXml.cs
Created December 4, 2011 18:52
Example of pretty-printing XML in C# using the XmlWriter class
using System;
using System.Text;
using System.Xml;
using System.Xml.Linq;
static string PrettyXml(string xml)
{
var stringBuilder = new StringBuilder();
var element = XElement.Parse(xml);
kdj@localhost ~$ brew install -v dotwrp
==> Cloning https://github.com/tenomoto/dotwrp.git
Updating /Users/kdj/Library/Caches/Homebrew/dotwrp--git
git remote set-url origin https://github.com/tenomoto/dotwrp.git
git fetch origin
git reset --hard origin/HEAD
HEAD is now at ea3da3a Updated README for SDOT.
git checkout-index -a -f --prefix=/private/tmp/homebrew-dotwrp-1.0-Vivz/
==> Using Homebrew-provided fortran compiler.
This may be changed by setting the FC environment variable.
@kristopherjohnson
kristopherjohnson / private.xml
Created March 8, 2012 18:53
Kris Johnson's private.xml settings for KeyRemap4MacBook
<?xml version="1.0"?>
<root>
<!-- Kris Johnson's private.xml settings for KeyRemap4MacBook -->
<!-- See reference manual at http://pqrs.org/macosx/keyremap4macbook/xml.html -->
<item>
<name>Private Settings</name>
<item>
<name>Fn+Backslash(\) to CapsLock</name>
<identifier>private.fn_backslash_to_capslock</identifier>
@kristopherjohnson
kristopherjohnson / Timed.cs
Created April 12, 2012 00:04
Measuring Elapsed Time in C# Methods
public static class Timed
{
/// <summary>
/// Execute action then invoke reporting action with elapsed time
/// </summary>
/// <param name="timedAction">action to be executed and elapsed time measured</param>
/// <param name="reportAction">action to be executed with the elapsed number of milliseconds passed as a parameter</param>
/// <returns>number of milliseconds elapsed during timedAction</returns>
public static long Execute(Action timedAction, Action<long> reportAction)
{
@kristopherjohnson
kristopherjohnson / showActivityIndicator_forTableViewCell.m
Created April 19, 2012 18:19
Display spinning activity indicator in a table-view cell
- (void)showActivityIndicator:(BOOL)show forTableViewCell:(UITableViewCell *)cell
if (show) {
cell.accessoryType = UITableViewCellAccessoryNone;
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[activityIndicatorView startAnimating];
cell.accessoryView = activityIndicatorView;
[activityIndicatorView release];
}
else {
kdj@luna ~$ brew install -v opencv
/usr/bin/env python -c import numpy
==> Downloading http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2
Already downloaded: /Users/kdj/Library/Caches/Homebrew/opencv-2.3.1a.tar.bz2
/usr/bin/tar xf /Users/kdj/Library/Caches/Homebrew/opencv-2.3.1a.tar.bz2
==> Patching
/usr/bin/patch -f -p1 -i 000-homebrew.diff
patching file modules/highgui/src/grfmt_exr.hpp
patching file modules/flann/include/opencv2/flann/any.h
patching file modules/flann/include/opencv2/flann/defines.h
@kristopherjohnson
kristopherjohnson / gist:2479418
Created April 24, 2012 12:56
brew --config output
kdj@luna ~$ brew --config
HOMEBREW_VERSION: 0.9
HEAD: 0beb7abfbc139053351f1858b26065ec6d6c8e55
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: 8-core 64-bit sandybridge
OS X: 10.7.3
Kernel Architecture: x86_64
Xcode: 4.3.2
GCC-4.0: N/A
@kristopherjohnson
kristopherjohnson / sortplist.py
Created April 28, 2012 16:11
Given an XML plist on standard input, write back to standard output with keys sorted
#!/usr/bin/python
#
# Reads plist from standard input and writes it back to standard output
# sorted by key.
from plistlib import readPlist, writePlist
from sys import stdin, stdout
plist = readPlist(stdin)
writePlist(plist, stdout)
@kristopherjohnson
kristopherjohnson / PropertyObserver.h
Created April 28, 2012 19:18
Invokes a block when an observed KVO property changes
// Copyright (C) 2012 Kristopher Johnson
//
// 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
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@kristopherjohnson
kristopherjohnson / makeNewUUIDString-ARC.m
Created April 30, 2012 15:40
Create a new UUID string, ARC-compatible
+ (NSString *)makeNewUUIDString {
CFUUIDRef uuid = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
return (__bridge_transfer NSString *)(string);
}