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
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();
@aliostad
aliostad / MemoryCacheNoFinalizer.cs
Created October 4, 2013 14:26
Not disposing MemoryCache results in memory leak
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 1000000000; i++)
{
var memoryCache = new MemoryCache("sdf"); // leads to memory leak!!!
// WHILE THIS ONE DOES NOT
// var memoryStream = new MemoryStream(new byte[100000]);
Date/Time: 2014-02-13 01:55:04 +0000
OS Version: 10.9 (Build 13A3028)
Architecture: x86_64
Report Version: 18
Event: Sleep Wake Failure
Steps: 44
Hardware model: MacBookPro11,1
Active cpus: 4
public static class CircuitBreakerExtensions
{
/// <summary>
///
/// </summary>
/// <param name="circuit">async work</param>
/// <param name="timeout">it abandons the work if not finished until this timeout</param>
/// <param name="finalTimeout">timeout for when the task runs for final time</param>
/// <param name="tries">number of times to try the work</param>
/// <param name="retryRemedy">after each unscuccessful retry, this will be called and the index will be passed</param>
public interface IConnectionProvider
{
IConnection GetConnection();
}
public class ConnectionProvider : IConnectionProvider
{
private IConnection _connection;
private SortedDictionary<FactoryWrapperScore, IConnectionFactoryWrapper> _stats =
new SortedDictionary<FactoryWrapperScore, IConnectionFactoryWrapper>();
@aliostad
aliostad / elasticsearch snippets.md
Created October 26, 2014 13:06
elasticsearch snippets

Sort and define numbers to return

{
	"query": {"match_all" :{}}
    ,
	"size": 10,
	"sort": { "PubDate":{ "order": "desc" }}
}
@aliostad
aliostad / TableStorageDumper.cs
Created November 26, 2014 15:25
Table Storage Dumper
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
namespace TableStorageDumper
@aliostad
aliostad / es_index_copier
Created December 2, 2014 21:02
Copies an ElasticSearch index between two servers using Bulk method
from __future__ import unicode_literals
import requests
import json
from io import StringIO
from requests.auth import HTTPBasicAuth
import datetime, pytz
def copy_indexes(sourceSearchUrl, destinationBulkUrl, newIndexName=None, newTypeName=None, auth=None):
BatchSize = 40