This file contains 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
// 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] |
This file contains 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
# 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() |
This file contains 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
// intended to be called only ONCE in real installations - or for a clean test run when no Jobs container exists | |
public static void GloballyInitializeJobManager(bool quiet) | |
{ | |
var blobContainer = AzureStorageAccess.GetBlobContainer(JobContainerName); | |
bool didNotExistCreated = blobContainer.CreateIfNotExist(); | |
if (!quiet) System.Diagnostics.Debug.Assert(didNotExistCreated); // else, we probably should not be calling this method | |
var blob = blobContainer.GetBlobReference(JobGlobalJobIdSequencePath); | |
if (!blob.Exists()) | |
{ | |
blob.UploadText(JobGlobalJobIdSequenceStartingValue); |
This file contains 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
using System.IO; | |
using System.Runtime.Serialization.Formatters.Binary; | |
// Alternative (not related to this code, but in case you want to serialize to XML | |
// instead): http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/5d08bc28-5b61-4c5a-8c4b-4665b1c929ea/ | |
// Usage example | |
// NOTE: The Windows Azure CloudQueueMessage constructor accepts either a string | |
// or a byte array. If a byte array is passed in, it is Base64 encoded. | |
// Base64 encoding results in approx a 1/3 payload size penalty (so the |
This file contains 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
-- 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/', |
This file contains 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
# Bill Wilder (@codingoutloud), 02-Oct-2013 | |
# Original: https://gist.github.com/codingoutloud/6800434 | |
import datetime | |
def ticks_since_epoch(start_time_override = None): | |
""" | |
Calculates number of Ticks since Jan 1, 0001 epoch. Uses current time unless another time is supplied. | |
Mimics behavior of System.DateTime.UtcNow.Ticks from.NET with 10 million Ticks per second. | |
http://msdn.microsoft.com/en-us/library/system.datetime.ticks.aspx | |
@return: Number of Ticks since Jan 1, 0001 epoch (earliest date supported by Python datetime feature) |
This file contains 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
#r "Newtonsoft.Json" | |
using System.Net; | |
using System.Text; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
#r "Newtonsoft.Json" | |
using System.Net; |
This file contains 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
#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; |
This file contains 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
# 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 | |
} |
This file contains 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
git add --all | |
git commit --all -m "Update" | |
git push |