This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (* ::Package:: *) | |
| (* ::Input:: *) | |
| (*a={0,0,0}*) | |
| (*b={1,0,0}*) | |
| (*c={1,1,0}*) | |
| (*d={0,1,0}*) | |
| (*e={0,0,1}*) | |
| (*f={1,0,1}*) | |
| (*g={1,1,1}*) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-XKCDComic { param ($n,$file); $h="https:"; iwr "$h$(((iwr "$h//xkcd.com/$n").images)[1].src)" -out $file } # Saves XKCD #n to a file | |
| function Get-XKCDCurrentIssueNo { (iwr "https://xkcd.com").RawContent -match "Permanent link to this comic: https://xkcd.com/(?<N>\d+)" | Out-Null; return [int]$matches["N"] } | |
| # Running Project Oxford APIs | |
| # Inspired by https://jamessdixon.wordpress.com/2016/12/25/age-and-sex-analysis-of-microsoft-usa-mvps/ | |
| # In Powershell | |
| # Get Subscription key at https://www.microsoft.com/cognitive-services/en-US/subscriptions | |
| #Modifying for XKCD recognition |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Runs in Julia 0.6.2. For Julia 1.0 code, refer to my Julia-Playground repo | |
| # Also, implementation of the bracket matching code isawful. What was I thinking about? | |
| bfcode = ", [ > + < - ] > ." | |
| cells = [0 for i=1:30000] | |
| bfcode = replace(bfcode, r"[^\+\-\<\>\.\,\[\]]", "") # Eliminating all extranious characters in the code | |
| # Initial processing: identifying pairs of [ and ], and populating two arrays with indexes (positions of the brackets in the bf code) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # JWT signature verification | |
| # $jwt should contain the JWT as a string | |
| $parts = $jwt.Split('.') | |
| $SHA256 = New-Object Security.Cryptography.SHA256Managed | |
| $computed = $SHA256.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($parts[0]+"."+$parts[1])) | |
| # Method A - just using X509Certificate2. TODO: initialise from file, no private key | |
| # Reference: https://blogs.msdn.microsoft.com/alejacma/2008/06/25/how-to-sign-and-verify-the-signature-with-net-and-a-certificate-c/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function Get-GroupChanges { | |
| Param( | |
| $group = "Domain Admins", | |
| $server = (Get-ADDomainController).HostName, | |
| $hours = 4 | |
| ) | |
| $adgroupobject = Get-ADGroup $group | |
| $memberchanges = Get-ADReplicationAttributeMetadata -Object $adgroupobject.DistinguishedName -Server $server -ShowAllLinkedValues | ? AttributeName -eq "Member" | ? LastOriginatingChangeTime -gt (Get-Date).AddHours(-1 * $Hours) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $jsontemplate = @' | |
| { | |
| "requests":[ | |
| { | |
| "image":{ | |
| "content":"/9j/7QBEUGhvdG9...image contents...eYxxxzj/Coa6Bax//Z" | |
| }, | |
| "features":[ | |
| { | |
| "type":"LABEL_DETECTION", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function New-Sparkbar { | |
| param ( | |
| $numbers | |
| ) | |
| $bars = "▁","▂","▃","▄","▅","▆","▇","█" | |
| $max = ($numbers | Measure-Object -Maximum).Maximum | |
| $min = ($numbers | Measure-Object -Minimum).Minimum | |
| $span = $max - $min | |
| $out = "" | |
| foreach ($n in $numbers) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This code relies on gcloud present in the path and authenticated with permissions to read folders | |
| # The output is Terraform HCL code in the .tf file and shell code to import the discovered resources in the .sh file | |
| # Similar approach can be used to survey other type of resources | |
| gcloud organizations list --format='json' | ConvertFrom-JSON -OutVariable org | |
| if (!$?) { throw "Error invoking gcloud" } # Rudimentary error handling - throw terminating error if gcloud errors out in any way | |
| $seed = $org.name.split("/")[1] | |
| $folders = @() # Starting with empty array, to be populated with org-level folders |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Setting default parameters for irm for better error tolerance in case of transient connectivity issues. Can specify Proxy and ProxyCredential here: | |
| $PSDefaultParameterValues = @{ | |
| "Invoke-RestMethod:MaximumRetryCount" = 3 | |
| "Invoke-RestMethod:RetryIntervalSec" = 1 | |
| } | |
| # This is simple token request per http://codematters.tech/getting-access-token-for-microsoft-graph-using-oauth-rest-api/ | |
| # Credentials JSON per ADAL example at https://github.com/AzureAD/azure-activedirectory-library-for-python/blob/dev/sample/client_credentials_sample.py |
OlderNewer