Skip to content

Instantly share code, notes, and snippets.

View carc1n0gen's full-sized avatar

Carson Evans carc1n0gen

View GitHub Profile
@carc1n0gen
carc1n0gen / thread_safe_random_numbers.c
Last active July 12, 2019 14:11
Thread safe random numbers in c
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <threads.h>
//#define NUM_THREADS 7
// Thread safe random numbers by tempering the upper 32 bits
// of a 64 bit int. The calculations are based on a seed.
@carc1n0gen
carc1n0gen / busboy-fields-before-file.js
Last active July 12, 2019 14:11
How to read form fields before the file in a multipart upload
// NOTE: this only works if the file upload form field appears last
const busboy = require('connect-busboy');
const express = require('express');
const app = express();
app.use(busboy());
app.post('/upload', (req, res) => {
GateNotDefined = type('GateNotDefined', (Exception,), {})
class Gatekeeper:
def __init__(self, gates={}, before=None):
self.gates = gates
self.before = before
def define(self, name, fn):
self.gates[name] = fn
import smtpd
import asyncore
class FakeSMTPServer(smtpd.SMTPServer):
messages = []
def __init__(*args, **kwargs):
print('Fake smtp server running on port 2525')
smtpd.SMTPServer.__init__(*args, **kwargs)
@carc1n0gen
carc1n0gen / mail.py
Last active April 11, 2021 16:41
Custom Mailer
import smtplib
from email.message import EmailMessage
from flask import g, current_app
class Mailer():
def __init__(self, smtp_host=None, smtp_port=None, username=None,
password=None):
self._smtp_host = smtp_host
self._smtp_port = smtp_port
@carc1n0gen
carc1n0gen / flask-domain-matching.py
Last active February 22, 2021 09:05
Flask Host Matching
from flask import Flask, url_for
app = Flask(__name__, host_matching=True, static_host='app1.local:5000')
@app.route('/', host='app1.local:5000')
def home1():
return url_for('home1')
@carc1n0gen
carc1n0gen / flask-blueprint-subdomains.py
Last active February 19, 2021 15:30
Flask Blueprint Subdomains
from flask import Flask, Blueprint, url_for
app = Flask(__name__)
app.config['SERVER_NAME'] = 'app.local:5000'
bp1 = Blueprint('bp1', __name__, subdomain='app1')
bp2 = Blueprint('bp2', __name__, subdomain='app2')
@carc1n0gen
carc1n0gen / sarcasmify_wsgi.py
Last active April 29, 2022 18:20
Plain WSGI API for converting text in to sarcasm/mocking format
from urllib.parse import parse_qs
def sarcasmify(text):
new_text = ''
flip = True
for i in range(len(text)):
char = text[i]
if flip:
new_text += char.lower()
else:
@carc1n0gen
carc1n0gen / sarcasmify.py
Created April 29, 2022 19:24
Cli command to create sarcasm/mocking formatted texrt
#!/usr/bin/env python3
import sys
def sarcasmify(text):
new_text = ''
flip = True
for i in range(len(text)):
char = text[i]
if flip:
@carc1n0gen
carc1n0gen / dino.cow
Created May 31, 2022 13:53
Custom Cowfiles
##
## Dino
##
$the_cow = <<EOC
\\
\\
\\ ____
\\ /o___)
/ /-/
________/ /-/