Skip to content

Instantly share code, notes, and snippets.

@panesofglass
panesofglass / Specification.cs
Created October 26, 2009 16:16
A generic specification base class.
using System;
using System.Linq.Expressions;
namespace Foundation.Specifications
{
/// <summary>
/// Defines an abstract class from which to create conditional specifications.
/// </summary>
/// <typeparam name="T">The type of entity used in the specification.</typeparam>
/// <seealso href="http://ubik.com.au/article/named/implementing_the_specification_pattern_with_linq" />
@kiliman
kiliman / LinqPadPrecompiler.cs
Created February 29, 2012 22:01
LinqPadPrecompiler for CS-Script http://www.csscript.net/
// Written by Michael Carter ([email protected])
// Copyright (c) 2012. All rights reserved.
//
// Redistribution and use of this code WITHOUT MODIFICATIONS are permitted provided that
// the following conditions are met:
// 1. Redistributions must retain the above copyright notice, this list of conditions
// and the following disclaimer.
// 2. Neither the name of an author nor the names of the contributors may be used
// to endorse or promote products derived from this software without specific
// prior written permission.
@riyadparvez
riyadparvez / CsvUtils.cs
Created January 6, 2013 14:48
DataTable to CSV extension methods. Export to CSV file, CSV string
public static class CSV
{
public static string ToCSV(this DataTable table)
{
var columnHeaders = (from DataColumn x in table.Columns
select x.ColumnName).ToArray();
StringBuilder builder = new StringBuilder(String.Join(",", columnHeaders));
builder.Append("\n");
foreach (DataRow row in table.Rows)
@ianmariano
ianmariano / git-fork-sync
Last active June 26, 2024 17:53
Syncs your repo fork with the upstream master and then pushes the synced master to origin. Presumes you have an 'upstream' remote which is from whence your fork was created. Put on your path and chmod a+x it then do: git fork-sync. Use -h for usage help.
#!/usr/bin/env bash
set -Eeuo pipefail
VERSION="20200421.1"
_usage() {
cat << __EOF
$0 usage:
public class RequireRouteValuesAttribute : ActionMethodSelectorAttribute {
public string[] ValueNames { get; private set; }
public RequireRouteValuesAttribute(params string[] valueNames) {
ValueNames = valueNames;
}
/// <summary>
/// Check for all strings
/// </summary>
<?php
// This map would show Germany:
$south = deg2rad(47.2);
$north = deg2rad(55.2);
$west = deg2rad(5.8);
$east = deg2rad(15.2);
// This also controls the aspect ratio of the projection
$width = 1000;
using System;
using System.Text.RegularExpressions;
using System.Reflection;
namespace RegexLibraryBuilder
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class RegexBuilderMain
{
@lakenen
lakenen / index.html
Last active September 21, 2024 14:43 — forked from abeppu/index.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://d3js.org/d3.v2.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div id="chart"></div>
@em0ney
em0ney / example.html
Last active June 15, 2018 17:53
A list-group-addon for prepending glyphicons to list groups in Bootstrap-3
<ul class="list-group">
<li class="list-group-item-cust list-group-item"><span class="list-group-addon glyphicon glyphicon-calendar"></span>
&nbsp;8th March 2014</li>
<li class="list-group-item-cust list-group-item"><span class="list-group-addon glyphicon glyphicon-time"></span>
&nbsp;10:00</li>
<li class="list-group-item-cust list-group-item"><span class="list-group-addon glyphicon glyphicon-flag"></span>
&nbsp;Location</li>
</ul>
@vkhorikov
vkhorikov / CustomerController.cs
Last active April 20, 2025 09:15
Handling failures and input errors in a functional way
[HttpPost]
public HttpResponseMessage CreateCustomer(string name, string billingInfo)
{
Result<BillingInfo> billingInfoResult = BillingInfo.Create(billingInfo);
Result<CustomerName> customerNameResult = CustomerName.Create(name);
return Result.Combine(billingInfoResult, customerNameResult)
.OnSuccess(() => _paymentGateway.ChargeCommission(billingInfoResult.Value))
.OnSuccess(() => new Customer(customerNameResult.Value))
.OnSuccess(