Skip to content

Instantly share code, notes, and snippets.

@hughpearse
hughpearse / ncws
Created January 21, 2019 14:25 — forked from kevn-xyz/ncws
Simple netcat based one shot http file server
#!/bin/bash
file=$1
port=$2
if [[ -n "$file" ]] && [[ -n "$port" ]]; then
{ echo -ne "HTTP/1.0 200 OK\nContent-Type: application/octet-stream\nContent-Disposition: inline; filename=\"$1\"\nContent-Length: $(wc -c < $file)\n\n"; cat $file; } | nc -l $port
else
echo "Usage: $(basename $0) <file> <port>"
fi
@hughpearse
hughpearse / listen.sh
Created January 23, 2019 11:07
Listen for any HTTP request
#!/bin/bash
port=$1
if [[ -n "$port" ]]; then
while true;
do
{ echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n<h1>hello world from $(hostname) on $(date)</h1>" | nc -vl $port; }
done
else
echo "Usage: $(basename $0) <port>"
fi
#!/usr/bin/env python3.7
from flask import Flask, Response, request
app = Flask(__name__)
def printReq(request):
print(">>>>")
print(request.method, request.path, request.environ.get('SERVER_PROTOCOL', 'HTTP/1.1'))
print(request.headers)
print(request.data.decode("utf-8"))
@hughpearse
hughpearse / WebServer.py
Last active January 2, 2020 11:53 — forked from joncardasis/WebServer.py
A simple and quick HTTP web server in Python
#!/usr/bin/python
import socket
import signal # Allow socket destruction on Ctrl+C
import sys
import time
import threading
import getopt
class WebServer(object):
"""
@hughpearse
hughpearse / Quarkus-hello-world.txt
Last active May 16, 2021 16:39
Quarkus hello world
Create your starter hello world app on the website and download the zip archive
https://code.quarkus.io/
Check your java version and compile your project:
foo@bar:~$ java -version 2>&1 | grep HotSpot
foo@bar:~$ ./gradlew quarkusDev
Open the dev console:
@hughpearse
hughpearse / user-mode-linux-hostfs.txt
Last active May 20, 2021 13:39
Building and running User Mode Linux (UML)
docker pull gcc
docker run --name gcc -it gcc /bin/bash
cd ~
apt update
apt-get -y install build-essential flex bison xz-utils wget ca-certificates bc linux-headers-5.10.0-6-common slirp
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.12.4.tar.xz
tar -xf linux-5.12.4.tar.xz
cd linux-5.12.4
make menuconfig ARCH=um
@hughpearse
hughpearse / Json.java
Last active November 1, 2021 11:59
Java http request and json processing
/**
* dependencies {
* implementation group: 'com.squareup.okhttp', name: 'okhttp', version: '2.7.5'
* implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.3'
* }
*/
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.squareup.okhttp.OkHttpClient;
import requests
import json
headers = {'Accept': 'application/json', 'User-Agent': 'Hugh'}
url = "https://reddit.com/r/worldnews.json"
r = requests.get(url, headers=headers)
print(r.json()['data'])
@hughpearse
hughpearse / user-mode-linux-alpine-steps.txt
Last active October 25, 2024 22:17
User Mode Linux (UML) Kernel With Alpine Linux OS
How to compile the linux kernel, launch it as a process and boot into Alpine linux
Command + Shift + 5
Host -> Docker GCC -> UML w/ Alpine
# get docker for compiling
foo@host:~$ docker pull gcc
# launch new container
foo@host:~$ docker run --privileged --name gcc -it gcc /bin/bash
@hughpearse
hughpearse / lithops-openwhisk.md
Last active May 27, 2021 23:41
How to deploy Lithops Multicloud with Apache Openwhisk Python 3 to Kubernetes

How to deploy Lithops Multicloud with Apache Openwhisk Python 3 to Kubernetes

This explains how to set up your serverless (FaaS) environment to run Lithops multicloud library. This allows you to avoid vendor lock-in and offboard your serverless code from cloud services.

Reset kubernetes

foo@bar$ export KUBECONFIG=
foo@bar$ minikube stop
foo@bar$ minikube delete --all