Skip to content

Instantly share code, notes, and snippets.

View haraldfianbakken's full-sized avatar

Harald S. Fianbakken haraldfianbakken

View GitHub Profile
@haraldfianbakken
haraldfianbakken / New-SVXProxyClient.ps1
Last active April 21, 2016 10:40
Creating a custom proxy client method in Powershell
function Create-SVCProxies{
[CmdletBinding()]
param([Parameter(Mandatory=$true)]$endpoint);
# If the endpoint name contians .svc , give it a more reasonable classname.
$className = $endpoint.Name -replace ".svc" , "";
# WMF5 required (PowerShell 5)
$f = New-TemporaryFile;
@haraldfianbakken
haraldfianbakken / Posting SAML Assertion to from PowerShell
Created April 29, 2015 06:29
Sample code on how to post an xml / base64 encoded file as a SAMLResponse to a server (Saml assertion)
Add-Type -AssemblyName System.Web;
$samlFile = "C:\Tmp\Assertion.xml"
$serviceProviderUri = "http://MYAPP/Sso/Acs"
function Get-SamlPayload($file){
$f = Get-ChildItem $file;
# If the file is an xml, content must be encoded.
if($f.Extension -match ".xml"){
$payload = ([xml](Get-Content $file)).InnerXml;
# Simple PowerShell script to load-test / test REST api with headers and cookies.
# Harald S. Fianbakken
$headers = @{
"Accept"= "application/zip";
"Accept-Encoding"= "gzip,deflate,sdch";
"My-Token-ID" = "This_is_a_test";
};
function Create-Cookie($name, $value, $domain, $path="/"){
$loginBase = "https://itunesconnect.apple.com";
$loginUrl = "$($loginBase)/WebObjects/iTunesConnect.woa";
# Load the login-page
$r = Invoke-WebRequest $loginUrl -SessionVariable ws;
# Set the login data
$form = $r.Forms[0];
$form.Fields["theAccountName"] = "this-is-a-test@gmail.com";
$form.Fields["theAccountPW"] = "this_is_my_password";
@haraldfianbakken
haraldfianbakken / ndc-battle-note
Last active August 29, 2015 14:00
The power of the shell
$test=@"
using System;
using System.IO;
using System.Media;
public class Beep
{
public static void Play( double frequency, double duration )
{
BeepBeep( 1000, frequency, duration );
@haraldfianbakken
haraldfianbakken / angular-error-handling
Last active August 29, 2015 14:00
Global error handling in angular
angular.module('MyApp').config(function($httpProvider){
$httpProvider.interceptors.push(function($rootScope, $q){
return {
'request': function(config){
config.timeout = 5000;
return config;
}
}
});
@haraldfianbakken
haraldfianbakken / powershell_huge_files
Created April 12, 2014 22:12
Powershell performance on huge files
$method1 = [scriptblock]{
gc Data\SwissProt.xml, Data\SwissProt.xml|Set-Content -Path Output.xml
}
$method2 = [scriptblock]{
gc -ReadCount 512 Data\SwissProt.xml, Data\SwissProt.xml|Set-Content -Path Output2.xml;
}
#Measure-Command -Expression $method1;
@haraldfianbakken
haraldfianbakken / PS_Stream
Created April 12, 2014 21:03
Powershell - Streaming and pipeline example
# Get a continous log stream and pass it down the line
gc .\Data\Sample.log -Tail 3 -Wait|Select-String "MyAwsomePattern"
@haraldfianbakken
haraldfianbakken / workaround
Last active August 29, 2015 13:58
transition-workaround
$scope.removeInsuranceCard = function(card){
var confirmed = confirm('Do you want to remove this item?');
if(confirmed){
$log.debug("Removing item @"+$scope.data.selectedIndex);
$scope.data.items.splice($scope.data.selectedIndex,1);
$scope.selectedItem = $scope.data.items[$scope.data.selectedIndex];
$stateParams.index = $scope.data.selectedIndex;
// Force GUI TO be updated when removing the item bug in the carousel
$state.transitionTo($state.current, $stateParams, {
@haraldfianbakken
haraldfianbakken / controller-example
Created April 10, 2014 08:42
controller-example
controller : function ($scope, $log, $stateParams, init, service) {
var ctrl = new slideController($scope,$log,$stateParams,init);
$scope.addInsuranceCard = function(){
$scope.data.items.push({});
}
$scope.removeInsuranceCard = function(card){
var confirmed = confirm('Do you want to remove this item?');
if(confirmed){