Skip to content

Instantly share code, notes, and snippets.

@cybermaxs
cybermaxs / DateTimeExtensions.cs
Created April 28, 2015 15:59
Yet another C# datetime extensions to convert DateTime to Unix timestamps.
using System;
namespace MyExtensions
{
public static class DateTimeExtensions
{
public const long EpochTicks = 621355968000000000;
public const long TicksPeriod = 10000000;
public const long TicksPeriodMs = 10000;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace Syntheticks.Tests.Designs
{
public class TimeSeries_AdvancedDesign
@cybermaxs
cybermaxs / NinjectWebCommon.cs
Created September 24, 2013 12:00
Measure and report performance of asp.net MVC Action Filters using asp.net MiniProfiler. Warning : default namespace is MyApp
[assembly: WebActivator.PreApplicationStartMethod(typeof(MyApp.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(MyApp.App_Start.NinjectWebCommon), "Stop")]
// please add a reference to NInject.MVC3
namespace MyApp.App_Start
{
using System;
using System.Web;
using System.Web.Mvc;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace Syntheticks.Tests.Designs
{
public class DataPoint : TableEntity
--------------------------------------------------------------------------------
-- Multi HINCRBY via a LUA script
-- Increments a list of fields in a hash stored at key.
-- KEYS : key of the hash
-- ARGS : list of field/increment
-- Note : Because a script is executed in an atomic way, you should always use this script to increment fields values.
-- ex via cli : redis-cli --eval hmincr.lua myhash , 1 10 2 20
--------------------------------------------------------------------------------
-- gets multiple fields from a redis hash as a dictionary
@cybermaxs
cybermaxs / index.js
Created October 19, 2016 12:52
Percentile Bucket Aggregation with Redis
// npm install native-hdr-histogram prob.js redis
var prob = require('prob.js');
var redis = require("redis");
var Histogram = require('native-hdr-histogram');
//generate fake response times
var random = prob.lognormal(0, 1.0); // μ = 0, σ = 1.0
var histogram = new Histogram(1, 120 * 1000);
var client = redis.createClient({ host: 'localhost', port: 6379 });
@cybermaxs
cybermaxs / EnumHelper.cs
Created October 13, 2016 14:09
Cache Enum.GetValues in an efficient way (I think :))
using System;
using System.Linq;
namespace MyFunnyProject
{
internal static class EnumHelper
{
public static class EnumCache<TEnum>
{
public readonly static TEnum[] Values = null;
using System;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
namespace RegexOptims
{
public static class RegexComparer
{
private const string REGEX_PATTERN = @"^[\w\d]+$";
@cybermaxs
cybermaxs / CustomServiceHost.cs
Last active April 21, 2016 15:55
an attempt to StructureMap4 and nested containers in WCF
using StructureMap;
using System;
using System.ServiceModel;
namespace MyWcfService.Classes
{
public class CustomServiceHost : ServiceHost
{
public CustomServiceHost(IContainer container, Type serviceType, params Uri[] baseAddresses)
: base(serviceType, baseAddresses)
@cybermaxs
cybermaxs / optimize_all.bat
Created February 29, 2016 15:35
Optimize all jpeg via jepgtran in a folder
for %%f in (*.jpg) do jpegtran -copy none -optimize %%f %%~nf.jpg