Skip to content

Instantly share code, notes, and snippets.

@felipegtx
felipegtx / CaculatorTests.cs
Created August 3, 2015 22:05
Some more monads
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TDD.CalculatorImpl;
namespace TDD.UnityTests
{
[TestClass]
public class CaculatorTests
{
private ICalculator _calculator;
public abstract class InstanceResolverFor<SomeType>
{
public static Func<SomeType> InstanceBuilder = () =>
{
throw new Exception(string.Format("The type '{0}' does not have a valid factory.", typeof(SomeType).FullName));
};
public static SomeType Instance { get { return InstanceBuilder(); } }
}
@felipegtx
felipegtx / singleton.cs
Last active August 29, 2015 14:00
C# singleton class
/// SimpleLocker class avaliable at: https://gist.github.com/felipegtx/6107975
public sealed class SingletonFor<TheType>
{
private static Func<TheType> _instanceBuilder = null;
private Func<TheType> _constructorCall = null;
private SimpleLocker _locker = null;
private bool _isInitialized = false;
private TheType _instance;
public bool IsInitialized { get { return _locker.Read(() => _isInitialized); } }
@felipegtx
felipegtx / full.html
Last active August 29, 2015 13:56
Resposta desafio 2
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<style>
table tr td
{
height: 2px;
}
@felipegtx
felipegtx / Desafio2.cs
Created February 25, 2014 14:33
Contador de bytes do Desafio 2
using System;
using System.IO;
using System.Linq;
namespace Desafio2
{
class Program
{
private static string[] EXTENSIONS = new string[] {
".exe", ".log", ".pdb", ".js", ".html", ".htm",
@felipegtx
felipegtx / monads1.cs
Last active August 29, 2015 13:56
Monads in C#
public class Program
{
static Func<int> Identity(int x)
{
return () => x;
}
static Func<int, Func<int>> Multiply(Func<int> what)
{
@felipegtx
felipegtx / SimpleLocker.cs
Last active December 20, 2015 09:29
Lock manager for C# (wrapping a RWLSlim implementation)
using System;
using System.Threading;
namespace Threading
{
public sealed class SimpleLocker
{
private ReaderWriterLockSlim _locker = new ReaderWriterLockSlim();
private int _lockTimeout = 1000;
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace YCombinatorCSharp
{
class Program
{
static void Main(string[] args)
{
@felipegtx
felipegtx / miniRT.js
Created November 18, 2012 23:33
Gerenciador de assinaturas JS
/// <reference path="../jQueryMin.js" />
(function (window) {
var miniRT = (function () {
var configuracoesBasicas = {
nomePlugin: "Default",
intervalo: 5000,
iniciarAutomaticamente: true,
@felipegtx
felipegtx / Base.js
Last active October 12, 2015 04:58
Base lib for JS
/// https: //gist.github.com/felipegtx/3974654
(function (window) {
window.Base = (function () {
var publicMembers = {
CreatePropertyBag: function (owner, defaults) {
/// <summary>