Skip to content

Instantly share code, notes, and snippets.

Avatar

Jim Caten quonic

View GitHub Profile
@quonic
quonic / Get-LastestPowershellCoreMSI.ps1
Created Mar 4, 2020
Checks if the current running Powershell Core environment is the latest version and download if it isn't
View Get-LastestPowershellCoreMSI.ps1
[Version]$ReleaseVersion = (Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json).ReleaseTag -replace '^v'
if ($PSVersionTable.PSEdition -like "Core" -and $ReleaseVersion -gt $PSVersionTable.PSVersion) {
$latest = Invoke-RestMethod -Uri "https://api.github.com/repos/PowerShell/PowerShell/releases" | Where-Object { $_.tag_name -eq "v$ReleaseVersion" }
$downloadUrl = $latest.assets | Where-Object Name -like "*win-x64.msi" | Select-Object -ExpandProperty 'browser_download_url'
Invoke-WebRequest -Uri $downloadUrl -OutFile "$PSScriptRoot\$(Split-Path $downloadUrl -Leaf)"
}
@quonic
quonic / static.py
Created Jul 2, 2019
Example of static screen at about 4 fps on a ryzen 7 1800X.
View static.py
import sys
import random
# import math
from itertools import *
import numpy as np
import pygame
# from past.builtins import xrange
from profilehooks import profile
@quonic
quonic / autotask_update_exchange_rates.py
Last active Apr 25, 2019
Untested: This should update the exchange rates of the Currency entities. Does require an AutoTask account to have access to multi-currencies.
View autotask_update_exchange_rates.py
# MIT license
# Created by Quonic on 4/23/2019
import atws
import getpass
import pprint
import keyring
import requests
def save_creds(creds_username, creds_password):
@quonic
quonic / ADSync.ps1
Created Apr 8, 2019
Untested: This will sync AD on all Domain Controllers
View ADSync.ps1
Function Sync-AD {
Param(
[Credential]
$Credential=$(Get-Credential)
)
$splatme = @{
ComputerName = Get-ADDomainController -Filter {Name -like "*"}
ScriptBlock = {
Import-Module -Name 'ADSync'
Start-ADSyncSyncCycle -PolicyType Delta
@quonic
quonic / install-autoupgrade.sh
Created Mar 3, 2019
This add an auto upgrade to cron for debian/ubuntu
View install-autoupgrade.sh
crontab -l > mycron
echo "0 2 * * * apt-get update" >> mycron
echo "0 3 * * * apt-get -y dist-upgrade" >> mycron
echo "0 4 * * * apt-get -y upgrade" >> mycron
crontab mycron
rm mycron
@quonic
quonic / Rename-DiscordCacheImagesToExt
Created Feb 14, 2019
Some example code to rename discord cached images
View Rename-DiscordCacheImagesToExt
# Function to figure out what the file type is
function Get-ImageExt {
[CmdletBinding()]
# [OutputType([System.Boolean])]
param(
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[Alias('PSPath')]
[string] $Path
)
@quonic
quonic / Powerpoint.ps1
Created Jan 22, 2019
Sample of how to create a PowePoint slide and get the text of a shape
View Powerpoint.ps1
$Application = New-Object -ComObject PowerPoint.Application
# Make PowerPoint visible during debug
$Application.Visible = [Microsoft.Office.Core.MsoTriState]::msoTrue
# Create a new presentation
$Application.Presentations.Add([Microsoft.Office.Core.MsoTriState]::msoTrue)
# Add a slide
# Yes... index starts at 1...
$Application.Presentations[1].Slides.Add(1,1)
# Get the text of the first shape in the first slide
$Application.Presentations[1].Slides[1].Shapes[1].TextFrame2.TextRange.Text
@quonic
quonic / ConvertTo-Bits.ps1
Last active Jan 4, 2019
ConvertTo-Bits converts any string, number or an array of numbers to a bit array object
View ConvertTo-Bits.ps1
function ConvertTo-Bits {
<#
.SYNOPSIS
This converts any string, number or an array of numbers to a bit array object
.DESCRIPTION
This converts any string, number or an array of numbers to a bit array object
.PARAMETER InputObject
Accepts any object, but String or Number is expected
@quonic
quonic / ConvertTo-UnixTime.ps1
Last active Apr 18, 2019
Created this to help convert UNIX time to and from Windows time when interfacing with data from API's that output time in UNIX time.
View ConvertTo-UnixTime.ps1
function ConvertTo-UnixTime {
[OutputType([int64])]
Param(
# Date in UNIX time
[Parameter(Mandatory,
ValueFromPipeline=$true)]
[DateTime]
$DateTime
)
[Math]::Floor([decimal](Get-Date($DateTime).ToUniversalTime() -UFormat "%s"))
@quonic
quonic / Test-Prime.ps1
Created Nov 6, 2018
Get-Factor and Test-Prime functions that are fairly fast, for Powershell
View Test-Prime.ps1
function Get-Factor {
param (
[Parameter(Mandatory = $true,
Position = 0,
ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[int64[]]
$Number,
[switch]