Skip to content

Instantly share code, notes, and snippets.

@onyxhat
onyxhat / Export-Terraformer.ps1
Created May 23, 2022 20:15
Terraformer Export Helper
[CmdletBinding()]
param (
[Parameter()]
[string]
$aws_profile = "VirtixProd",
[Parameter()]
[string[]]
$aws_region = @("us-east-2"),
@onyxhat
onyxhat / get_myip.php
Created March 10, 2019 04:59
simple PHP script to return client IP address
<?php
/**
* Ensures an ip address is both a valid IP and does not fall within
* a private network range.
*/
function validate_ip($ip) {
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) {
return false;
}
return true;
@onyxhat
onyxhat / printenv.groovy
Created February 26, 2019 18:44 — forked from CodeFreezr/printenv.groovy
Jenkins Groovy to print all env-variables
def env = System.getenv()
env.each{
println it
}
Param (
[string]$VMName,
[int]$vCPU,
[int]$MemoryGB
)
$Settings = New-Object PsObject -Property @{
Name = $VMName
vCPU = $vCPU
MemoryStartupBytes = [int]$MemoryGB * 1GB
[string]$UserName = "myJenkinsUser"
[string]$Jenkins_Token = "myJenkinsUserApiKey"
[uri]$Build_URL = "http://jenkins.local/job/myAwesomeApp/latest/"
$Headers = @{
"Authorization" = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("${UserName}:${Jenkins_Token}"))
}
$jobObj = Invoke-RestMethod -Headers $Headers -Uri "${Build_URL}/api/json"
$jobObj
@onyxhat
onyxhat / Create-LinuxVM.ps1
Created August 15, 2018 15:44
Hyper-V script to Automate creation of Linux VMs
$Settings = New-Object PsObject -Property @{
Name = Read-Host "VM Name"
vCPU = Read-Host "vCPU Count"
MemoryStartupBytes = [int]$(Read-Host "GB of RAM") * 1GB
ImgSrc = Read-Host "Source VHD Location"
}
$vmhost = Get-VMHost
if ((Get-VM -Name $Settings.Name -ErrorAction SilentlyContinue) -or (Test-Path -Path "$($vmhost.VirtualHardDiskPath)\$($Settings.Name).vhdx")) {
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

Is a useful one-liner which will give you the full directory name of the script no matter where it is being called from

These will work as long as the last component of the path used to find the script is not a symlink (directory links are OK). If you want to also resolve any links to the script itself, you need a multi-line solution:

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
@onyxhat
onyxhat / remove_floppy.sh
Last active June 15, 2018 03:05
Ubuntu fd0 Errors on boot in Hyper-V
#! /bin/bash
set -e
#Re-run the script if not using sudo/root
detect_current_uid() {
echo $(id -u)
}
rerun_script_as_root() {
if [ $(detect_current_uid) -ne "0" ]; then
@onyxhat
onyxhat / main.go
Created January 8, 2018 01:39 — forked from enricofoltran/main.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@onyxhat
onyxhat / Parse-ChocoParams.ps1
Last active July 15, 2016 15:24
Stub for parsing Chocolatey --params string into variables in the chocolateyinstall.ps1/chocolateyuninstall.ps1
#$packageParameters = $env:chocolateyPackageParameters
$packageParameters = "var1 = val1;var2=`"val2 with spaces -`""
$match_pattern = "(?<key>(\w+))\s*=\s*(?<value>([`"'])?([\w- _\\:\.]+)([`"'])?)"
# Now parse the packageParameters using good old regular expression
if ($packageParameters -match $match_pattern ) {
$results = $packageParameters | Select-String $match_pattern -AllMatches
$results.matches | % {
Set-Variable -Name $_.Groups['key'].Value.Trim() -Value $_.Groups['value'].Value.Trim()
}