Skip to content

Instantly share code, notes, and snippets.

@cybermaxs
cybermaxs / loadspeedv2.js
Created September 8, 2014 11:29
Compares page load time between HTML5 Navigation timings and basic computation using Date.now() (examples/loadspeed.js). Requires PhantomJS 2.0
var page = require('webpage').create(),
system = require('system'),
t, address;
if (system.args.length === 1) {
console.log('Usage: loadspeedv2.js <some URL>');
phantom.exit(1);
} else {
t = Date.now();
address = system.args[1];
@cybermaxs
cybermaxs / Benckmark.cs
Last active August 29, 2015 14:07
Yet another fast Enum.ToString() Implementation. Read explanations http://cybermaxs.wordpress.com/2014/10/03/the-importance-of-useless-micro-optimization/
using Ideafixxxer.Generics;
using System;
using System.Diagnostics;
using System.Text;
namespace EnumBenchmarks
{
public enum MyEnum
{
Undefined = 0,
@cybermaxs
cybermaxs / Statup.cs
Created December 19, 2014 11:23
Batch requests experiments in Web Api. Like the async & parallel processing on server-side
using Owin;
using System.Web.Http;
using System.Web.Http.Batch;
namespace BatchRequestDemo
{
public class Startup
{
// This code configures Web API. The Startup class is specified as a type
// parameter in the WebApp.Start method.
@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;
@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 / 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 / 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 / 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)
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 / 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;