Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / Shell.fs
Created December 20, 2012 20:55 — forked from dvdsgl/Shell.fs
// Demo:
//
// let files = sh "ls -a /Users/david" |> lines
// let install = sh "cp -r %s /Applications"
// install "/Volumes/Awareness/Awareness.app"
//
module Campari.Shell
open System
jQuery.download = function (url, data, callback) {
if (jQuery.browser.msie) {
download(url, data, callback);
} else {
setTimeout(function() {
download(url, data, callback);
}, 100);
}
};
(defun ruby-align-hash (begin end)
"Aligns ruby symbol-keyed hashes"
(interactive "r")
(align-regexp begin end "\\(\\s-*\\)[a-z_]+:" 1 1))
(define-key ruby-mode-map "\C-xrh" 'ruby-align-hash)
@marciol
marciol / gist:5071576
Last active December 14, 2015 10:19
.emacs
;; initialize packages
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
@marciol
marciol / script_rails.rb
Last active December 16, 2015 16:09
In order to allow the requirement of gems that aren't in Gemfile, remember that the gems must be installed in global gemset as made below with the pry-debugger.
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
# In order to allow the requirement of gems that aren't in Gemfile
# remember that the gems must be installed in global gemset
/* =============================================================
* bootstrap-typeahead.js v2.2.2
* http://twitter.github.com/bootstrap/javascript.html#typeahead
* =============================================================
* Copyright 2012 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*