Skip to content

Instantly share code, notes, and snippets.

@Eibwen
Eibwen / gist:8854805
Created February 6, 2014 23:39
JsFiddle links
Playing with HSL colors in javascript
http://jsfiddle.net/HfCw2/
@Eibwen
Eibwen / AppleStoreProduct.js
Created November 3, 2014 18:49
Apple laptops research
var _ = require("underscore");
function AppleStoreProduct(baseData) {
_.extend(this, baseData);
}
var specsLookup = [
//Very specific ones... only single matches
{ match: /^(Refurbished |)(?:([0-9\.]+-inch) )?(MacBook (?:Air|Pro)) ([0-9\.]+ ?GHz) ([dD]ual-core|Quad-core) (Intel (?:Core )?(i5|i7))( with Retina Display|)$/,
@Eibwen
Eibwen / DebugTimerRepository.cs
Created November 12, 2014 16:30
DebugTimerRepository - Ability to sum time taken on tasks
/// <summary>
/// How to use this:
/// 1. Get the reference
/// a. Inject IDebugTimerRepository
/// b. call DebugTimerRepository.Instance
/// 2. Log values
/// a. Call _debugTimerRepository.AddValue(string label, long value)
/// Probably using value == Stopwatch.TotalMiliseconds
///
/// Option 2:
@Eibwen
Eibwen / FindUnusedCode_Proposal.cs
Created November 12, 2014 23:49
A proposal for tracking if code is EVER hit or not
void Main()
{
//Usage is simply, anywhere in the solution:
CodeCalledRepository.Instance.CodeHit(CodeCalled.OldAssEmail1);
//Result is:
Database.Dump("Result 1");
CodeCalledRepository.Instance.DEBUGDUMP();
@Eibwen
Eibwen / Quine.cs
Last active December 11, 2015 04:19
Finally got bored enough to get around to writing a quine...
void Main()
{
string pre = SOURCE.Substring(0, SOURCE.LastIndexOf(DELIMITER));
string post = SOURCE.Substring(SOURCE.LastIndexOf(DELIMITER) + 1);
Console.Write(pre + SOURCE.Replace("\"", "\"\"") + post);
}
// Define other methods and classes here
const char DELIMITER = '$';
const string SOURCE = @"void Main()
@Eibwen
Eibwen / ParamNames.cs
Last active December 14, 2015 01:59
type-safe-enum pattern Started from http://stackoverflow.com/a/424414/356218 then MSDN operators...
void Main()
{
ParamNames.TESTVALUE.Dump();
ParamNames.TEST.Dump();
ParamNames p1 = ((ParamNames)ParamNames.TESTVALUE).Dump();
//Not possible:
//ParamNames p2 = (ParamNames.TESTVALUE as ParamNames);
bool t3 = (p1 == ParamNames.TEST).Dump();
bool t4 = (p1 == (ParamNames)ParamNames.TESTVALUE).Dump();
bool t5 = (p1 == ParamNames.TESTVALUE).Dump();
@Eibwen
Eibwen / IFilterItem.cs
Created April 17, 2013 05:30
Fun with interfaces Any object or list of objects to formatted string
void Main()
{
_filters.Add("Integer", new FilterItem<int>(999));
_filters.Add("IntegerList", new FilterListItem<int>(new [] { 1, 2, 3, 863, 2452, 24 }));
_filters.Add("string", new FilterItem<string>("test str"));
foreach (var kvp in _filters)
{
kvp.Value.GetQueryString().Dump();
}
@Eibwen
Eibwen / SemiGenericEncryption.cs
Created May 2, 2013 20:06
Trying to make a nicer interface for obtaining encryption/hash stream
void Main()
{
Guid UserGuid = new Guid("99a2caf0-0c9b-4452-9313-ff6a1d9786fa");
using (MemoryStream ms = new MemoryStream())
using (Stream cs = BasicGoodEncrypt(UserGuid, "imalittleteapot", ms))
{
}
}
@Eibwen
Eibwen / template.bat
Last active February 18, 2016 16:51
Useful windows batch file snippets
:: Check if argument equals string
if /i "%1" equ "/resume" (
echo Resuming now!
)
:: Allow argument, but override if needed
set action=%1
if "%action%"=="" (
set action=start
)
@Eibwen
Eibwen / CleanConsul.js
Last active March 3, 2016 21:05
Deregister services in Consul when they get messy
"use strict";
var request = require('request');
var HOST = "http://127.0.0.1:8500";
var SERVICE_LIST = "/v1/agent/services";
var SERVICE_DEREGISTER = "/v1/agent/service/deregister/";
request(HOST + SERVICE_LIST, (error, response, body) =>