Skip to content

Instantly share code, notes, and snippets.

View fishi0x01's full-sized avatar
💾
0x01

Karl Fischer fishi0x01

💾
0x01
View GitHub Profile
#!/usr/bin/env python3
"""
A simple python(3) bf interpreter.
First argument is .bf file with code to execute.
Optionally a file with input arguments can be specified as second argument.
"""
import sys
import re
@fishi0x01
fishi0x01 / power_set.py
Last active March 21, 2020 15:19
Bitwise Techniques for Subset Iterations in Python. Code for blog post https://fishi.devtail.io/weblog/2015/05/18/common-bitwise-techniques-subset-iterations/
#!/usr/bin/env python3
"""
Iterate over each subset of any size (Power set)
"""
def power_set(A):
subsets = []
N = len(A)
# iterate over each subset
@fishi0x01
fishi0x01 / bw_msrmnt.c
Last active November 17, 2023 07:44
Measuring Bandwidth and Round-Trip Time of a TCP Connection inside the Application Layer. Code for blog post https://fishi.devtail.io/weblog/2015/04/12/measuring-bandwidth-and-round-trip-time-tcp-connection-inside-application-layer/
/* Code snippet for measuring bandwidth with harmonic mean */
#define SKIPS 10 // initial measurement skips - skip the first slow-start values
// bandwidth metrics
double bandwidth = -1; // in MB/s
float total_bytes = 0;
int n = 0; // number of measure values
int skips = SKIPS;
@fishi0x01
fishi0x01 / ConnectWMINamespace.java
Last active March 21, 2020 15:22
Basic j-interop DCOM bridge setup snippets. Code for blog post https://fishi.devtail.io/weblog/2015/01/21/pure-java-dcom-bridge-j-interop/
/**
* Code snippet that tries to create a connection with the given wmiLocator object to the given namespace.
* @return An IJIDispatch object that can be used for WQL queries to the given namesapce of the target machine.
* @Exception In case the ConnectServer method could not be properly executed.
*/
public IJIDispatch createNamespaceServer(IJIDispatch wmiLocator, String nameSpace, String ipAddress) throws Exception
{
// create an instance of the WbemScripting.SWbemLocator object to talk to WMI on the target machine.
// namespace could be for instance "root\\cimv2"
JIVariant results[] =
/*
* A simple client that opens a socket.
*/
#include <stdio.h>
#include <sys/socket.h>
int main(int argc, char *argv[])
{
int sockfd;
@fishi0x01
fishi0x01 / header.sh
Last active November 11, 2021 15:02
Dynamic login messages with update-motd framework. Code for blog post https://fishi.devtail.io/weblog/2015/02/06/dyamic-login-messages-update-motd/
# Simple static header for update-motd framework
COLOR_GREEN="\033[0;32m"
# print personal static banner in green
printf "${COLOR_GREEN}
_____ .__ .__ .__
_/ ____\|__| ______| |__ |__|
\ __\ | | / ___/| | \ | |
| | | | \___ \ | Y \| |
@fishi0x01
fishi0x01 / example.html
Last active March 21, 2020 15:23
Functional headless UI testing in Django with Selenium. Code for blog post https://fishi.devtail.io/weblog/2015/03/02/functional-headless-ui-testing-django-selenium/
<!-- Simple webpage for Django UI example test -->
<html>
<head>
</head>
<body>
<p id="test">Hello World!</p>
</body>
</html>
@fishi0x01
fishi0x01 / deploy.sh
Last active March 21, 2020 15:21
Setting up a Django CI with Jenkins. Code for blog post https://fishi.devtail.io/weblog/2015/02/22/setting-django-ci-jenkins-and-git/
#!/bin/bash
# A simple django project deployment script for jenkins
BUILD_ROOT="/srv/www/django/d_project/"
MNGR=${BUILD_ROOT}"manage.py"
# source python env
echo "Sourcing python env..."
source ${BUILD_ROOT}"py-env/bin/activate"
@fishi0x01
fishi0x01 / fermat_binom.py
Last active March 21, 2020 15:19
Calculating large binomial coefficients modulo prime / non-prime numbers (nCk mod m). Code for blog post https://fishi.devtail.io/weblog/2015/06/25/computing-large-binomial-coefficients-modulo-prime-non-prime/
#!/usr/bin/env python3
"""
Using Fermat's little theorem to calculate nCk mod m, for k < m and m is prime
Two versions:
1. Pre-Compute factorials and multiplicative inverses in O(n*logn) --> later lookup in O(1)
2. Compute directly --> no lookup --> each time O(n)
"""
#!/bin/bash
SENSITIVE_FILES="roles/ssh/templates/sshd_config.j2.enc"
if [ "$1" != "clean" ] && [ "$1" != "decrypt" ]
then
echo "only 'clean' or 'decrypt' are allowed"
exit 1
fi