Skip to content

Instantly share code, notes, and snippets.

@m0sa
m0sa / keybase.md
Created May 4, 2017 10:52
keybase.md

Keybase proof

I hereby claim:

  • I am m0sa on github.
  • I am m0sa (https://keybase.io/m0sa) on keybase.
  • I have a public key ASAavKcbBv6nHLYVkk6S6ok_cEEKg0TWjww4sulsl1EfzAo

To claim this, I am signing this object:

@m0sa
m0sa / mathjax-editing.js
Last active April 8, 2016 15:18 — forked from dpvc/mathjax-editing.js
StackExchange MathJax editing code
// The MIT License (MIT)
//
// Copyright (c) 2016 Stack Exchange
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@m0sa
m0sa / readme.md
Created December 4, 2015 09:03
SourceFrom file size Encoding inconsitency
  • install SourceLink (via run chocho install sourcelink) and be sure it's in your path
  • copy the test.csx to a solution where the 1.1.0 Microsoft.CodeAnalysis.CSharp package is installed
  • start the VS development console (msbuild has to be in the path), run csi test.csx

Example output:

v:\example> csi .\CompilationCrazy.csx

SourceLink 1.1.0

876aa6db6eb96d35bbdee9f1586d9f94ff90d928 v:\example\precompilation\obj\huge.cs

@m0sa
m0sa / StringBuilderInterpolationOptimizer.cs
Last active October 19, 2015 08:23
Roslyn Adventures: Optimizing StringBuilder string interpolation
class StringBuilderInterpolationOptimizer : CSharpSyntaxRewriter
{
private readonly SemanticModel _model;
public StringBuilderInterpolationOptimizer(SemanticModel model)
{
_model = model;
}
// we use the semantic model to get the type information of the method being called
private static bool CanRewriteSymbol(SymbolInfo symbolInfo, out bool appendNewLine)
<Query Kind="Program">
<NuGetReference>Microsoft.AspNet.Mvc</NuGetReference>
<NuGetReference>Microsoft.CodeAnalysis.CSharp</NuGetReference>
<Namespace>System.CodeDom.Compiler</Namespace>
<Namespace>System.Web.Razor</Namespace>
<Namespace>System.Web.WebPages.Razor</Namespace>
<Namespace>Microsoft.CodeAnalysis</Namespace>
<Namespace>Microsoft.CodeAnalysis.CSharp</Namespace>
<Namespace>Microsoft.CodeAnalysis.Emit</Namespace>
<Namespace>Microsoft.CodeAnalysis.Text</Namespace>
@m0sa
m0sa / so_hangouts_auth.user.js
Last active June 8, 2016 08:13
SO Hangouts Authuser Redirect
// ==UserScript==
// @name SO Hangouts Authuser Redirect
// @namespace http://m0sa.net/
// @version 1.1
// @description authuser=1
// @author m0sa
// @include https://plus.google.com/hangouts/_/stackoverflow.com/*
// @include https://hangouts.google.com/hangouts/_/stackoverflow.com/*
// @grant none
// ==/UserScript==
@m0sa
m0sa / protobuf-codedom-vs-roslyn.linq
Last active August 29, 2015 14:10
Roslyn vs CodeDom IL
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\System.IO.dll</Reference>
<Reference>&lt;RuntimeDirectory&gt;\System.Reflection.dll</Reference>
<Reference>&lt;RuntimeDirectory&gt;\System.Runtime.dll</Reference>
<Reference>&lt;RuntimeDirectory&gt;\System.Text.Encoding.dll</Reference>
<Reference>&lt;RuntimeDirectory&gt;\System.Threading.Tasks.dll</Reference>
<NuGetReference Prerelease="true">Microsoft.CodeAnalysis</NuGetReference>
<NuGetReference Prerelease="true">Microsoft.CodeAnalysis.Common</NuGetReference>
<NuGetReference Prerelease="true">Microsoft.CodeAnalysis.CSharp</NuGetReference>
<NuGetReference>protobuf-net</NuGetReference>
@m0sa
m0sa / Program.Original.cs
Created November 2, 2014 00:25
Walk the #line
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string foobar = _s("$foo$ bar", new { foo = Foo() }), baz = Baz();
}
static string Foo() { return "Foo"; }
@m0sa
m0sa / RssController.cs
Created September 27, 2012 18:46
Syndication of Google+ articles and notes to an RSS feed
// the controler:
public class RssController : Controller
{
private readonly IGoogleSettings _settings;
public RssController(IGoogleSettings settings)
{
_settings = settings;
}
@m0sa
m0sa / ZeroMQ-XPUB.py
Created April 3, 2012 22:32
Example of the ZeroMQ XPUB socket, that shows how the producer can be controlled by the number of subscribers
import thread
import time
import zmq
from zmq.core.socket import Socket
# global zmg context
context = zmq.Context()
endpoint = "tcp://*:8888"
# the subscriber thread function