Skip to content

Instantly share code, notes, and snippets.

View aliostad's full-sized avatar
🐒
I may be slow to respond.

Ali Kheyrollahi aliostad

🐒
I may be slow to respond.
View GitHub Profile
@aliostad
aliostad / ThreadExtensions.cs
Created June 9, 2012 16:47
ASYNC/AWAIT - To repro problems Tugberk experienced. VS2012 - .NET 4.5
using System.Diagnostics;
namespace System.Threading
{
public static class ThreadNameTracingExtensions
{
/// <summary>
/// if thread has a name, it leaves the name as it is. If it does not have a name,
/// it sets the thread's name to the module.method
/// It outputs as
@aliostad
aliostad / IEnumerableExtensions.cs
Created June 25, 2012 20:29
ForEachOne for IEnumerable<T> not having to use ToList().ForEach()
using System;
using System.Collections.Generic;
using System.Linq;
namespace System.Collections.Generics
{
public static class IEnumerableExtensions
{
public static IEnumerable<T> ForEachOne<T>(this IEnumerable<T> enumerable, Action<T> action)
{
@aliostad
aliostad / PollingWorker.cs
Created June 26, 2012 15:40
A class that creates a dedicated thread to poll
using System.Collections.Generic;
namespace System.Threading
{
public class PollingWorker : IPollingWorker,IDisposable
{
private class TickAction
{
public string Name { get; set; }
public Action Work { get; set; }
@aliostad
aliostad / CacheCow.Client.Sample.cs
Created August 6, 2012 21:57
CacheCow.Client sample. Requires CacheCow.Client v>=0.1.3
using System;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using CacheCow.Client;
using CacheCow.Client.Headers;
namespace ConsoleApplication1
{
class Program
@aliostad
aliostad / CacheCow.Client.Sample.cs
Created August 6, 2012 21:57
CacheCow.Client sample. Requires CacheCow.Client v>=0.1.3
using System;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using CacheCow.Client;
using CacheCow.Client.Headers;
namespace ConsoleApplication1
{
class Program
@aliostad
aliostad / CommandLineParse.cs
Created August 17, 2012 10:54
Parses commandline into name value pairs
/// <summary>
/// Parses commandline parameters that are in format of
/// -name:value
/// /name=value
/// -name="value 1"
/// </summary>
public static class CommandLineParser
{
private const string CommandLinePattern =
"\\s+[-/](?<name>\\w+)[=:](?:(?<value>[^\\s\\:\"]+)|(?:\"(?<value>.*)\"))";
@aliostad
aliostad / app.config
Created August 29, 2012 11:30
Turn off simple.data tracing
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="simpleData">
<section name="simpleDataConfiguration" type="Simple.Data.SimpleDataConfigurationSection, Simple.Data"/>
</sectionGroup>
</configSections>
<simpleData>
<simpleDataConfiguration traceLevel="Error"/>
</simpleData>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
@aliostad
aliostad / ko.js
Last active December 16, 2015 03:38
A simple js view model
function ViewModel(price, discountPercentage){
this.price = price;
this.discountPercentage = discountPercentage;
}
ViewModel.prototype.getRealPrice = function(){
return this.price * this.discountPercentage;
class Program
{
static void Main(string[] args)
{
Func<string> getStuff = () =>
{
Console.WriteLine("Called!");
return Guid.NewGuid().ToString();