Skip to content

Instantly share code, notes, and snippets.

View Fosna's full-sized avatar

Vedran Marsic Fosna

View GitHub Profile
// Run as snippet in chrome when on event lottery page.
(function () {
// Returns a random integer between min (included) and max (excluded)
// Using Math.round() will give you a non-uniform distribution!
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
function renderTable(placeholderSelector, names) {
<?xml version="1.0" encoding="utf-8"?>
<UserSettings>
<ApplicationIdentity version="14.0"/>
<ToolsOptions>
<ToolsOptionsCategory name="Environment" RegisteredName="Environment"/>
</ToolsOptions>
<Category name="Environment_Group" RegisteredName="Environment_Group">
<Category name="Environment_FontsAndColors" Category="{1EDA5DD4-927A-43a7-810E-7FD247D0DA1D}" Package="{DA9FB551-C724-11d0-AE1F-00A0C90FFFC3}" RegisteredName="Environment_FontsAndColors" PackageName="Visual Studio Environment Package">
<PropertyValue name="Version">2</PropertyValue>
<FontsAndColors Version="2.0">
@Fosna
Fosna / BuildExp.linq
Created January 22, 2016 09:25
It's suggested to use LINQPad 5 (download link: http://www.linqpad.net/download.aspx). How to build expression tree without lambda function. Use dynamic LINQ.
Expression<Func<int, int, int>> addExp = (a, b) => a + b;
Console.WriteLine(addExp);
var aArg = Expression.Parameter(typeof(int), "a");
var bArg = Expression.Parameter(typeof(int), "b");
var addBody = Expression.Add(aArg, bArg);
var buildAddExp = (Expression<Func<int, int, int>>)Expression.Lambda(addBody, aArg, bArg);
Console.WriteLine(buildAddExp);
@Fosna
Fosna / SimpleLogicalExpression.linq
Created January 22, 2016 09:22
It's suggested to use LINQPad 5 (download link: http://www.linqpad.net/download.aspx). Look at debug output to get familiar with expression tree.
Expression<Func<int, int, int>> exp =
(a, b) => a + b;
Console.WriteLine(exp);
@Fosna
Fosna / TreeVsDelegate.linq
Created January 22, 2016 09:20
It's suggested to use LINQPad 5 (download link: http://www.linqpad.net/download.aspx). See what's the difference between lambda delegate and lambda expression tree.
Func<int, int, int> addDel = (a, b) => a + b;
Console.WriteLine(addDel);
int d = addDel(1, 2);
Console.WriteLine(d);
Expression<Func<int, int, int>> addExp = (a, b) => a + b;
Console.WriteLine(addExp);
@Fosna
Fosna / SimpleBinaryExpression.linq
Created January 22, 2016 09:17
It's suggested to use LINQPad 5 (download link: http://www.linqpad.net/download.aspx). See that expression tree you get from expression a + b looks awfully like abstract syntax tree nodes that Roslyn compiler uses.
Expression<Func<int, int, int>> exp =
(a, b) => a + b;
Console.WriteLine(exp);
@Fosna
Fosna / AddStatement.linq
Created January 22, 2016 09:11
It's suggested to use LINQPad 5 (download link: http://www.linqpad.net/download.aspx). See how Roslyn C# compiler generates abstract syntax tree for expression a + b. See how does IL code for this expression look like.
int a = 0;
int b = 0;
int c = 0;
c = a + b;