Skip to content

Instantly share code, notes, and snippets.

View devlead's full-sized avatar

Mattias Karlsson devlead

View GitHub Profile
@devlead
devlead / gist:6046575
Created July 20, 2013 22:04
Had some twitter discussions with Filip Ekberg ( @fekberg ) about a blog post he wrote (http://blog.filipekberg.se/2013/07/12/are-you-serving-files-insecurely-in-asp-net/) I didn't agrree 100% with his post and some times 140 chars isn't enough to make you point, so toke 10 minutes before bed to write an quick code example and comment more detai…
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.Caching;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using FileDownloadSecurityIdeas.Models;
@devlead
devlead / AzureFriday
Last active August 29, 2015 13:57
Get all high quiality azure friday episodes for Build trip
$(Invoke-RestMethod -Uri http://channel9.msdn.com/Shows/Windows-Azure-Friday/feed/mp4high)|%{$pattern = "[{0}]" -f ([Regex]::Escape( [System.IO.Path]::GetInvalidFileNameChars() -join '' )); @{ FileName = [RegEx]::Replace($_.title + ".mp4", $pattern, ''); Url=@($_.group.content.url |sls high.mp4)[0].ToString()} }|%{if(!(Test-Path -Path $_.FileName )){Invoke-WebRequest -Uri $_.Url -OutFile $_.FileName}}
@devlead
devlead / gist:6f6d706dbdd572031377
Last active August 29, 2015 14:10
PiFace Quickstart Mono

#Ladda ner

git clone git://git.drogon.net/wiringPi

#Kompilera

cd wiringPi 
./build 
@devlead
devlead / gist:9638825a3380fa473bca
Created December 8, 2014 18:45
POSH GIT Batch update remote
gci -Directory -Recurse .git -Hidden|%{pushd;cd (Split-Path -Parent $_);(git remote -v)-split "`n"|%{$r=$_ -split "`t| ";iex "git remote set-url $(if($r[2]-eq"(push)"){"--push "})$($r[0]) $($r[1]-replace ("John","Doe"))"} ;popd}
@devlead
devlead / AddBitbucketSlackHook
Created January 8, 2015 15:06
Rough 1min add slack hook to all or certain repos PowerShell sample
$owner = "repo owner"
$body = @{type="POST";URL="slack hook"}
$cred=Get-Credential
$repos = Invoke-RestMethod -Credential $cred -Uri 'https://api.bitbucket.org/1.0/user/repositories/'
#All repos
$repos |Where-Object {$_.owner -eq $owner} | %{$uri="https://bitbucket.org/api$($_.resource_uri)/services/";Invoke-RestMethod -Uri $uri -Body $body -Method Post -Credential $cred}
#Filter repos
$repos |Where-Object {$_.owner -eq $owner -and $_.resource_uri -like "*needle*" } | %{$uri="https://bitbucket.org/api$($_.resource_uri)/services/";Invoke-RestMethod -Uri $uri -Body $body -Method Post -Credential $cred}
@devlead
devlead / PostMessage.ps1
Created January 8, 2015 16:10
Post to slack from PowerShell
$postSlackMessage = @{token="*topsecret*";channel="#general";text="Hello from PowerShell!";username="PowerShell";icon_url="https://pbs.twimg.com/profile_images/1604347359/logo_512x512_normal.png"}
Invoke-RestMethod -Uri https://slack.com/api/chat.postMessage -Body $postSlackMessage
@devlead
devlead / NewAzureMachine.ps1
Created January 20, 2015 10:44
PowerShell Script to easily provision a dev environment in Azure using Chocolatey
Param(
[string]$SubscriptionName = ((Get-AzureSubscription|?{$_.SubscriptionName -like "*MSDN*"})[0].SubscriptionName),
[string]$AzureVMImageName = "03f55de797f546a1b29d1b8d66be687a__Visual-Studio-2013-Ultimate-Update4-AzureSDK-2.5-Win8.1-x64"
)
function InstallWinRMCert($serviceName, $vmname)
{
$winRMCert = (Get-AzureVM -ServiceName $serviceName -Name $vmname | select -ExpandProperty vm).DefaultWinRMCertificateThumbprint
$AzureX509cert = Get-AzureCertificate -ServiceName $serviceName -Thumbprint $winRMCert -ThumbprintAlgorithm sha1
@devlead
devlead / README.md
Created April 1, 2015 14:02
Windows 10 aware app.manifest

OSVersion

In windows 8.1 Environment.OSVersion underlying Win32 GetVersionEx function changed to for compatibility reasons report latest version app is compiled for.

The code

Console.WriteLine(
    System.Environment.OSVersion
    );
DROP TABLE dbo.Events
DROP TABLE dbo.Streams
CREATE TABLE dbo.Streams(
StreamId CHAR(40) NOT NULL,
StreamIdOriginal NVARCHAR(1000) NOT NULL,
StreamIdInternal INT IDENTITY(1,1) NOT NULL,
IsDeleted BIT NOT NULL DEFAULT ((0)),
CONSTRAINT PK_Streams PRIMARY KEY CLUSTERED (StreamIdInternal)
);
@devlead
devlead / ValidateCountry.ps1
Created May 13, 2015 09:17
ValidateScript is very powerful to validate script / fucntion parameters, example below validate country based on rest service
Param(
[ValidateScript(
{
$countries = ((Invoke-RestMethod -Uri https://raw.githubusercontent.com/devlead/ISO-3166-Countries-with-Regional-Codes/master/all/all.json)| % Name)
if ( $countries -contains $_)
{
$true
}
else
{