Skip to content

Instantly share code, notes, and snippets.

@JFFail
JFFail / quarantine_days.sh
Last active July 30, 2020 21:12
Simple Bash script to calculate the number of days in quarantine.
#!/bin/bash
# Print help if it was requested.
if [[ $1 == "-h" || $1 == "-?" ]]; then
printf "quarantine_days - Provide a date in the format of YYYY/MM/DD\n"
printf "\tIf the date is valid, the number of days in quarantine will be printed.\n"
printf "\tNon-valid dates will cause the script to exit.\n"
exit
fi
# Make sure something was passed.
@JFFail
JFFail / monthStartUTC.groovy
Created June 5, 2020 20:39
Get a Date object at a specified Date and Time as an ISO formatted string in UTC
TimeZone.setDefault(TimeZone.getTimeZone('UTC'))
Integer year = Calendar.getInstance().get(Calendar.YEAR)
Integer month = Calendar.getInstance().get(Calendar.MONTH)
def then = new GregorianCalendar(year, month, 1, 0, 0, 0).time
// Desired format: 2020-06-01T00:00:00.000000+00:00
thenISO = then.format("yyyy-MM-dd'T'HH:mm:ss.SSSZ", TimeZone.getTimeZone("UTC"))
thenISOFixed = thenISO[0..thenISO.length() - 3] + ":00"
println thenISOFixed
@JFFail
JFFail / chessboard.js
Created May 11, 2020 23:59
Simple chessboard-generating script from Eloquent JavaScript Chapter 2.
var size = 15, base = "";
for(var i = 1; i <= size; i++) {
if(i % 2 === 1) {
for(var k = 1; k <= size; k++) {
if(k % 2 === 1) {
base += "#";
} else {
base += " ";
}
@JFFail
JFFail / parse_pstn_usage.py
Created April 28, 2020 22:34
Parses a monthly PSTN usage report from Office 365 to report on the minutes consumed per destination phone number for dial-out.
import csv
usage_tracker = {}
report_file = "./pstn_report.csv"
with open(report_file, "r", newline="") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
@JFFail
JFFail / Export-ADContacts.ps1
Created June 1, 2019 21:03
Sample of getting required properties from an AD object and storing a multi-value attribute properly in a .csv file.
# Get the objects with the required attributes and storing proxyAddresses properly in the .csv file.
Get-ADObject -Filter { objectClass -eq "contact" } -Server myserver.mydomain.net -SearchBase "OU=Contacts,DC=mydomain,DC=net" -SearchScope OneLevel -Properties name,givenName,sn,displayName,telephoneNumber,proxyAddresses,targetAddress,mail,mailNickname,company,department,l,physicalDeliveryOfficeName,postalCode,st,streetAddress,title | Select-Object name,givenName,sn,displayName,telephoneNumber,targetAddress,mail,mailNickname,company,department,l,physicalDeliveryOfficeName,postalCode,st,streetAddress,title,@{name="proxyAddresses"; expression={$_.proxyAddresses -join ";"}} | Export-Csv -Path .\sample.csv -Encoding ASCII -Append -NoClobber -NoTypeInformation
# Shows how to then use the proxyAddresses attribute in the future.
$allContacts = Import-Csv -Path .\sample.csv
foreach($singleContact in $allContacts) {
$proxyAddresses = $singleContact.proxyAddresses.Split(";")
}
@JFFail
JFFail / NumberClass.ps1
Created April 30, 2016 13:55
Example of how to overload operators with classes in PowerShell.
class Number {
[int] $value = 0
Number() {
#Does nothing.
}
Number([int]$somethingElse) {
$this.value = $somethingElse
}
@JFFail
JFFail / GarageDoor.cs
Created April 26, 2016 00:18
Reddit Daily Programmer #260 - Garage Door Opener
//Reddit Daily Programmer #260 - Easy
//https://www.reddit.com/r/dailyprogrammer/comments/4cb7eh/20160328_challenge_260_easy_garage_door_opener/
using System;
namespace DoorOpener
{
class DoorOpener
{
//Create an enumerated set for my sanity in figuring the state of the door.
enum DoorState { open, closed, opening, closing, stoppedOpening, stoppedClosing, emergencyOpening, openBlocked };
@JFFail
JFFail / change-lightswitch.ps1
Created March 2, 2016 20:17
Solution To Reddit Daily Programmer #255 - Playing With Light
#https://www.reddit.com/r/dailyprogrammer/comments/46zm8m/20160222_challenge_255_easy_playing_with_light/
#Function for flipping the switches.
function FlipSwitch ($Array,$Position)
{
$currentBoolean = $Array[$Position]
if($currentBoolean)
{
$newValue = $false
}
@JFFail
JFFail / state-employee.ps1
Created February 16, 2016 02:13
Silly script to figure out where state employees will go to lunch based on whether or not it's pay day!
#Making a class for where state employees go for lunch. This does NOT account for holidays affecting when you get paid.
class StateEmployee
{
#Base properties.
[string] $firstName = ""
[string] $lastName = ""
[bool] $payDay = $false
#Default empty constructor. Seriously, don't use this.
StateEmployee()
@JFFail
JFFail / up_arrow.vbs
Created February 10, 2016 20:41
VBScript for the laziest possible way to continuously re-run your last command in a shell.
Option Explicit
Dim objShell
set objShell = CreateObject("WScript.Shell")
While true
objShell.AppActivate("powershell")
objShell.SendKeys "{Up}"
WScript.Sleep 200
objShell.SendKeys "{Enter}"
WScript.Sleep 5000
Wend