Skip to content

Instantly share code, notes, and snippets.

View SP3269's full-sized avatar

Svyatoslav Pidgorny SP3269

View GitHub Profile
@SP3269
SP3269 / dodeca.m
Created September 16, 2017 23:31
Visualising rhombic dodecahedron in Wolfram Mathematica
(* ::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}*)
@SP3269
SP3269 / Read-XKCD.ps1
Created December 10, 2017 07:43
This Powershell code fetches XKCD comics and submits to Microsoft Cognitive Services Vision API for handwritten text recognition, creating XKCD text dataset
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
@SP3269
SP3269 / GoogleVisionAPI.ps1
Last active March 25, 2018 23:47
This is an example of using JSON template for Google API calls in Powershell. The JSON template is direct copy/paste from Google documentation. The script reads image file, modifies the JSON and submits the request to the API.
$jsontemplate = @'
{
"requests":[
{
"image":{
"content":"/9j/7QBEUGhvdG9...image contents...eYxxxzj/Coa6Bax//Z"
},
"features":[
{
"type":"LABEL_DETECTION",
@SP3269
SP3269 / ADGroupChanges.ps1
Last active April 11, 2018 04:17
Detecting Active Directory group changes based on AD metadata. In addition, the account making the change is found from Windows event on originating DC (assumptions apply)
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)
@SP3269
SP3269 / Prepare-TerraformImport.ps1
Created September 12, 2018 01:28
This is PowerShell code that is using Google Cloud Platform SDK's gcloud to read the organization's folders, iterates through the folder hierarchy, and generates Terraform HCL code and shell script for import to Terraform state.
# 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
@SP3269
SP3269 / bf.jl
Last active September 30, 2018 04:02
Brainfuck implementation in Julia
# 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)
@SP3269
SP3269 / H-R.m
Created March 17, 2019 05:14
Constructing and training simple neural networks in Wolfram Mathematica
(* ::Package:: *)
(* ::Text:: *)
(*First, let's take a look at the data for the Hertzsprung-Russell diagram. Following example from https://mathematica.stackexchange.com/questions/125681/how-can-i-plot-the-h-r-diagram-of-stars*)
(**)
(* ::Input:: *)
(*stardata=SemanticImport["/home/pi/g3.csv"]*)
@SP3269
SP3269 / RunGBigQuery.ps1
Created May 3, 2019 05:39
This PowerShell script is using Google BigQuery REST API to run a query and creates a result set using returned schema for field names and types
$project = "your-gcp-project"
$accesstoken = gcloud auth print-access-token # Lazy way. Can also get access token using service account and 2LO - ref. https://gist.github.com/SP3269/da43b00692de5b3f591b3068d76df577
# Using Google BigQuery REST API per https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query
# Example query using public dataset available to anyone in BQ
$query = 'SELECT * FROM `bigquery-public-data.san_francisco_trees.street_trees` WHERE plant_date >= "1969-01-01 00:00:00 UTC" AND plant_date < "1970-01-01 00:00:00 UTC"'
$body = @{
useLegacySql = "false"
@SP3269
SP3269 / DiceRolls.ps1
Created March 6, 2020 23:37
Simple statistical look at the dice rolls in game of Catan using PowerShell 7
$game20200305 = @'
44
61
65
63
41
45
22
63
23
// A Web server with two endpoints - /stable (returning 200) and /unstable (going into failing state with defined probability every tick and returning 500 while in it)
// Based on Googles slo-burn code https://github.com/google/prometheus-slo-burn-example/tree/master/server
package main
import (
"fmt"
"math/rand"
"net/http"
"os"