Skip to content

Instantly share code, notes, and snippets.

View kristofer84's full-sized avatar
๐Ÿ˜€

Kristofer Nilsson kristofer84

๐Ÿ˜€
  • Stockholm, Sweden
View GitHub Profile
@kristofer84
kristofer84 / ChatGpt-q.ps1
Created July 14, 2025 11:50
Query ChatGpt from PowerShell
$env:OPENAI_API_KEY = "my-key"
function q {
[CmdletBinding()]
param(
[string]$File,
[switch]$Code,
[string]$Model,
[switch]$Help,
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
@kristofer84
kristofer84 / codex.sh
Created June 4, 2025 18:39
Start codex from WSL
docker run -it --rm --entrypoint /bin/bash -v /mnt/c/code:/tmp/code node:latest
npm install -g pnpm
export SHELL="bash"
pnpm setup
source /root/.bashrc
pnpm i -g @openai/codex
export OPENAI_API_KEY="key"
git config --global --add safe.directory /tmp/code
cd /tmp/vol
codex --model gpt-4.1
@kristofer84
kristofer84 / reusableToast.ts
Created May 15, 2025 08:20
Reusable toast with vue-toast-notification
import guid from "./guid";
import { ToastPluginApi, ActiveToast, useToast, ToastProps } from "vue-toast-notification";
import { toastProps } from "./toastProps";
export class ReusableToast {
private toast: ToastPluginApi = useToast(toastProps());
private toastId: string = guid();
private el = document.createElement("span");
private instance: ActiveToast | null = null;
@kristofer84
kristofer84 / geo_names.sh
Last active May 14, 2025 07:14
Conversion and grouping of GeoNames data
# Data from https://download.geonames.org/export/dump/readme.txt
# Add -c to compact and > for output.
# To simple array
jq -Rsn '[inputs
| . / "\n"
| (.[] | select(length > 0) | . / "\t") as $input
| {"location": $input[1], "lat": $input[4], "lon": $input[5], "country": $input[8]}]
' < data.txt
# Grouped by country
@kristofer84
kristofer84 / plc.sh
Created May 5, 2025 08:55
open-plc-utils commands
# https://community.tp-link.com/us/home/forum/topic/553172?sortDir=ASC&page=5
# https://github.com/qca/open-plc-utils
# Info
plcstat -i eth0 -t
plcstat -i eth0 -m
# Get PIB (Parameter Information Block)
plctool -i eth0 -p backup_local.pib AA:BB:CC:DD:EE:FF
@kristofer84
kristofer84 / date-extension.ts
Created October 14, 2024 10:02
getISOWeekNumber ts
// date-extension.d.ts
interface Date {
getISOWeekNumber(): number;
}
// date-extension.ts
Date.prototype.getISOWeekNumber = function (): number {
const date = new Date(this.getTime()); // Create a copy of the current date
date.setUTCDate(this.getUTCDate() + 4 - (this.getUTCDay() || 7)); // Set to nearest Thursday (ISO 8601 week starts on Monday)
const yearStart = new Date(Date.UTC(date.getUTCFullYear(), 0, 1)); // Get the first day of the year
#In PowerShell
$env:DISPLAY="127.0.0.1:0.0"
ssh -Y <your_user_id>@<server_address>
#In Linux
export DISPLAY=localhost:10.0
@kristofer84
kristofer84 / static_route.sh
Created September 17, 2024 19:05
Enable and disable static route in EdgeRouter
configure
delete protocols static route [ip-addr]/32 next-hop 192.168.2.99 disable
set protocols static route [ip-addr]/32 next-hop 192.168.2.99 disable
commit
import { define } from '@selectize/selectize';
define('autofill_off', function (options) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
var self = this;
self.setup = (function () {
var original = self.setup;
return function () {
original.apply(self, arguments);
self.$control_input.attr({ autocomplete: "one-time-code", autofill: "no" });
@kristofer84
kristofer84 / ms-graph.ps1
Last active August 6, 2024 13:55
My commonly used PowerShell Graph commands
# finding expired passwords
$userid = 'user@domain.com'
$user = Get-MgUser -UserId $userid
Get-MgUserOwnedObjectAsApplication -UserId $user.Id | Select-Object DisplayName,Id,AppId,@{e={$_.PasswordCredentials?[0].EndDateTime}}
# cleaning passwords
$app = Get-MgApplication -ApplicationId app-guid
Update-MgApplication -ApplicationId $app.Id -BodyParameter @{ PasswordCredentials = @() }
# updating redirect uris (for spa)