Skip to content

Instantly share code, notes, and snippets.

@kenegozi
kenegozi / untyped-mongodb.cs
Created August 28, 2012 21:02
Accessing mongodb using the official c# driver without types
using System;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Wrappers;
using Newtonsoft.Json;
namespace Mongothingies {
class Program {
static void Main() {
var server = MongoServer.Create();
@kenegozi
kenegozi / MobileServices_WindowsPhone.cs
Created August 29, 2012 00:38
First glance on my unofficial Windows Phone SDK for Azure Mobile Services
// in App.xaml.cs
public partial class App : Application
{
public static readonly MobileServiceClient MobileServiceClient;
public static User CurrentUser;
static App()
{
// Get this data from the management portal's quickstart page
// in the 'connect to existing apps' section
@kenegozi
kenegozi / EditMyMobileServiceDataWithExcel.cs
Created September 7, 2012 07:06
Editing Azure Mobile Service data using Excel
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using Microsoft.Office.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Excel = Microsoft.Office.Interop.Excel;
// Humidity and temperature monitor
// for Arduino UNO R3 (and probably most others)
// Main pieces:
// DHT11 humidity/temp sensor
// - mandatory 10k pull-up resistor
// -> using DHT.f by adafruit at https://github.com/adafruit/DHT-sensor-library
// 16x2 LCD
// - 10K potentiometer for contrast control
// - Push button and transistor for backlight control
// - 220ohm resistor to make the backlight a bit darker
@kenegozi
kenegozi / IncludeInterfacesModelMetadataProvider.cs
Created August 22, 2011 21:23
Allowing MVC3 model validator to use interface attributes
class IncludeInterfacesModelMetadataProvider : DataAnnotationsModelMetadataProvider {
protected override IEnumerable<Attribute> FilterAttributes(Type containerType, PropertyDescriptor propertyDescriptor, IEnumerable<Attribute> attributes) {
var validationAttributesOnInterfaces =
from i in containerType.GetInterfaces()
from p in i.GetProperties()
where p.Name == propertyDescriptor.Name
from a in p.GetCustomAttributes(true).Cast<Attribute>()
where typeof(ValidationAttribute).IsAssignableFrom(a.GetType())
select a;
@kenegozi
kenegozi / ParallelHttpRequests.cs
Created March 15, 2011 22:46
Demonstrating the use of WebClient.DownloadStringAsync to parallelize http requests
class ParallelHttpRequests
{
static void Main()
{
var count = 300;
var root = "http://files.kenegozi.com/temp/";
ServicePointManager.DefaultConnectionLimit = 1000;
@kenegozi
kenegozi / XunitConsoleForwarder.cs
Created June 25, 2017 22:35
Capturing console output in Xunit 2 tests
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Xunit.Abstractions;
namespace MagicalUnicorns {
public class XunitConsoleForwarder : TextWriter {
private readonly ITestOutputHelper output;
@kenegozi
kenegozi / GistsResolver.cs
Created September 4, 2012 07:03
Given a gist embed script tag, get the gist's content
public class GistsResolver {
public static string CreateContentForFeedFrom(string content) {
try {
return UnwrapGists(content, GetGist);
}
catch {
return content;
}
}