Skip to content

Instantly share code, notes, and snippets.

Avatar

Bill Wilder codingoutloud

View GitHub Profile
@codingoutloud
codingoutloud / getRandomInt.js
Created Aug 30, 2020
JavaScript functions for choosing a random integer between 0 and some max value. There are two variants: one where max is supplied, and one where an array is supplied.
View getRandomInt.js
// Return a random integer in [0..max] (inclusive, so 0 and max are valid values).
// Assumes (but does not validate) that max is a non-negative integer less than Number.MAX_SAFE_INTEGER.
// Does not use a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG).
function getRandomInt(max) {
return Math.floor(Math.random() * (max + 1));
// How it works:
// Math.random() → returns a floating point number at least zero but less than one: [0..1)
// Math.random() * (max+1) → returns a floating point number at least 0 but less than (max+1): [0..max+1)
// floor(Math.random() * (max+1)) → returns an integer at least 0 but could be as high as max: [0..max]
@codingoutloud
codingoutloud / myip.py
Created Feb 2, 2020
Command line to get my public IP address by leveraging handy feature in OpenDNS
View myip.py
# OpenDNS resolves "myip.opendns.com" to the caller's publicly-facing IP.
# To use this feature, resolve that DNS name against an OpenDNS name server.
# https://github.com/rthalley/dnspython
# pip install dnspython
import dns.resolver
resolver = dns.resolver.Resolver()
View check-azure-sql-db-logins.sql
-- Turn on Audit Logging to Blob for your Azure SQL Database. Then you can query who has logged in.
-- The example below assumes DB Server-level audit logging. Details will vary slightly for Database-level audit logging.
-- The example below shows who logged in so far today.
-- Change "-0" to "-1" to look at yesterday (from a UTC perspective, not your local timezone).
-- Change "-0" to "-100" to look at 100 days ago.
SELECT FORMATMESSAGE('%s (%s)', CAST(DATEADD(day, -0, CONVERT(date, SYSUTCDATETIME())) as varchar),
DATENAME(WEEKDAY, DATEADD(day, -0, SYSUTCDATETIME()))),
server_principal_name,
COUNT(server_principal_name) as 'Logins'
FROM sys.fn_get_audit_file(FORMATMESSAGE('https://<MYBLOB>.blob.core.windows.net/sqldbauditlogs/<MYDBSERVER>/<MYDB>/SqlDbAuditing_ServerAudit/%s/'
View ReportBlockedByCSP
#r "Newtonsoft.Json"
using System.Net;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
#r "Newtonsoft.Json"
using System.Net;
@codingoutloud
codingoutloud / run.csx
Created Mar 25, 2018
Get User Agent Summary from within an Azure Function using whatismybrowser.com API
View run.csx
#r "Newtonsoft.Json"
using System.Net;
using System.Net.Http;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@codingoutloud
codingoutloud / IpTools.psm1
Created Jan 29, 2018
PowerShell module for IP address tools
View IpTools.psm1
# put this in some shared module folder, such as /usr/local/share/powershell/Modules
Function Get-IpCountry {
param([String]$ip="9.9.9.9")
$country = Invoke-RestMethod -Method GET -Uri https://ipinfo.io/$ip/country
return $country
}
@codingoutloud
codingoutloud / gitpush.ps1
Last active Dec 1, 2017
Simple mode to continually push from a remote machine to a git repo
View gitpush.ps1
git add --all
git commit --all -m "Update"
git push
@codingoutloud
codingoutloud / Publish-CertFromKeyVaultToWebApp.ps1
Created Nov 21, 2017
Get an SSL Cert from Key Vault and push it to a Web App
View Publish-CertFromKeyVaultToWebApp.ps1
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionName AzureFAQ # subscription where the Web App resides
$webAppName = "pageofphotos" # Web App resource Name, (Get-AzureRmWebApp)[0].Name
$fqdn = "pageofphotos.com" # what is the DNS address? could be admin.pageofphotos.com if that's what's mapped
$vaultName = "GlobalOpsVault"
$certificateName = "MySSL"
$passwordLength = 50
@codingoutloud
codingoutloud / AzureFunctionRandomQuote.js
Created Sep 14, 2017
Simple "hello world"-level web page intended for use with Azure Functions - paste this text into a JavaScript HTTP trigger, upload project.json to kudu, and set up MOVIE_API_KEY as an environment variable.
View AzureFunctionRandomQuote.js
var request = require('request');
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
var html = "<html><body><h1>didn't work</h1></body></html>"
var movieApiUrl = 'https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies&count=10';
// go get your own API key: https://market.mashape.com/andruxnet/random-famous-quotes#get-endpoint
var movieApiKey = process.env['MOVIE_API_KEY'];
// context.log('MOVIE API KEY = ' + movieApiKey);
@codingoutloud
codingoutloud / http-get-repeatedly.sh
Created Sep 7, 2017
Usage: http-get-repeatedly.sh [number of times to repeat] -- no param means once.
View http-get-repeatedly.sh
#!/bin/bash
URL="https://prod-24.southcentralus.logic.azure.com:443/workflows/62d71dadbb0b451bb8de9f27c9e51f93/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=8HpJbLEcF078jtVgBZoMpWA65sZDI8_nowFVINX8HK0"
for i in `seq 1 $1`;
do
echo $i
curl "$URL"
done
You can’t perform that action at this time.