Skip to content

Instantly share code, notes, and snippets.

View lantoli's full-sized avatar

Leo Antoli lantoli

View GitHub Profile
@lantoli
lantoli / 1_LoopExtension.java
Last active August 29, 2015 14:11
LoopExtension.java
package com.experimental;
import java.util.Stack;
import nu.xom.Attribute;
import nu.xom.Document;
import nu.xom.Element;
import nu.xom.Elements;
import org.concordion.api.Evaluator;
@lantoli
lantoli / AlphabeticalOrder.cs
Last active August 29, 2015 14:11
Reto MSDN AlphabeticalOrder
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Security.Cryptography;
using System.Text;
namespace UnitTestProject8
{
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Linq;
// http://json.codeplex.com/
// NUGET: install-package Newtonsoft.Json
// MY TIME: Millisecs = 0, Ticks = 588 (total 357 ms)
namespace Reto7
{
@lantoli
lantoli / 1StudiousStudentWrong.java
Last active September 25, 2015 13:13
Studious Student
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;
public class StudiousStudentWrong {
public static void main(String[] args) throws Exception {
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace Reto_6
{
[DebuggerDisplay("Count = {Count}, ActiveCount = {ActiveCount}")]
[DebuggerTypeProxy(typeof(CacheDebugView))]
using System.Collections.Generic;
using System.Linq;
namespace Reto5
{
public class DictionaryPlus<TK, TV> : Dictionary<TK, TV>
{
public IEnumerable<TV> this[params TK[] keys] {
get {
return keys.Select(key => base[key]);
/*
We are asked to give a random derangement: http://en.wikipedia.org/wiki/Derangement
We use a slight modification of Fisher-Yates shuffle algorithm to make sure it's a derangement.
This algoritm works because all elements are moved one or more times to the left so at the end
all elements are in different positions than the original one.
But with this modification, random properties are not great. For example some permutations are more
likely than others, and there are some permutatations which can never happen.
@lantoli
lantoli / ObjectDumper.cs
Last active August 29, 2015 14:07
Refactored ObjectDumper from @eiximenis
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Dict = System.Collections.Generic.Dictionary<string, System.Delegate>;
using Pair = System.Collections.Generic.KeyValuePair<string, string>;
namespace ObjectDumper
{
public class ObjectDumper<T> where T: class
@lantoli
lantoli / Reto.cs
Last active August 29, 2015 14:06
Leo Antoli Solution to reto 2 MSDN defining add and remove http://blogs.msdn.com/b/esmsdn/archive/2014/09/19/retosmsdn-reto-2-161-esos-eventos.aspx
// Leo Antoli solution to reto 2 MSDN using add and remove: http://blogs.msdn.com/b/esmsdn/archive/2014/09/19/retosmsdn-reto-2-161-esos-eventos.aspx
// NOTE: It's not thread-safe, locking should be added.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Reto2ClassLibrary
{
// Leo Antoli solution to reto 2 MSDN: http://blogs.msdn.com/b/esmsdn/archive/2014/09/19/retosmsdn-reto-2-161-esos-eventos.aspx
using System;
using System.Linq;
namespace Reto2ClassLibrary
{
public class Reto2 : IReto2
{
public event EventHandler EventFired;