Skip to content

Instantly share code, notes, and snippets.

@scichelli
scichelli / IssuesList.cs
Created March 18, 2015 22:06
Parse the JSON of GitHub's issues into a pipe-delimited file for importing into a spreadsheet application
namespace IssuesList
{
using System;
using System.Linq;
using System.IO;
using System.Reflection;
using Newtonsoft.Json;
class Program
{
public static class EnumerableExtensions
{
public static IEnumerable<T> NullToEmpty<T>(this IEnumerable<T> items)
{
return items ?? Enumerable.Empty<T>();
}
}
@scichelli
scichelli / ResultCompanion.cs
Created January 14, 2014 14:56
Blog comment from uvwu on http://lostechies.com/sharoncichelli/2014/01/13/maybe-that-shouldnt-be-settable/. Code transcribed by me, so blame me for any typos.
public static class Result
{
private const int UNKNOWN_STATUS_CODE = -1;
private const string UNKNOWN_STATUS_PHRASE = @"WAT?";
public static Result<t> Success(T result = default(T))
{
return Result<t>.Success(new[] { result });
}
public class MyCoolService
{
public Result<CoolThing> Fetch(Uri uri)
{
HttpResponseMessage response = CallThatThingInTheCloud(uri);
return response.IsSuccessStatusCode
? Result<CoolThing>.Success(Deserialize(response))
: Result<CoolThing>.Error(response.StatusCode, response.ReasonPhrase);
}
public class Result<T>
{
public bool IsSuccess { get; private set; }
public string ErrorMessage { get; private set; }
public IEnumerable<T> Results { get; private set; }
private Result()
{ }
public static Result<T> Success(IEnumerable<T> results)
public class MyCoolService
{
public Result<CoolThing> Fetch(Uri uri)
{
HttpResponseMessage response = CallThatThingInTheCloud(uri);
if (response.IsSuccessStatusCode)
{
return new Result<CoolThing>
{
public class Result<T>
{
public bool IsSuccess { get; set; }
public string ErrorMessage { get; set; }
public IEnumerable<T> Results { get; set; }
}
@scichelli
scichelli / ExplicitFixie.cs
Created June 13, 2013 15:31
Making an explicit test for Fixie
public class MyTestsExplicit
{
public void RunOnlyOnDemand()
{
throw new Exception("You ran me on purpose, didn't you?");
}
}
@scichelli
scichelli / ServoSweep.ino
Created November 27, 2012 04:07
Arduino example sketch controlling a servo motor
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
@scichelli
scichelli / sleep.ps1
Created November 27, 2012 02:14
Show an alert and then set the computer to sleep
$WarningDuration = 5
$MessagePlural = ""
if ($WarningDuration -gt 1) { $MessagePlural = "s" }
[System.Media.SystemSounds]::Asterisk.play()
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[windows.forms.messagebox]::show(("Save your work. Sleep in {0} minute{1}." -f $WarningDuration, $MessagePlural))
Start-Sleep -Second ($WarningDuration * 60)
[System.Media.SystemSounds]::Beep.play()