Skip to content

Instantly share code, notes, and snippets.

@hmemcpy
hmemcpy / gist:3434473
Created August 23, 2012 09:06
Better way to indian?
// converts 0x00010203 to a byte array, containing: 0x03, 0x02, 0x01, 0x00
public static byte[] ToBigEndian(int data)
{
var result = new byte[4];
result[0] = (byte)data;
result[1] = (byte)(((uint)data >> 8) & 0xFF);
result[2] = (byte)(((uint)data >> 16) & 0xFF);
result[3] = (byte)(((uint)data >> 24) & 0xFF);
protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context)
{
var db = container.Resolve<ISisoDatabase>();
container.Register<ISession>((c, overloads) => new SessionWrapper(db.BeginSession()));
}
public class SessionWrapper : ISession
{
readonly ISession session;
@hmemcpy
hmemcpy / gist:2868064
Created June 4, 2012 12:28
Non-generic pattern match
public override IEnumerable<IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
{
IStructuralMatchResult match = Match(registrationRootElement);
if (match.Matched)
{
// ReSharper SSR will match a generic method with this pattern too. If has generic arguments, return
var invocationExpression = match.MatchedElement as IInvocationExpression;
if (invocationExpression == null || invocationExpression.TypeArguments.Count > 0)
{
@hmemcpy
hmemcpy / gist:2585890
Created May 3, 2012 14:08
Which do you like better?
// #1
public IModule GetTargetModule(ICSharpExpression expression)
{
var referenceExpression = expression as IReferenceExpression;
if (referenceExpression != null)
{
var typeofExpression = referenceExpression.QualifierExpression as ITypeofExpression;
if (typeofExpression != null)
{
let unionCases<'a> =
FSharpType.GetUnionCases(typeof<'a>)
|> Array.map (fun x -> FSharpValue.MakeUnion(x, [||]) :?> 'a)
|> Array.toList
let deck : Deck =
(unionCases<Suit>, unionCases<Rank>) ||> cartesianProduct
@hmemcpy
hmemcpy / gist:1435212
Created December 5, 2011 20:27
Find uri.ToString() with ReSharper SSR
Here's how you can find all instances of System.Uri's ToString() method with ReSharper SSR (Structural Search and Replace):
1. Go to ReSharper menu -> Find -> Search with Pattern
2. Type in the following in the search pattern window:
$uri$.ToString()
3. Click 'Add Placeholder', select Expression. In the new dialog, put uri in the Name and 'System.Uri' in Expression type .
4. Click Find!
5. Voilla!
public class AnonymousCheckoutController : StoreController
{
public AnonymousCheckoutController(
Services.ISalesService salesService
, Services.ICartService cartService
, Services.IAccountService accountService
, Services.IEmailerService emailerService
, Services.IDocumentService documentService
, Services.ICacheService cacheService
, Services.IAddressService addressService
Buildfile: file:///D:/code/Tao/Tao.build
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: test
compile-interfaces:
[csc] Compiling 4 files to 'D:\code\Tao\build\net-2.0\Tao.Interfaces.dll'.
[csc] d:\code\Tao\src\Tao.Interfaces\IFunction.cs(8,32): error CS1031: Type expected
[csc] d:\code\Tao\src\Tao.Interfaces\IFunction.cs(8,32): error CS1519: Invalid token 'in' in class, struct, or int
@hmemcpy
hmemcpy / PublishingContextExtensions.cs
Created April 23, 2011 14:38
Updating the blog contents from within PublishNotificationHook
// based on an old blog post in Japanese: http://blog.sharplab.net/computer/cprograming/windowslivewriter/433/
// The field was moved to a base type in the latest version of Live Writer
using System.Reflection;
using WindowsLive.Writer.Api;
using WindowsLive.Writer.Extensibility.BlogClient;
using WindowsLive.Writer.PostEditor;
namespace WindowsLiveWriterPlugin.Extensions
{
@hmemcpy
hmemcpy / R# plugins
Created August 20, 2015 06:35
ReShaper plugins I'm using
CitizenMatt PreviewTab build 1.2.0 on 2015-08-07 09:38:44Z.
ConfigureAwaitChecker v9 build 0.4.0.1 on 2015-08-07 09:38:44Z.
EtherealCode ReSpeller build 4.1.9.0 on 2015-08-07 09:38:44Z.
EtherealCode ReSpellerPro build 4.1.9.0 on 2015-08-07 09:38:44Z.
JetBrains Mnemonics build 1.1.1 on 2015-08-07 09:38:44Z.
JLebosquain EnhancedTooltip build 2.3.1 on 2015-08-07 09:38:44Z.
JoarOyen ReSharper.LiveTemplates build 2.0.1.0 on 2015-08-07 09:38:44Z.
ReSharper AgentMulder build 1.2.0 on 2015-08-07 09:38:44Z.
ReSharper HeapView.R90 build 0.9.7 on 2015-08-07 09:38:44Z.
ReSharper Postfix.R90 build 2.1.1 on 2015-08-07 09:38:44Z.