Skip to content

Instantly share code, notes, and snippets.

#include "crt.bi"
function merge(c1 as ulong, c2 as ulong, w as single) as ulong
dim as integer r1, g1, b1, r2, g2, b2
dim as integer m = int(w * 256)
assert(m >= 0 and m < 256)
r1 = c1 shr 16 and 255: r2 = c2 shr 16 and 255
g1 = c1 shr 8 and 255: g2 = c2 shr 8 and 255
b1 = c1 and 255: b2 = c2 and 255
@countingpine
countingpine / unscale2x.txt
Last active April 25, 2020 15:50
unscale2x algorithm - reverse of scale2x (notes/pseudocode)
A reverse procedure of Scale2x, as defined by https://www.scale2x.it/algorithm:
ABC
DEF
GHI
B B
D E0 E1 F
D E2 E3 F
H H
#!/bin/bash
# sha256sum each (megabyte-sized) block of /dev/sda, prepend the block number
# intent is to compare two drivesum lists and then dd out the changed blocks and send them to the other drive
device=/dev/sda
bs=1048576
size=$(blockdev --getsize64 $device)
sumsfile=/tmp/sums_$(date +%s).txt
blocks=$(( ($size+$bs-1)/$bs ))
@countingpine
countingpine / 50_isos
Last active April 12, 2018 19:31
grub menuentries for booting from different ISO files
# To use: adjust as needed, place in /etc/grub.d, make executable, run 'sudo update-grub'
# Ubuntu
# https://help.ubuntu.com/community/Grub2/ISOBoot/Examples
menuentry 'Ubuntu 12.04 (64-bit)' {
set isofile="/iso/ubuntu-12.04-desktop-amd64.iso"
loopback loop (hd0,1)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject keyboard-configuration/layoutcode=gb
initrd (loop)/casper/initrd.lz
}
@countingpine
countingpine / GetVMHardDiskParents.ps1
Last active March 29, 2018 09:16
Powershell script to get each VM, and list its disks, and list the chain of differencing disks for each one
Foreach ($VM in Get-VM){
Write-Output $VM.name
Foreach ($HardDrive in $VM.HardDrives){
$VHDPath = $HardDrive.path
Do {
Write-Output ("- " + $VHDPath)
$VHDPath = (Get-VHD -Path $VHDPath).ParentPath
} While ($VHDPath)
}
}
@countingpine
countingpine / mysql-password.ps1
Created May 18, 2018 11:53
PowerShell MySQL password hash generator [TESTME]
$pass = Read-Host "Password" -AsSecureString; $passplain = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass))
$sha1 = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
"*" + [BitConverter]::ToString($sha1.ComputeHash($sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($passplain)))) -replace '-'
@countingpine
countingpine / tc-terminal-server.sh
Last active February 26, 2022 16:34
tc-terminal-server
#!/bin/busybox ash
# Woven together by Curaga (2008)
# Changes made remove user interaction and allow serial console and TFTP package loading by Matthew Fearnley (2018)
. /etc/init.d/tc-functions
useBusybox
set -x
set -u
ROOTFS=core
@countingpine
countingpine / pptxjpg.ps1
Created September 8, 2018 09:52
Convert images in pptx from PNG to JPEG (https://superuser.com/a/1251979/19792)
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)][string]$File,
[Parameter()][int]$Quality = 50
)
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.Drawing
$fs = New-Object System.IO.FileStream (Resolve-Path $File), 'Open'
$zip = New-Object System.IO.Compression.ZipArchive $fs, 'Update'
$zip.Entries | ? {$_.FullName -like 'ppt/media/*.png'} | % {
@countingpine
countingpine / tvsread.c
Created November 3, 2018 23:47
tvsread.c - dump contents of KEY chunks in TeamViewer ".tvs" videos
/* tvsread.c: lists KEY chunks in video and uncompresses them to ./key1.data, ./key2.data, ... */
/* See also http://www.jerrysguide.com/tips/demystify-tvs-file-format.html, https://stackoverflow.com/a/53135938/446106 */
/* Fairly quick and dirty. Tested with a Version 5 video from TeamViewer 13. */
/* compile with gcc -lz tvsread.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
@countingpine
countingpine / truncatefile.bas
Last active November 18, 2019 14:32
Truncate file in VB6
'' see also https://stackoverflow.com/questions/6334917/how-can-i-trim-the-end-of-a-binary-file
'' based in part on http://vbnet.mvps.org/index.html?code/fileapi/truncaterandomfile.htm
Option Explicit
'' constants for CreateFile
Private Const OPEN_ALWAYS As Long = 4, GENERIC_WRITE As Long = &H40000000, GENERIC_READ As Long = &H80000000, FILE_ATTRIBUTE_NORMAL As Long = &H80, INVALID_HANDLE_VALUE As Long = -1
'' constants for SetFilePointer
Private Const FILE_BEGIN As Long = 0, INVALID_SET_FILE_POINTER As Long = -1