Skip to content

Instantly share code, notes, and snippets.

@maurges
maurges / abstract_iterator_proxy.cpp
Created February 27, 2019 12:24
Saving here for later as for the time being I restructured my code to not require this. This shows how to create an iterator proxy for your container within a class. Class names should be changed to appropriate ones.
// When i needed to proxy both const and non-const iterators, i decided
// to metaprogram and cut the code required in half
template <typename It>
class abstract_iterator
{
It m_iter;
// appropriately const value type
using ValueType = typename
std::conditional< std::is_const<decltype(*m_iter)>::value
@maurges
maurges / extrapolate_gradient.py
Created March 13, 2019 11:46
python pillow gradient interpolation
#!/usr/bin/env python3
from PIL import Image, ImageDraw
import sys
def put_vert_grad(draw, x, start, end, factor, init=(0,0,0)):
for y in range(start - 1, end - 1, -1):
color = tuple(round(ini + y * fac) for fac, ini in zip(factor, init))
draw.point((x, y), color)
if x == 0 and y == start - 1:
print("vertical gradient is {}".format(color))
@maurges
maurges / pulseaudio-server.sh
Created May 31, 2019 16:36
Create a pulseaudio rtp stream
#!/bin/bash
# Create a pulseaudio rtp stream
# Run a script, then set <rtpcombine> as your default stream, then connect to it from other device
# check if combined sink already exists
pacmd list-sinks | grep -Fq 'name: <rtpcombine>' && echo "Combined stream already exists" && exit 0
# load rtp modules
pactl load-module module-null-sink sink_name=rtp format=s16be channels=2 rate=44100 sink_properties="device.description='RTP Multicast Sink'"
@maurges
maurges / preproc.rb
Created August 18, 2019 06:36
Simple preprocessor I once wrote in ruby (for cisco configuration files BTW)
#!/usr/bin/ruby
class Inclusions
def initialize(filename)
#file stack to remember where we were before
@files = [filename]
#shows if the inclusion map contains no circular inclusions
@status = true
end
@maurges
maurges / listener.py
Created August 18, 2019 06:38
Simplest flag catcher for when you discover RCE
#!/usr/bin/env python3
# Description: listen for incoming tcp connections, get flags from them, and
# send them to hackerdom's jury server
from socket import create_connection
import socketserver
import re
from sys import stderr
@maurges
maurges / Main.hs
Created August 28, 2019 05:30
The smallest yesod + websockets example
{-# LANGUAGE OverloadedStrings, QuasiQuotes, TemplateHaskell, TypeFamilies #-}
module Main where
import Yesod
import Yesod.WebSockets
import Data.Text (Text)
data MyApp = MyApp
mkYesod "MyApp" [parseRoutes|
@maurges
maurges / main.cpp
Created November 16, 2019 11:22
Clipboard Explorer: see what files hide in clipboard
#include "mainwindow.h"
#include <QApplication>
// Description: simple application with intuitive interface.
// It dumps content of clipboard into files. Useful when you have many different content
// types in your clipboard, and want to see them all.
// All output goes into console window, so run from console.
// Requires Qt5Core and Qt5Widgets. Can be built with qmake or cmake (I build with qmake).
int main(int argc, char *argv[])
@maurges
maurges / cert_create.cpp
Last active December 6, 2019 09:55
NCrypt not having fun
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <Wincrypt.h>
#include <stdexcept>
#include <memory>
#include <iostream>
#include <NCrypt.h>
#include "win32_exception.h"
@maurges
maurges / TlsPipes.hs
Created January 30, 2020 08:55
Haskell pipes example: convert tcp pipes to tls pipes
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE Rank2Types #-}
module Main where
import Control.Concurrent.MVar (MVar, newMVar, takeMVar, putMVar)
import Control.Monad.State.Strict (runStateT)
import Data.ByteString (ByteString)
import Data.ByteString.Lazy (fromStrict)
import Data.Default (def)
@maurges
maurges / RewriteUa.purs
Last active April 6, 2020 09:39
Mozilla extension user-agent rewriting extension example rewritten in purescript
-- | A purescript rewrite of this example extension:
-- | https://github.com/mdn/webextensions-examples/tree/master/user-agent-rewriter
module RewriteUa (main) where
import Prelude
import Browser.Event (addListener)
import Data.Options ((:=))
import Data.String.Common (toLower)
import Effect (Effect)
import Browser.WebRequest