Skip to content

Instantly share code, notes, and snippets.

View oauth_signature.rb
require 'cgi'
require 'base64'
require 'openssl'
def oauth_url(url)
parameters = ["oauth_consumer_key=#{ENV.fetch 'OAUTH_KEY'}",
View rpc_benchmark.rb
#!/usr/bin/env ruby
require 'securerandom'
require 'json'
require 'benchmark'
require 'bunny'
conn =
ch = conn.create_channel
x = ch.default_exchange
View gist:0729156d1912fbd2af67
b = ENV.fetch 'CLOUDAMQP_URL', connection_timeout: 10
ch = b.create_channel # by default only one thread will be used per channel for processing messages
ch.prefetch 50
ch.queue('my-jobs', durable: true).subscribe(ack: true) do |delivery, headers, body|
data = JSON.parse body
ch.ack delivery.delivery_tag
carlhoerberg /
Last active Sep 1, 2015
Spamassassin and postfix on Ubuntu 14.04


apt-get install spamassassin postfix

in /etc/postfix/ modify;

smtp      inet  n       -       -       -       -       smtpd
View Chart.ascx
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Web.UI.DataVisualization.Charting.Chart>" %>
Model.Page = this.Page;
var writer = new HtmlTextWriter(Page.Response.Output);
View web.config.xml
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" /> <!-- Require SSL must be OFF in the site settings -->
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
carlhoerberg / MigrateAndGenerateContext.cmd
Created May 26, 2010
Work with Linq to Sql and Migrator
View MigrateAndGenerateContext.cmd
@echo off
set path="%CommonProgramFiles(x86)%\microsoft shared\TextTemplating\10.0";"%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools";%path%
set connStr="Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=true"
REM Download MigratorDotNet from
echo Applying migrations
..\Libs\Migrator\Migrator.Console SqlServer %connStr% "..\MyProject.Migrations\Bin\Debug\MyProject.Migrations.dll" -trace
carlhoerberg / SyncDB.cmd
Created May 27, 2010
Sync two MsSql databases
View SyncDB.cmd
@echo off
set path="%programfiles%\IIS\Microsoft Web Deploy";%PATH%
msdeploy -verb:sync -source:dbFullSql="Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=true", ^
-dest:dbFullSql="Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=true",dropDestinationDatabase=true
View VarCharLengthValidatorProvider.cs
public class VarCharLengthValidatorProvider : AssociatedValidatorProvider
protected override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context, IEnumerable<Attribute> attributes)
var columnAttribute = attributes.OfType<System.Data.Linq.Mapping.ColumnAttribute>().FirstOrDefault();
if (columnAttribute == null || !columnAttribute.DbType.ToLower().Contains("varchar"))
yield break;
var match = Regex.Match(columnAttribute.DbType, @"(\d+)", RegexOptions.IgnoreCase);
if (match.Success)
carlhoerberg / cookies.js
Created Sep 15, 2015
Cookies as a hash
View cookies.js
var cookies = document.cookie.split("; ").reduce(function(o, c) { var s = c.split("="); o[s[0]] = s[1]; return o; }, {});