Skip to content

Instantly share code, notes, and snippets.

@marciol
marciol / FSharpSerialization.fsx
Created October 16, 2012 04:03 — forked from theburningmonk/FSharpSerialization.fsx
Serializing/Deserializing F# Record and DU types
#r "System.Xml.dll"
#r "System.Runtime.Serialization.dll"
open Microsoft.FSharp.Reflection
open System.IO
open System.Reflection
open System.Runtime.Serialization
open System.Runtime.Serialization.Formatters.Binary
open System.Runtime.Serialization.Json
open System.Text
@marciol
marciol / T4TemplateEngine.cs
Created August 15, 2012 04:24
Simple Solution to Rendering Engine in .net C#
public interface IRenderable
{
string TransformText();
string Render<T>(object parameters);
void Initialize();
}
public partial class Layout : IRenderable
{
public IRenderable Content { get; set; }
@marciol
marciol / QueryAdventureWorksWithDapperAndLambdas.cs
Created August 11, 2012 23:24
Genial solution to return anonymous types for a function using Dapper and lambda expressions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using Dapper;
namespace ConsoleApplication2
{
@marciol
marciol / PathToRegex.cs
Created August 11, 2012 23:22
PathToRegexForMicroWebFramework
private Dictionary<string, string> PathForRegex(string path)
{
var dic = new Dictionary<string, Regex> {
{"foo", new Regex("foo/(?<directory_id>\\d+)/bar/(?<coast>\\d+)/hei", RegexOptions.ExplicitCapture)},
{"hei", new Regex("foo/(?<name>\\w+)/jow", RegexOptions.ExplicitCapture)}
};
var Params =
(
@marciol
marciol / gist:3290143
Created August 7, 2012 22:43
Custom System Routes (Nancy inspired)
Get("foo/bar.html",
(request, response) => {
using (var connection = new SqlConnection(
System.Configuration.ConfigurationManager.AppSettings["strConnection"]))
{
connection.Open();
var result = connection.Query<ExecutiveReportResult>(
Util.getSql("rm_consulta_relatorio_executivo"),
let newtonSqrt (x : float) : float =
let accuracy : float = 0.00001 // desired accuracy
let rec iterate (x : float) (a : float) : float =
let diff : float = x - a*a
if abs diff <= accuracy
then a
else iterate x ((a + x/a) / 2.0)
iterate x (x/2.0)
let badcode x y =
if y
then newtonSqrt x
else newtonSqrt "abc"
val newtonSqrt : float -> float
let newtonSqrt x =
let accuracy = 0.00001 // desired accuracy
let rec iterate a =
let diff = x - a*a
if abs diff <= accuracy
then a
else iterate ((a + x/a) / 2.0)
iterate (x/2.0)
@marciol
marciol / mysqldump_tips
Created July 12, 2012 15:44
msyqldump command tips
# Only insert data
mysqldump --compact --no-create-info
# Only structure
mysqldump --compact --no-data