Skip to content

Instantly share code, notes, and snippets.

View gnilchee's full-sized avatar

Greg Nilchee gnilchee

  • Evernote
  • Woodinville, WA
View GitHub Profile
@gnilchee
gnilchee / http_multithreaded.py
Last active March 12, 2024 13:54
Multi-threaded Python3 HTTP Server
#!/usr/bin/env python3
import sys, os, socket
from socketserver import ThreadingMixIn
from http.server import SimpleHTTPRequestHandler, HTTPServer
HOST = socket.gethostname()
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
@gnilchee
gnilchee / docker-compose-consul.yml
Created October 28, 2016 06:04
Stand up a single node consul server and export ui/api over port 80 and consul dns over port 53
version: '2'
services:
consul:
image: consul
volumes:
- ./data/consul:/consul/data
command: /bin/consul agent -server -data-dir="/consul/data" -bootstrap -client="0.0.0.0" -advertise="127.0.0.1" -ui
ports:
- 80:8500 #HTTP API/UI
- 53:8600/udp #DNS
@gnilchee
gnilchee / haproxy.cfg
Created March 10, 2020 01:32
HAProxy config supporting an active/active setup with shared table used for rate limiting
# tested with HAProxy 2.0 LTS on Debian 9
global
stats socket /tmp/haproxy_admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
defaults
mode http
maxconn 500
@gnilchee
gnilchee / https_server.py
Last active April 6, 2022 18:08
Simple Single threaded HTTPS (SSL) "Server" using Python 3
#!/usr/bin/env python3
import http.server, socketserver, socket, ssl
PORT = 443
HOST = socket.gethostname()
Handler = http.server.SimpleHTTPRequestHandler
https = socketserver.TCPServer(("0.0.0.0", PORT), Handler)
https.socket = ssl.wrap_socket(https.socket, keyfile='/path/to/keyfile.key', certfile='/path/to/certfile.crt', server_side=True, ssl_version=ssl.PROTOCOL_TLSv1_2, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers='ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK')
@gnilchee
gnilchee / https_server_multithread.py
Last active March 11, 2022 19:51
Multi-threaded Python 3 HTTPS Server
#!/usr/bin/env python3
import sys, os, socket, ssl
from socketserver import ThreadingMixIn
from http.server import SimpleHTTPRequestHandler, HTTPServer
HOST = socket.gethostname()
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
@gnilchee
gnilchee / captcha.txt
Last active October 20, 2020 10:32
Convert captcha images so it can be read in tesseract
# apt-get install -y imagemagick tesseract-ocr tesseract-ocr-eng python-pip
# pip install Image pytesseract
# python convert.py 2 captcha.png captcha-clean.png
# convert captcha-clean.png -resize 500 captcha-clean-big.png
# tesseract -c tessedit_char_whitelist=abcdefghijklmnopqrstuvwxyz1234567890 -psm 7 captcha-clean-big.png output
# cat output.txt
@gnilchee
gnilchee / state_to_abbreviation.json
Created May 4, 2020 04:25
convert state name to abbreviation
[
{
"name": "Alabama",
"abbreviation": "AL"
},
{
"name": "Alaska",
"abbreviation": "AK"
},
{
@gnilchee
gnilchee / multiple_promises.js
Last active April 29, 2020 08:02
Using node-fetch and Promises. Comparing using a function vs within the promise to manipulate the data
// import node-fetch module
const fetch = require("node-fetch");
// return user-agent from request
const userAgent = fetch("https://httpbin.org/user-agent")
.then((response) => response.json())
.then((response) => response);
// return origin IP from request
const originIP = fetch("https://httpbin.org/ip")
@gnilchee
gnilchee / get_urls.py
Created March 22, 2020 08:40
Use asyncio and aiohttp to grab status codes from 20 sites
import asyncio
import aiohttp
my_urls = [
'https://www.google.com/',
'https://www.youtube.com/',
'https://www.facebook.com/',
'https://www.wikipedia.org/',
'https://www.yahoo.com/',
'https://www.reddit.com/',
@gnilchee
gnilchee / foreach_tester.php
Created September 16, 2018 07:41
foreach example
<?php
$array = array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'mango',
'fruit5' => 'peach');
echo $array['fruit3'];
echo "\n";