Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace System.Linq
{
public static class IEnumerableExtensionForEach
{
public static void ForEach<T>(this IEnumerable<T> list, Action<T> block) {
@osuritz
osuritz / ValidateJsonAntiForgeryTokenAttribute.cs
Created December 16, 2012 01:40
.NET 4.5 / MVC4-compatible version of ValidateKsonAntiForgeryTokenAttribute
namespace Casero.Web.Mvc
{
using System;
using System.Collections.Specialized;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
// Checks the User's CSRF token
// http://haacked.com/archive/2011/10/10/preventing-csrf-with-ajax.aspx
@MastaP
MastaP / MinCut.java
Created April 5, 2012 21:02
Finding minimum cuts in undirected graph using contraction algorithm
import java.io.*;
import java.util.*;
/**
* https://class.coursera.org/algo/quiz/attempt?quiz_id=52
*/
public class MinCut {
private static class Graph {
@markrendle
markrendle / README.md
Last active August 5, 2017 13:35
Vagrantfile to run Kafka in boot2docker

Kafka in Docker in Vagrant

I'm using this Vagrantfile to run Kafka on a Windows 8.1 laptop for development purposes.

It runs the ultra-lightweight boot2docker Linux, then uses Vagrant's Docker provisioning support to spin up ZooKeeper and Kafka.

The fun bits to work out were:

  • You need to forward the ports on both Vagrant (lines 13 & 14) and Docker (the -p flag), so you can access the instance from Windows using localhost:9092
@DamianEdwards
DamianEdwards / Program.cs
Created March 19, 2013 05:54
Demonstrates that SqlDependency notifications can occur concurrently with the command that set them up. This might cause issues in certain cases if the application isn't expecting multiple commands to be executed at the same time.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
namespace SqlDependencyConcurrency
{
class Program
{
private static readonly string _connectionString = "Data Source=(local);Initial Catalog=Sample;Integrated Security=SSPI;";
@CyrusJavan
CyrusJavan / justify_text.go
Created October 23, 2020 21:23
Justify Text - techincal interview question and answer written in Golang with many comments explaing the answer.
package main
import (
"fmt"
"strings"
)
func main() {
text := "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras " +
"venenatis, quam et dapibus porttitor, nisi mauris maximus sapien, a " +
@taylorkj
taylorkj / gist:9012616
Last active March 27, 2021 14:16
How to use Dapper's new Table Valued Parameter (TVP) in C#
/*
I wasn't able to find a single example on how to actually use Dapper's new TVP, so I though I'd add one.
First of all, you will need to install the Dapper.TVP package from NuGet.
The main item to note is the need to create and populate a list of SqlDataRecords. This is then used to used as part of the
input parameter for Dapper's TableValueParameter.
The API is thus:
@thomaspark
thomaspark / subnav.css
Last active June 6, 2023 10:19
Subnav for Bootstrap 2
section {
padding-top: 60px;
}
.subnav {
margin-bottom: 60px;
width: 100%;
height: 36px;
background-color: #eeeeee; /* Old browsers */
background-repeat: repeat-x; /* Repeat the gradient */
@colmmacc
colmmacc / shardcalc.py
Last active August 7, 2023 11:05
Calculate the blast radius of a shuffle shard
import sys
# choose() is the same as computing the number of combinations. Normally this is
# equal to:
#
# factorial(N) / (factorial(m) * factorial(N - m))
#
# but this is very slow to run and requires a deep stack (without tail
# recursion).
#