Skip to content

Instantly share code, notes, and snippets.

View devlead's full-sized avatar

Mattias Karlsson devlead

View GitHub Profile
@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 / 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
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
{
@devlead
devlead / azure.xml
Created October 17, 2015 08:18
Add new file types under system.webserver
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
@devlead
devlead / git-random-tip.ps1
Last active November 9, 2015 15:08
PowerShell scrips that displays random GIT tips
(irm https://raw.githubusercontent.com/git-tips/tips/master/tips.json)|sort {random}|select -First 1|% {"$($_.title)`r`n$($_.tip)" }
@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;