Skip to content

Instantly share code, notes, and snippets.

View tresf's full-sized avatar

Tres Finocchiaro tresf

View GitHub Profile
#!/bin/bash
keywords=('developer-low' 'door-open' 'fuser-over-temp' 'fuser-under-temp' 'input-tray-missing' 'interlock-open' 'interpreter-resource-unavailable' 'marker-supply-empty' 'marker-supply-low' 'marker-waste-almost-full' 'marker-waste-full' 'media-empty' 'media-jam' 'media-low' 'media-needed' 'moving-to-paused' 'opc-life-over' 'opc-near-eol' 'output-area-almost-full' 'output-area-full' 'output-tray-missing' 'paused' 'shutdown' 'spool-area-full' 'stopped-partly' 'stopping' 'timed-out' 'toner-empty' 'toner-low')
echo "INFO: This is an informational message, I guess?" >&2
for i in {1..290}
do
echo "STATE: ${keywords[$i % 29]}" >&2
sleep .1
done
@tresf
tresf / qz_despatchcloud.md
Last active May 17, 2023 04:31
QZ Tray and DespatchCloud
const ws = require('ws');
const qz = require('qz-tray');

qz.api.setWebSocketType(ws);

fetch('https://production.courierapi.co.uk/api/couriers/v1/Test/create-label',
{
    method: 'POST',
    headers: {
@tresf
tresf / dosbox_raw.md
Last active April 10, 2023 18:32
Printing to a raw printer from DOSBox

Printing to a raw printer from DOSBox

Summary

  • Although DOSBox offers printing support, the documentation is sparse and most articles refer to printing on a Windows host.
  • Using DOSBox 0.7.4-3 I was unable to get printing working, so I'm using DOSBox-X instead.
  • Using Ubuntu 20.04 and a fork of DOSBox called DOSBox-X, printing can be configured as follows.

Prerequisites

@tresf
tresf / sign-message.deno.js
Created March 23, 2023 14:46
Signing using Deno + QZ Tray
/**
* Author: A. Tres Finocchiaro
* License: Public Domain
*/
import "https://raw.githubusercontent.com/qzind/tray/v2.2.2/js/qz-tray.js";
import { encode, decode } from "https://deno.land/std/encoding/base64.ts";
// Load certificate
qz.security.setCertificatePromise(function(resolve, reject) {
@tresf
tresf / print.js
Created February 2, 2023 23:38
QZ Tray + ThermalPrinterEncoder (Node.js)
let tpe = require('thermal-printer-encoder');
let ws = require('ws');
let qz = require('qz-tray');
let encoder = new tpe({
language: 'esc-pos'
});
let result = encoder
.initialize()
@tresf
tresf / index.php
Last active January 12, 2023 02:22
QZ Tray PHP Hello World
<html><head><meta charset="UTF-8"></head>
<body>
<!-- USAGE: index.php?var1=some_value_to_print -->
<?php
if (isset($_GET["var1"])) {
echo '<!-- FROM PHP --><script>var var1 = "' . htmlspecialchars($_GET["var1"]) . '";</script>';
} else {?>
<form action="index.php" method="get">Some value: <input type="text" name="var1"><br>
@tresf
tresf / README.MD
Last active December 15, 2022 19:49
PowerShell QZ Tray Session Stealer (for Windows fast user switching)

PowerShell QZ Tray Session Stealer

Custom session stealer for Windows fast user switching

For a pure Batch solution, see here instead: https://gist.github.com/tresf/ff91bd29f1f6846c13bf6f8bc255ab55

Problem

  • QZ Tray is a singleton application, so only one instance can run at a time.
  • Windows fast-user switching feature leaves applications running when a new user signs onto a shared workstation
  • QZ Tray can "steal" the instance, however this is retroactive and places a burden on the user
@tresf
tresf / README.MD
Last active December 15, 2022 19:49

Batch QZ Tray Session Stealer

Custom session stealer for Windows fast user switching

For a pure PowerShell solution, see here instead: https://gist.github.com/tresf/4e19e15ad38354af6732ee701c990102

Problem

  • QZ Tray is a singleton application, so only one instance can run at a time.
  • Windows fast-user switching feature leaves applications running when a new user signs onto a shared workstation
  • QZ Tray can "steal" the instance, however this is retroactive and places a burden on the user
@tresf
tresf / active_sessions.ps1
Last active December 14, 2022 17:44
PowerShell: Get active windows login sessions
# Adopted from: https://www.reddit.com/r/PowerShell/comments/306mcn/wtsenumeratesessions/
# Original Author: u/geostude
$_WTSMyStruct_Def = @'
namespace mystruct {
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public struct WTS_SESSION_INFO {
public Int32 SessionID;
@tresf
tresf / qz-tray-properties.bat
Last active November 16, 2022 17:24
Add entry to properties file
@echo off
NET SESSION >nul 2>&1
if %ERRORLEVEL% EQU 0 (
echo Administrator PRIVILEGES Detected!
) else (
echo NOT AN ADMIN!
pause
exit
)