Skip to content

Instantly share code, notes, and snippets.

@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;
--------------------------------------------------------------------------------
-- 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 / 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
@cybermaxs
cybermaxs / http.js
Created October 9, 2015 11:28
List all http anchor in a web site
[].forEach.call(document.querySelectorAll('a'), function(a) {
var href = a.getAttribute('href');
if(href && href.indexOf('http:')>-1)
console.log(href);
});
@cybermaxs
cybermaxs / cleanup.ps1
Last active August 29, 2015 14:28
Clean up your .net solutions folders with powershell. Delete bin, obj, packages and TestResults
Write-Host "Deleting bin, obj, packages,TestResults folders ..." -nonewline
Get-ChildItem -inc bin,obj,TestResults,packages -rec | Remove-Item -rec -force
Write-Host "Done" -ForegroundColor Yellow
@cybermaxs
cybermaxs / PerfStatsExtensions.cs
Created June 4, 2015 08:57
Extension methods for performance statistics (avg, median, centiles)
using System;
using System.Linq;
namespace MyNamespace
{
public static class PerfStatsExtensions
{
public static double? Avg(this double[] values)
{
if (values == null) return null;
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
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