Skip to content

Instantly share code, notes, and snippets.

View jfoshee's full-sized avatar
🗺️
Exploring

Jacob Foshee jfoshee

🗺️
Exploring
View GitHub Profile
@jfoshee
jfoshee / gist:3086735
Created July 10, 2012 22:48
Convert text string to UIImage in MonoTouch
static public UIImage StringToImage(string s, float fontSize)
{
return StringToImage(s, UIFont.FromName("Helvetica", fontSize));
}
static public UIImage StringToImage(string s, UIFont font)
{
var ns = new NSString(s);
var size = ns.StringSize(font);
UIGraphics.BeginImageContext(size);
@jfoshee
jfoshee / UIViewAnimations.cs
Last active December 14, 2015 01:39
An RAII style class for setting UIView.AnimationsEnabled MonoTouch / Xamarin.iOS
using System;
using MonoTouch.UIKit;
public sealed class UIViewAnimations : IDisposable
{
public UIViewAnimations(bool enabled)
{
_wasEnabled = UIView.AnimationsEnabled;
UIView.AnimationsEnabled = enabled;
}
@jfoshee
jfoshee / ListPickerViewModel.cs
Created March 22, 2013 19:20
Implementation of MonoTouch (Xamarin.iOS) UIPickerViewModel for an IList<T>.
namespace Unplugged
{
public abstract class ListPickerViewModel<TItem> : UIPickerViewModel
{
public TItem SelectedItem { get; private set; }
IList<TItem> _items;
public IList<TItem> Items
{
get { return _items; }
@jfoshee
jfoshee / format-sql-insert
Last active December 19, 2015 13:39
Format a SQL INSERT statement to line up column names with values.
$('#output').text('Ready');
var splitArgList = function (s) {
var first_paren = s.indexOf('(') + 1;
var opening = s.substring(0, first_paren).trim();
var args_closing = s.substring(first_paren);
var last_paren = args_closing.lastIndexOf(')');
var args = args_closing.substring(0, last_paren)
var closing = args_closing.substring(last_paren).trim();
return [opening, args, closing];
@jfoshee
jfoshee / Service Oriented ViewModel MonkeySpace 2013.md
Created July 27, 2013 01:04
Markdown source of slides I presented at MonkeySpace 2013

A Service Oriented ViewModel

Jacob Foshee

MonkeySpace 2013

Summary

  • Service not reinvented by 3rd party
  • VM not reinvented by 2nd device
  • VM Responsible for wrapping DTOs
@jfoshee
jfoshee / PerformanceMeter.cs
Last active August 29, 2015 13:57
PerformanceMeter wraps System.Diagnostics.Stopwatch to easily accumulate basic performance measurements.
using System;
using System.Diagnostics;
namespace Unplugged.Visualization
{
public class PerformanceMeter
{
public int Count { get; private set; }
public double Minimum { get; private set; }
public double Maximum { get; private set; }
@jfoshee
jfoshee / CodeFirstDatabase.cs
Created May 9, 2014 21:03
Sorts ServiceStack.OrmLite POCO table definitions so they can be created without violating foreign key constraints using QuickGraph's topological sort.
using System;
using System.Collections.Generic;
using System.Linq;
using QuickGraph;
using QuickGraph.Algorithms;
using ServiceStack.OrmLite;
namespace Gists
{
public static class CodeFirstDatabase
<?xml version="1.0" encoding="utf-8"?>
<!-- copy to ~/Library/XamarinStudio-5.0/Snippets/ as vmpc.template.xml -->
<CodeTemplates version="3.0">
<CodeTemplate version="2.0">
<Header>
<_Group>C#</_Group>
<Version />
<MimeType>text/x-csharp</MimeType>
<Shortcut>vmpc</Shortcut>
<_Description>property changed</_Description>
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Xunit.Sdk;
namespace Example.Testing
{
/// <summary>
@jfoshee
jfoshee / TypeExtensions.cs
Created May 26, 2021 19:40
Helpful extension methods for System.Type
using System;
namespace Example
{
public static class TypeExtensions
{
/// <summary>
/// Returns a default value for a given Type at run-time.
/// </summary>
public static object GetDefaultValue(this Type type)