Skip to content

Instantly share code, notes, and snippets.

View shawnoster's full-sized avatar

Shawn Oster shawnoster

View GitHub Profile
@shawnoster
shawnoster / pprint_color.py
Last active December 27, 2018 20:47 — forked from EdwardBetts/pprint_color.py
Python pprint with color syntax highlighting for the console
from pygments import highlight
from pygments.lexers import PythonLexer, JsonLexer
from pygments.formatters import TerminalFormatter
from pprint import pformat
def ap(obj):
'''Faked Awesome Print'''
print(highlight(pformat(obj), PythonLexer(), TerminalFormatter()))
@shawnoster
shawnoster / propc.sublime-snippet
Created May 9, 2012 05:15
Sublime snippet that inserts a property that raises PropertyChanged
<snippet>
<tabTrigger>propc</tabTrigger>
<content><![CDATA[
private ${1:string} _${2};
public ${1} ${2/./\u$0/}
{
get
{
return _${2};
}
@shawnoster
shawnoster / msbuild.sublime-build
Created May 9, 2012 05:04
msbuild build system for Sublime Text 2
{
"cmd": ["msbuild"],
"path": "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319",
"working_dir": "${project_path:${folder}}",
"file_regex": "^ (.*)\\(([0-9]*),([0-9]*)"
}
@shawnoster
shawnoster / LinqExtensions.cs
Created February 15, 2012 02:17
An extension method that converts an Enumerable to an ObservableCollection
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Librarian.Common
{
public static class Enumerable
{
public static ObservableCollection<TSource> ToObservable<TSource>(this IEnumerable<TSource> source)
{
return new ObservableCollection<TSource>(source);
@shawnoster
shawnoster / gist:1832571
Created February 15, 2012 02:16
AgFx pattern to verify you have valid data (either from cache or web)
public void AuthenticateUser(Action<AuthorizedUser> completed, Action<Exception> error)
{
EnsureIsAuthenticated();
AuthorizedUser = DataManager.Current.LoadFromCache<AuthorizedUser>("authenticated_user");
// LoadFromCache returns an object even if it didn't exist in the
// cache so check one of its properties for existance vs. the object
// itself.
if (!String.IsNullOrEmpty(AuthorizedUser.Id))
@shawnoster
shawnoster / RestSharpLoadRequest.cs
Created February 15, 2012 02:13
An AgFx LoadRequest that uses RestSharp to make the actual request, supports passing in OAuth tokens
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using AgFx;
using RestSharp;
using RestSharp.Authenticators;
namespace Librarian.AgFx
@shawnoster
shawnoster / gist:1832552
Created February 15, 2012 02:12
Some basic REST end-point utilities
private static string UrlCombine(string baseUrl, string resource)
{
if (baseUrl.Length == 0)
{
return baseUrl;
}
if (resource.Length == 0)
{
return resource;