Skip to content

Instantly share code, notes, and snippets.

View nordineb's full-sized avatar

Nordine Ben Bachir nordineb

  • Bekk
  • Oslo, Norway
View GitHub Profile
@nordineb
nordineb / SwapGit.sh
Last active October 9, 2017 10:24
Speed up git on cygwin
mv /cygdrive/c/cygwin/bin/git.exe /cygdrive/c/cygwin/bin/git.cygwin.exe
ln -s /cygdrive/c/Program\ Files/Git/bin/git.exe /cygdrive/c/cygwin/bin/git.exe
@nordineb
nordineb / run.sh
Last active October 11, 2017 13:58
RDP to a linux VM
az group create -l westeurope -n testlinuxRG
az vm create -n ubuntuvm -g testlinuxRG --image UbuntuLTS --generate-ssh-keys
### SSH into the VM
sudo apt-get update
sudo apt-get install xfce4
sudo apt-get install xrdp
echo xfce4-session >~/.xsession
sudo service xrdp restart
sudo netstat -plnt | grep rdp
@nordineb
nordineb / run.sh
Last active September 20, 2018 14:33
Azure Instance Metadata service
# Get all metadata
curl -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2017-04-02"
# Get all network metadata
curl -H Metadata:true "http://169.254.169.254/metadata/instance/network?api-version=2017-04-02"
# Get public ip only
curl -H Metadata:true "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-04-02&format=text"
@nordineb
nordineb / README.md
Created October 11, 2017 14:42
userPrincipalName(UPN) Vs samAccountName

userPrincipalName(UPN) Vs samAccountName

The samAccountName is the User Logon Name in Pre-Windows 2000 (this does not mean samAccountName is not being used as Logon Name in modern windows systems). The userPrincipalName is a new way of User Logon Name from Windows 2000 and later versions. user Name part can be different for the same user like DomainName\testUser and [email protected].

SamAccountName

  • The samAccountName attribute is the user logon name used to support clients and servers from a previous version of Windows ( Pre-Windows 2000).
  • The user logon name format is : DomainName\testUser.
  • The samAccountName must be unique among all security principal objects within the domain.
  • The samAccountName should be less than 20 characters.
  • Query for the new name against the domain to verify that the samAccountName is unique in the domain.
@nordineb
nordineb / README.md
Last active October 20, 2017 14:22
Test Performance using iperf

Server VM:

sudo apt-get install iperf
iperf -s

Client VM

sudo apt-get install iperf
iperf -c
@nordineb
nordineb / IMDSSample.cs
Last active October 20, 2017 13:18
cloud-powershell
namespace Samples
{
using System;
using System.Net.Http;
class IMDSSample
{
// Query IMDS server and retrieve JSON result
private static string JsonQueryIMDS(string path)
{
const string api_version = "2017-04-02";
@nordineb
nordineb / P2Scertificates.ps1
Created October 24, 2017 19:17
Create p2S certificates
# if you already have a root certificate
$cert= Get-ChildItem -Path “Cert:\CurrentUser\My” | where { $_.subject -eq "CN=NordineRootCertForP2SVPN" }
# otherwise create a self-signed root certificate
$cert = New-SelfSignedCertificate -Type Custom -KeySpec Signature `
-Subject "CN=RootCertForP2SVPN" -KeyExportPolicy Exportable `
-HashAlgorithm sha256 -KeyLength 2048 `
-CertStoreLocation "Cert:\CurrentUser\My" -KeyUsageProperty Sign -KeyUsage CertSign
@nordineb
nordineb / ninject.cs
Created October 26, 2017 10:34
Ninject tips
var kernel = <The_Kernel>
FieldInfo bindingCacheFieldInfo = typeof(KernelBase).GetField("bindingCache", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic);
ICollection<Type> cachedBindingTypes = ((Multimap<Type, IBinding>)bindingCacheFieldInfo.GetValue(kernel)).Keys;
FieldInfo bindingFieldInfo = typeof(KernelBase).GetField("bindings", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic);
ICollection<Type> bindingTypes = ((Multimap<Type, IBinding>)bindingFieldInfo.GetValue(kernel)).Keys;
List<Type> nonActivatedTypes = bindingTypes.Except(cachedBindingTypes).ToList();
public override void Load()
{
@nordineb
nordineb / Get-AzureRmCachedAccessToken.ps1
Created October 26, 2017 10:50
AccessToken (Bearer) from an existing Azure PowerShell session
function Get-AzureRmCachedAccessToken()
{
$ErrorActionPreference = 'Stop'
if(-not (Get-Module AzureRm.Profile)) {
Import-Module AzureRm.Profile
}
$azureRmProfileModuleVersion = (Get-Module AzureRm.Profile).Version
# refactoring performed in AzureRm.Profile v3.0 or later
if($azureRmProfileModuleVersion.Major -ge 3) {
@nordineb
nordineb / DeleteAspNetTempfiles.ps1
Last active May 15, 2022 07:50
DeleteAspNetTempfiles.ps1
Remove-Item "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\*" -ErrorAction SilentlyContinue -Force -Recurse 2>&1 | out-null
Remove-Item "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\*" -ErrorAction SilentlyContinue -Force -Recurse 2>&1 | out-null