Skip to content

Instantly share code, notes, and snippets.

View johnkors's full-sized avatar

John Korsnes johnkors

View GitHub Profile
@johnkors
johnkors / UIButtonCentered
Created May 9, 2011 17:22
En sentrert UIButton i MonoTouch
public UIButton GetCenteredButton()
{
var buttonWidth = 250f;
var center = (window.Frame.Width / 2) - (buttonWidth / 2); //BYTT UT window MED DITT VIEW OM DU ER I EN VIEWCONTROLLER
var position = new RectangleF(center,50f,buttonWidth,100f);
var uiButton = new UIButton(position);
uiButton.BackgroundColor = UIColor.Gray;
var textButtonLabel = new UILabel();
textButtonLabel.Text = "Trykk her";
textButtonLabel.BackgroundColor = UIColor.Red;
@johnkors
johnkors / Overload.js
Created June 14, 2012 10:28
"Overloads" in javascript
// http://howtonode.org/connect-it
// 1: store original
// 2: overwrite existing method with new function with extra functionality
// 3: in new function from 2, call the original method stored in 1.
module.exports = function logItSetup() {
// Initialize the counter
var counter = 0;
using System;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Dispatcher;
using Ninject;
namespace WebApiNinjectIHttpControllerActivator
{
public class NinjectKernelActivator: IHttpControllerActivator
{
@johnkors
johnkors / gist:5205893
Last active December 15, 2015 04:59
InterfaceImplementations_Always_ShouldBeInjected
[Test]
public void InterfaceImplementations_Always_ShouldBeInjected()
{
var interfaces = _source.OfType<InterfaceDeclarationSyntax>().Select(
x => x.Identifier.ToString()
);
var classes = _source.OfType<ClassDeclarationSyntax>();
var implementsInterface = classes.Where(
c => (
@johnkors
johnkors / gist:5319953
Created April 5, 2013 14:59
Eksempel på bruk av eksternt assembly via scriptingstyle cshart: csx
#r "Faggruppe.MyBusiness.dll"
using System;
using Faggruppe.MyBusiness;
var person = new Person();
for(int i =1; i < 6; i++)
{
var person = new Person();
var spoken = person.Speak();
@johnkors
johnkors / gist:5501060
Created May 2, 2013 09:02
Powershell script to install karma test runner on Windows. This uses Chocolatey to install node.js, but could also be done by downloading the msi. The script needs to be run with Administrator privileges.
# helper to update ps sessions env variables
function Update-Environment {
$locations = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
'HKCU:\Environment'
$locations | ForEach-Object {
$k = Get-Item $_
$k.GetValueNames() | ForEach-Object {
$name = $_
$value = $k.GetValue($_)
## Octopus Azure deployment script, version 1.0
## --------------------------------------------------------------------------------------
##
## This script is used to control how we deploy packages to Windows Azure.
##
## When the script is run, the correct Azure subscription will ALREADY be selected,
## and we'll have loaded the neccessary management certificates. The Azure PowerShell module
## will also be loaded.
##
## If you want to customize the Azure deployment process, simply copy this script into
@johnkors
johnkors / PreDeploy.ps1
Created February 6, 2014 16:29
Octopus Deploy - PreDeploy.ps1 for Windows Azure when wanting to modify Cloud Service instance count and/or certificate thumbprint values.
<#
.SYNOPSIS
Modifies some Azure cscfg entries that Octopus Deploy 2.0 is not able to as of today.
.DESCRIPTION
Sets the thumbprint of the first certificate value. Sets the instance count for each role. Octopus-variables must match either of the two forms:
Azure.Role[rolename].Instances
Azure.Role[rolename].Certificate
where rolename is the roleName as defined in the ServiceConfiguration.Cloud.csfcg.
The config file must be named ServiceConfiguration.Cloud.cscfg.
#>
## Octopus Azure deployment script, version 1.0
## --------------------------------------------------------------------------------------
##
## This script is used to control how we deploy packages to Windows Azure.
##
## When the script is run, the correct Azure subscription will ALREADY be selected,
## and we'll have loaded the neccessary management certificates. The Azure PowerShell module
## will also be loaded.
##
## If you want to customize the Azure deployment process, simply copy this script into
@johnkors
johnkors / ElasticEventService
Created January 26, 2015 11:29
IdentityServer v3 IEventService implementation using the Serilog ElasticSearch sink to provide messages on LogStash format
public class ElasticSearchEventService : IEventService
{
private readonly ElasticsearchSink _nativeSink;
public ElasticSearchEventService(IElasticSearchEventConfig conf)
{
var elasticsearchSinkOptions = new ElasticsearchSinkOptions(conf.ElasticSearchUri);
_nativeSink = new ElasticsearchSink(elasticsearchSinkOptions);
}