Skip to content

Instantly share code, notes, and snippets.

View quonic's full-sized avatar

Spyingwind quonic

  • Dallas
View GitHub Profile
@quonic
quonic / Get-LastestPowershellCoreMSI.ps1
Created March 4, 2020 22:59
Checks if the current running Powershell Core environment is the latest version and download if it isn't
[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 July 2, 2019 02:47
Example of static screen at about 4 fps on a ryzen 7 1800X.
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 April 25, 2019 19:35
Untested: This should update the exchange rates of the Currency entities. Does require an AutoTask account to have access to multi-currencies.
# 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 April 8, 2019 18:16
Untested: This will sync AD on all Domain Controllers
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 March 3, 2019 07:06
This add an auto upgrade to cron for debian/ubuntu
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 February 14, 2019 06:47
Some example code to rename discord cached images
# 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 January 22, 2019 22:47
Sample of how to create a PowePoint slide and get the text of a shape
$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 January 4, 2019 08:28
ConvertTo-Bits converts any string, number or an array of numbers to a bit array object
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 August 15, 2021 20:50
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.
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 November 6, 2018 20:26
Get-Factor and Test-Prime functions that are fairly fast, for Powershell
function Get-Factor {
param (
[Parameter(Mandatory = $true,
Position = 0,
ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[int64[]]
$Number,
[switch]