Skip to content

Instantly share code, notes, and snippets.

View neverendingqs's full-sized avatar

Mark Tse neverendingqs

View GitHub Profile
@neverendingqs
neverendingqs / Git-RemovedMergedBranches.ps1
Created September 7, 2015 16:06
Delete all local branches that has been merged on remote.
# Can also add to PowerShell profile
function Git-RemovedMergedBranches {
git branch --merged |
? { $_ -NotMatch "^\*" } |
? { $_ -NotMatch "master" } |
% { $_.Trim() } |
% { git branch -d $_ }
}
#n::Run "C:\Program Files (x86)\Notepad++\notepad++.exe"
#c::Run "C:\Program Files\ConEmu\ConEmu64.exe"
#v:: ; Text–only paste from ClipBoard
Clip0 = %ClipBoardAll%
ClipBoard = %ClipBoard% ; Convert to text
Send ^v ; For best compatibility: SendPlay
Sleep 50 ; Don't change clipboard while it is pasted! (Sleep > 0)
ClipBoard = %Clip0% ; Restore original ClipBoard
VarSetCapacity(Clip0, 0) ; Free memory
D2LAppContextFactory appContextFactory = new D2LAppContextFactory();
ID2LAppContext appContext = appContextFactory.Create(appId, appKey);
UserContextProperties userContextProperties = new UserContextProperties() {
UserId = myUserId, // put your user ID here
UserKey = myUserKey, // put your user key here
Scheme = "https",
HostName = bsUrl,
Port = port
};
+-----------------+ +-----------------+ +-----------------+
| | | | | |
| Sample App | | User / Browser | | Auth Server |
| | | | | |
+--------+--------+ +--------+--------+ +--------+--------+
| | |
| | |
| GET /auth | |
| <-----------------------------
@neverendingqs
neverendingqs / brightspace-oauth2-whoami.py
Last active November 23, 2016 16:40
Brightspace "whoami" using OAuth 2.0 access token
import requests # requests==2.7.0
url = "http://localhost:44453/d2l/api/lp/1.0/users/whoami"
access_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjBiOWU5Njg2LWRiYTctNDBkNS05MmRlLTYxNmVkNmYzZmJhMSJ9.eyJzdWIiOiIxNjkiLCJ0ZW5hbnRpZCI6IjNlZGE2ZTJhLWNmZjItNGE0OS1hZjQ5LWY4MmUzZWUzZTkxMSIsInNjb3BlIjoiY29yZToqOioiLCJqdGkiOiJlNDI0YjQyZi1hZTY5LTQ4ZGItYWUzMS00ZjhlZTQ1NDBkNmEiLCJpc3MiOiJodHRwczovL2FwaS5icmlnaHRzcGFjZS5jb20vYXV0aCIsImF1ZCI6Imh0dHBzOi8vYXBpLmJyaWdodHNwYWNlLmNvbS9hdXRoL3Rva2VuIiwiZXhwIjoxNDc5OTIxMTUxLCJuYmYiOjE0Nzk5MTc1NTF9.GznF7Wl-DQxJ3Qp7OPJ4PU_nhHzCzaHYcAFlgahLXyBhAqqAQWKYcrID8UB478iwL2ntYPCtJKLCsJp-ZzZ4QMNc0rwFSJ6_jpQ9W3ALYgIBhILuabG-Xkfdnv4Bi-ME4Q1RcNUvNuuP7ygaJtONc7S4hJtYagsmI9JOW46h-64nevDLijO4CJOIq9B27k_PjPzisAET0ziUD6swIvhX7rUz_nOmCWZJDP56Mi-LIMSd7GrTYP9dTnwvw_rmU_iliO8iOqSKtPaaYUBF9gK4Zulg93nNZDybZozM9sxlfvdRrnjDq6PPUCIbyG1zFwD3GH7-bE9HlemSElhuxyMqSg"
response = requests.get(url, headers={'authorization': "Bearer {}".format(access_token)})
print(response.json())
Dim client As New RestSharp.RestClient("https://auth.brightspace.com/core/connect/token")
' Must use basic auth
client.Authenticator = new HttpBasicAuthenticator("(client id)", "(client secret)");
Dim req As New RestSharp.RestRequest(Method.POST)
req.AddHeader("Content-Type", "application/x-www-form-urlencoded")
req.AddHeader("Accept", "application/json")
req.AddParameter("grant_type", "refresh_token")
req.AddParameter("refresh_token", "(manually obtained refresh token)")
req.AddParameter("scope", "Application:*:* Core:*:* Data:*:*")
@neverendingqs
neverendingqs / s3-no-delete-policy.json
Last active April 9, 2017 20:29
S3 No Delete Bucket Policy
{
"Id": "a3769712-3b2a-47e8-8206-85cdaf882384",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "NoDelete",
"Action": [
"s3:Delete*",
"s3:PutBucketPolicy"
],
@neverendingqs
neverendingqs / LICENSE
Last active September 3, 2017 22:34
Batching (Native) Promise calls in serial
MIT License
Copyright (c) 2017 Mark Tse
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@neverendingqs
neverendingqs / git-perms-change-windows.txt
Created January 12, 2018 16:26
Changing file permissions in Git on Windows
# Taken from http://blog.lesc.se/2011/11/how-to-change-file-premissions-in-git.html on January 12, 2018
>git ls-tree HEAD
100644 blob 55c0287d4ef21f15b97eb1f107451b88b479bffe script.sh
>git update-index --chmod=+x script.sh
>git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
@neverendingqs
neverendingqs / example.json
Last active August 17, 2018 01:35
2017/09/24/aws-lambda-notprincipal - example.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyObjectDeleteWithWhitelist",
"Effect": "Deny",
"NotPrincipal": {
"AWS": [
"arn:aws:iam::123456789012:role/SuperRoleOne",
"arn:aws:iam::123456789012:role/SuperRoleTwo"