Skip to content

Instantly share code, notes, and snippets.

require 'cgi'
require 'base64'
require 'openssl'
def oauth_url(url)
parameters = ["oauth_consumer_key=#{ENV.fetch 'OAUTH_KEY'}",
"oauth_nonce=#{Random.rand(100000000).to_s}",
"oauth_signature_method=#{'HMAC-SHA1'}",
"oauth_timestamp=#{Time.now.to_i.to_s}",
"oauth_version=1.0"].join('&')
#!/usr/bin/env ruby
require 'securerandom'
require 'json'
require 'benchmark'
require 'bunny'
conn = Bunny.new
conn.start
ch = conn.create_channel
x = ch.default_exchange
b = Bunny.new ENV.fetch 'CLOUDAMQP_URL', connection_timeout: 10
b.start
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
process(data)
ch.ack delivery.delivery_tag
end
@carlhoerberg
carlhoerberg / a.md
Last active September 1, 2015 20:11
Spamassassin and postfix on Ubuntu 14.04

Install:

apt-get install spamassassin postfix

in /etc/postfix/master.cf modify;

smtp inet n - - - - smtpd
<%@ 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);
Model.RenderControl(writer);
%>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" /> <!-- Require SSL must be OFF in the site settings -->
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
@carlhoerberg
carlhoerberg / MigrateAndGenerateContext.cmd
Created May 26, 2010 09:47
Work with Linq to Sql and Migrator
@echo off
setlocal
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 http://code.google.com/p/migratordotnet/
echo Applying migrations
..\Libs\Migrator\Migrator.Console SqlServer %connStr% "..\MyProject.Migrations\Bin\Debug\MyProject.Migrations.dll" -trace
@carlhoerberg
carlhoerberg / SyncDB.cmd
Created May 27, 2010 11:38
Sync two MsSql databases
@echo off
setlocal
set path="%programfiles%\IIS\Microsoft Web Deploy";%PATH%
msdeploy -verb:sync -source:dbFullSql="Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=true",computerName=yourcomputer.com ^
-dest:dbFullSql="Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=true",dropDestinationDatabase=true
endlocal
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
carlhoerberg / cookies.js
Created September 15, 2015 08:05
Cookies as a hash
var cookies = document.cookie.split("; ").reduce(function(o, c) { var s = c.split("="); o[s[0]] = s[1]; return o; }, {});