Skip to content

Instantly share code, notes, and snippets.

Frank Hu frankhu1234

Block or report user

Report or block frankhu1234

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
frankhu1234 /
Last active Apr 24, 2019
Update PHP version for Ubuntu Machines with Apache2
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2
sudo apt-get install php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-mysql php7.2-mbstring php7.2-mcrypt php7.2-zip php7.2-fpm
sudo a2dismod <old-php-version>
sudo a2enmod php7.2
sudo service apache2 restart
frankhu1234 / Get All AAD Policies for SP
Created Mar 14, 2019
This gist is a powershell script utilizing AzureAD Preview to get the claims mapping policies for a service principal.
View Get All AAD Policies for SP
Import-Module "AzureADPreview"
$appID = "...guid-of-the-AppID..."
$sp = Get-AzureADServicePrincipal -Filter "servicePrincipalNames/any(n: n eq '$appID')"
$existingPolicies = Get-AzureADServicePrincipalPolicy -Id $sp.ObjectId `
| Where-Object { $_.Type -eq "ClaimsMappingPolicy" }
View AAD V2 Powershell Script to Get Roles for Service Principal via App Name
$appname = "Your-App-Registration-Name"
$sp = Get-AzureADServicePrincipal -filter "DisplayName eq '$appname'"
$role = Get-AzureADDirectoryRole
For ($i=0; $i -lt $role.Count; $i++){
View Get Roles for AAD Service Principal via AAD V2 Powershell Using ObjectID
$SPObjectID = "your-spn-objectid"
$role = (Get-AzureADDirectoryRole).objectId
For ($i=0; $i -lt $role.Count; $i++){
if(Get-AzureADDirectoryRoleMember -ObjectId $role.Get($i) | where {$_.objectId -eq $SPObjectID}) {
View Regex for Phone numbers
1. xxx-xxx-xxxx grep -o '[0-9]\{3\}\-[0-9]\{3\}\-[0-9]\{4\}' file.txt
2. (xxx)xxx-xxxx grep -o '([0-9]\{3\})[0-9]\{3\}\-[0-9]\{4\}' file.txt
3. xxx xxx xxxx grep -o '[0-9]\{3\}\s[0-9]\{3\}\s[0-9]\{4\}' file.txt
4. xxxxxxxxxx grep -o '[0-9]\{10\}' file.txt
grep -o '\([0-9]\{3\}\-[0-9]\{3\}\-[0-9]\{4\}\)\|\(([0-9]\{3\})[0-9]\{3\}\-[0-9]\{4\}\)\|\([0-9]\{10\}\)\|\([0-9]\{3\}\s[0-9]\{3\}\s[0-9]\{4\}\)' file.txt
- Found online, and put on my git for reference.
Credit goes to Raullen Chai
frankhu1234 / CreateRandomUsers
Created Nov 4, 2018
This method will create users for a test tenant in order to test paging, or if you're trying to do some sort of testing.
View CreateRandomUsers
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System.Net.Http.Headers;
using System.Net.Http;
static async Task createRandomUsers()
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
Console.WriteLine("\n \n Creating users {0}", DateTime.Now.ToString());
for(int index = 0;index < 10; ++index)
frankhu1234 / MSFTGraphSDKGetUsers
Last active Jan 1, 2019
MicroosftGraphSDK Get Users
View MSFTGraphSDKGetUsers
using Microsoft.Graph;
static async Task getUsersUsingGraphServiceClient()
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
return Task.FromResult(0);
frankhu1234 / AcquireAccessToken
Created Nov 4, 2018
Get the access token using ADAL .net library using an interactive login flow
View AcquireAccessToken
using Microsoft.IdentityModel.Clients.ActiveDirectory;
static async Task getAccessToken()
int retryCount = 0;
bool retry = false;
authContext = new AuthenticationContext(authority + tenantID);
retry = false;
View MainMethod for .net tutorial
static void Main(string[] args)
// GetMembers utilizes HTTP Client, will print JSON Prettified in method
Console.WriteLine("\n Press Enter to exit the program \n");
frankhu1234 / PrettifyJWT
Last active Nov 4, 2018
Prettify JWT token to be readable
View PrettifyJWT
using System.IdentityModel.Tokens.Jwt;
static async Task prettyJWTPrint(String myToken)
//Assume the input is in a control called txtJwtIn,
//and the output will be placed in a control called txtJwtOut
var jwtHandler = new JwtSecurityTokenHandler();
var jwtInput = myToken;
String prettyPrint = "";
You can’t perform that action at this time.