Skip to content

Instantly share code, notes, and snippets.

View dterracino's full-sized avatar
🐢
I may be slow to respond…

David Terracino dterracino

🐢
I may be slow to respond…
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
int? minValue = 5;
int? maxValue = 17;
@flq
flq / HttpFileServer.cs
Created April 17, 2010 09:39
Smallest file web server
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
public class HttpFileServer : IDisposable
{
private readonly string rootPath;
private const int bufferSize = 1024*512; //512KB
@katylava
katylava / git-selective-merge.md
Last active February 27, 2024 10:18
git selective merge

Update 2022: git checkout -p <other-branch> is basically a shortcut for all this.

FYI This was written in 2010, though I guess people still find it useful at least as of 2021. I haven't had to do it ever again, so if it goes out of date I probably won't know.

Example: You have a branch refactor that is quite different from master. You can't merge all of the commits, or even every hunk in any single commit or master will break, but you have made a lot of improvements there that you would like to bring over to master.

Note: This will not preserve the original change authors. Only use if necessary, or if you don't mind losing that information, or if you are only merging your own work.

using System;
namespace TCastr.Models
{
/// <summary>
/// An implicitly-convertible buffer that automatically converts between
/// a compact string representation and a Guid.
/// </summary>
/// <remarks>
@tarnacious
tarnacious / gist:874052
Created March 17, 2011 09:26
Compiling SelectMany Linq without System.Linq. Also a List Monad.
using System;
using System.Collections.Generic;
public static class ExtensionMethods
{
public static IEnumerable<T> ToList<T>(this T value) {
yield return value;
}
public static IEnumerable<U> SelectMany<T, U>(this IEnumerable<T> m, Func<T, IEnumerable<U>> k)
@davecowart
davecowart / SelectExtensions.cs
Created March 22, 2011 18:34
DropDown source code
namespace System.Web.Mvc.Html {
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Web;
using System.Web.Mvc.Resources;
@flq
flq / NonTopmostPopup.cs
Created April 5, 2011 08:04
WPF: Popup that is only topmost with respect to parent window. Taken from the comments at http://chriscavanagh.wordpress.com/2008/08/13/non-topmost-wpf-popup/ (Joe Gershgorin) which was in not easy to digest state
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interop;
/// <summary>
/// Popup with code to not be the topmost control
using (var file = new System.IO.StreamReader(script)) {
var fileContent = file.ReadToEnd();
if (scriptType == ScriptType.Stylesheet) {
var fromUri = new Uri(context.Server.MapPath("~/"));
var toUri = new Uri(new FileInfo(script).DirectoryName);
var relativeUri = fromUri.MakeRelativeUri(toUri);
fileContent = fileContent.Replace("url(", "url(/" + relativeUri.ToString() + "/");
}
scriptbody.Append(fileContent);
}
@JohannesRudolph
JohannesRudolph / MethodStatics.cs
Created June 26, 2011 13:30
Caller-dependent method level local statics implementation in C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace MethodStaticLocals
{
class ExpensiveObject
@joelmartinez
joelmartinez / GameOfLife.cs
Created September 5, 2011 03:24
Conway's Game Of Life in C#
using System;
using System.Threading.Tasks;
namespace Life
{
public class LifeSimulation
{
private bool[,] world;
private bool[,] nextGeneration;
private Task processTask;