Skip to content

Instantly share code, notes, and snippets.

View poizan42's full-sized avatar

Kasper Fabæch Brandt poizan42

View GitHub Profile
@poizan42
poizan42 / q_encode.php
Created June 8, 2015 12:16
PHP q_encode
/*
Konverterer en streng til Q-encoding
En del spam filtrer ser ud til at regne det for mere sandsyneligt at en mail er spam hvis
subject og from er base64 encodet - og der er ingen grund til at udfordre skæbnen...
Q-encoding er en modificeret udgave af quoted-printable, som benyttes til mime headers
quoted-printable er beskrevet på wikipedia på http://en.wikipedia.org/wiki/Quoted-printable
forskellene der er i Q-encoding er beskrevet på http://en.wikipedia.org/wiki/MIME#Encoded-Word
Der er faktisk en funktion i php til at gøre dette - iconv_mime_encode -
denne encoder bare ikke alting korrekt (mellemrum som =20),
@poizan42
poizan42 / Mandelbrot16x16-fixed.pdf
Last active August 29, 2015 14:25
16x16 Mandelbrot set rendered by a tint transform (it's not technically a valid pdf because it lacks lengths and the xref table which is hard to write by hand, but every reader can reconstruct them anyways). The Mandelbrot16x16-fixed.pdf file has been opened and saved with Adobe Reader which repairs the file (but makes it human unreadable).
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@poizan42
poizan42 / mandelbrot-pdf-256x256.py
Created July 21, 2015 23:11
Some experimentation with creating a pdf with a 256x256 Mandelbrot set rendered by the viewer by using a tint transform. Viewers generally seems to reduce the precision to 8bpp before passing the data on to the tint transform, so it doesn't work
#!/usr/bin python
pdf = """%PDF-1.4
1 0 obj
<< /Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R
>>
endobj
2 0 obj
function Get-CroppedText
{
$pdftotext="C:\Program Files\xpdf\pdftotext.exe"
$bbox=$args[0]
$inFile=$args[1]
pdfcrop --bbox $bbox $inFile tmp2.pdf | Out-Null
& $pdftotext -nopgbrk tmp2.pdf - | Select-Object -First 1 | foreach { $_.Trim() }
rm tmp2.pdf
}
@poizan42
poizan42 / eratosthenes.cs
Last active March 14, 2016 15:21
Example showing the problem described in icsharpcode/ILSpy#684. Code originally written for [02242 Program Analysis](http://www.kurser.dtu.dk/02242.aspx), the language used is called While+ (but note that there are a couple of slightly different languages with that designation used in analysis and semantics litterature).
// Program
static int Main(string[] array)
{
int[] array2 = new int[1000];
int num = int.Parse(Console.ReadLine());
if ((num >= 1000) ?? (num < 2))
{
Console.WriteLine(-1);
}
else
{
"saveVersion": 15,
"resources": [
{
"name": "catnip",
"value": 143495309.65551314,
"unlocked": true,
"isHidden": false
},
{
@poizan42
poizan42 / Makefile
Last active January 4, 2020 23:26
Demonstration of running 32-bit code on WSL
call32test: call32test.o call32.o
gcc -g $^ -o $@
call32test.o: call32test.c
gcc -g -c $< -o $@
call32.o: call32.asm
nasm -f elf64 call32.asm -o call32.o
@poizan42
poizan42 / get-dncore-stacks.sh
Created September 19, 2017 20:54
Prints full stack trace of every thread in a dotnet core process out to stdout
lldb --attach-name dotnet -o "plugin load libsosplugin.so" -o "eestack" -o "process detach" -o "exit"
@poizan42
poizan42 / StreamedXmlReader.cs
Created November 1, 2017 17:27
XmlReader that supports reading a document from a stream with multiple documents
using System.IO;
using System.Xml;
internal class StreamedXmlReader : XmlTextReader
{
private bool eof;
public override bool EOF => base.EOF || eof;
public StreamedXmlReader(TextReader input) : base(input)
{
}
@poizan42
poizan42 / DeleteAnyFile.ps1
Last active November 24, 2017 13:33
PowerShell script for deleting files with otherwise invalid filenames
param([String]$filename)
$signature = @'
[DllImport("kernel32.dll", ExactSpelling=true, CharSet=CharSet.Unicode, SetLastError=true)]
public static extern uint DeleteFileW(
string lpFileName);
'@
$type = $null
try