Skip to content

Instantly share code, notes, and snippets.

using System;
using System.IO;
public class LogSearcher
{
public static int DateLength = "2013-12-29 17:37:56".Length;
public void Search(string path, DateTime start, DateTime end, TextWriter results)
{
using (var file = File.Open(path, FileMode.Open))
@ryanohs
ryanohs / choropleth.htm
Last active August 29, 2015 13:57
Presentation examples for Nebraska Code Camp.
<html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<script src="us-states.js"></script>
</head>
<body>
<div id="map" style="height: 580px"></div>
<script>
public static class SystemTime
{
private static readonly ThreadLocal<Func<DateTime>> _Now = new ThreadLocal<Func<DateTime>>(() => () => DateTime.Now);
public static DateTime Now
{
get { return _Now.Value(); }
}
public static ResetSystemTime Set(DateTime executionTime)
@ryanohs
ryanohs / gist:844100
Created February 25, 2011 17:09
DDD update sample
public class TradeController
{
private readonly IRepository<Trade> _Trades;
public TradeController(IRepository<Trade> trades)
{
_Trades = trades;
}
[ValidationExceptionFilter]
@ryanohs
ryanohs / gist:2048500
Created March 16, 2012 04:24
Merge Sort - CoffeeScript
mergesort = (input) ->
n = input.length
if n == 1
return input
pivot = Math.floor n/2
a = mergesort input[0...pivot] # coffee script does not include the last element in a slice
b = mergesort input[pivot...n]
merge(a, b)
merge = (a, b) ->
@ryanohs
ryanohs / gist:2048499
Created March 16, 2012 04:24
Merge Sort - C++
int* mergesort(int input[], size_t length)
{
if(length == 1)
{
return input;
}
int pivot = length/2;
size_t a_length = pivot;
size_t b_length = length-pivot;
int *a = mergesort(input, a_length);
using System;
using System.Collections.Generic;
using System.Linq;
using PagedList;
public class DataTablesSearch
{
public string Value { get; set; }
public bool Regex { get; set; }
}
@ryanohs
ryanohs / EFHelpers.cs
Last active June 15, 2016 02:33
For updating database from disconnected entities.
public static class EFHelpers
{
/// <summary>
/// Helper function to update an EF model child collection from a view model posted from javascript.
/// </summary>
public static void MergeGraph<TModel, TUpdate, TId>(
ICollection<TModel> modelCollection,
ICollection<TUpdate> updateCollection,
DbSet<TModel> dbSet,
Func<TModel, TId> modelId,
@ryanohs
ryanohs / FastAccessor.cs
Created April 2, 2016 15:31
Playing with IL generation.
public class FastAccessor<T> where T : class
{
private static readonly Hashtable _cache = new Hashtable();
public static FastAccessor<T> For(T target)
{
if (_cache.ContainsKey(typeof(T)))
{
var dlg = (Action<T, string, object>)_cache[typeof(T)];
return new FastAccessor<T>(dlg, target);