Skip to content

Instantly share code, notes, and snippets.

Avatar

Carl Hörberg carlhoerberg

View GitHub Profile
View oauth_signature.rb
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('&')
View rpc_benchmark.rb
#!/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
View gist:0729156d1912fbd2af67
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 Sep 1, 2015
Spamassassin and postfix on Ubuntu 14.04
View a.md

Install:

apt-get install spamassassin postfix

in /etc/postfix/master.cf 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);
Model.RenderControl(writer);
%>
View web.config.xml
<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
Work with Linq to Sql and Migrator
View MigrateAndGenerateContext.cmd
@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
Sync two MsSql databases
View SyncDB.cmd
@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
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
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; }, {});
You can’t perform that action at this time.