Skip to content

Instantly share code, notes, and snippets.

@JFFail
JFFail / quarantine_days.sh
Last active Jul 30, 2020
Simple Bash script to calculate the number of days in quarantine.
View quarantine_days.sh
#!/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 Jun 5, 2020
Get a Date object at a specified Date and Time as an ISO formatted string in UTC
View monthStartUTC.groovy
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
Simple chessboard-generating script from Eloquent JavaScript Chapter 2.
View chessboard.js
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 Apr 28, 2020
Parses a monthly PSTN usage report from Office 365 to report on the minutes consumed per destination phone number for dial-out.
View parse_pstn_usage.py
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 Jun 1, 2019
Sample of getting required properties from an AD object and storing a multi-value attribute properly in a .csv file.
View Export-ADContacts.ps1
# 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 Apr 30, 2016
Example of how to overload operators with classes in PowerShell.
View NumberClass.ps1
class Number {
[int] $value = 0
Number() {
#Does nothing.
}
Number([int]$somethingElse) {
$this.value = $somethingElse
}
@JFFail
JFFail / GarageDoor.cs
Created Apr 26, 2016
Reddit Daily Programmer #260 - Garage Door Opener
View GarageDoor.cs
//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 Mar 2, 2016
Solution To Reddit Daily Programmer #255 - Playing With Light
View change-lightswitch.ps1
#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 Feb 16, 2016
Silly script to figure out where state employees will go to lunch based on whether or not it's pay day!
View state-employee.ps1
#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 Feb 10, 2016
VBScript for the laziest possible way to continuously re-run your last command in a shell.
View up_arrow.vbs
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
You can’t perform that action at this time.