This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pydantic import BaseModel, TypeAdapter | |
from sqlalchemy import JSON, TypeDecorator | |
from sqlalchemy.orm import DeclarativeBase | |
from sqlalchemy.sql import elements | |
class PydanticJson(TypeDecorator): | |
impl = JSON | |
cache_ok = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from io import BytesIO, IOBase, StringIO | |
from typing import Type, TypeVar | |
from pydantic import BaseModel, TypeAdapter | |
from ruamel.yaml import YAML | |
from sqlalchemy import Text, TypeDecorator | |
T = TypeVar("T", bound=BaseModel) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Installs an IKEv2 VPN server on Amazon linux. | |
# Reference: | |
# https://hub.zhovner.com/geek/universal-ikev2-server-configuration/ | |
# https://www.zeitgeist.se/2013/11/22/strongswan-howto-create-your-own-vpn/ | |
# Operates well on a t2.nano instance for administrative use. t2 allows full CPU | |
# usage as long as < 5% of daily operation time which is perfect for an | |
# administrative VPN. The server fits well inside the ram requirements and uses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Some fonts may not be able to represent all characters. | |
# This replaces or removes the offending characters. | |
# Get the contents. | |
f = open('translate.txt', 'r') | |
file_contents = f.read() | |
f.close() | |
# Escape all special characters. | |
escaped_string = file_contents.encode('ascii', 'xmlcharrefreplace').decode('utf-8') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DUMP_DIR="<dump_dir>" | |
MYSQLDUMP="/usr/bin/mysqldump" | |
DUMP_FILE_PREFIX="<database>_dump" | |
dump_date=`date +"%Y%m%d-%H"` | |
dump_file="${DUMP_FILE_PREFIX}_${dump_date}.sql" | |
if [ ! -d "$DUMP_DIR" ]; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Lines of code | |
cloc ./Classes | |
# Number of classes | |
grep -r "^\@interface [a-zA-Z0-9]* \: " ./Classes | wc -l | |
# Number of instance selectors | |
grep -r "^\- ([a-zA-Z0-9 ]*)[a-zA-Z0-8:() ]* {" ./Classes | wc -l |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <CommonCrypto/CommonHMAC.h> | |
NSString* md5(NSString *string) { | |
const char *cStr = [string UTF8String]; | |
unsigned char digest[CC_MD5_DIGEST_LENGTH]; | |
CC_MD5( cStr, (unsigned int)strlen(cStr), digest ); | |
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; | |
for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) | |
[output appendFormat:@"%02x", digest[i]]; | |
return output; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var alphaNumeric = regexp.MustCompile("^[a-zA-Z0-9]*$") | |
var db *sql.DB | |
// Checks that the user is authorized by validating the username and password | |
// provided through basic authentication against values in the database. | |
// Presents a login page if not present or invalid. | |
func authHandler(fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc { | |
return func(w http.ResponseWriter, r *http.Request) { | |
// Send a 401 Not Authorized and set a header value to trigger login. | |
presentLogin := func(w http.ResponseWriter, r *http.Request) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"fmt" | |
"io" | |
"net/http" | |
"strings" | |
"time" | |
) | |
// https://httpd.apache.org/docs/2.2/logs.html#combined + execution time. | |
const apacheFormatPattern = "%s - - [%s] \"%s %s %s\" %d %d \"%s\" \"%s\" %.4f\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install gogs as a package | |
wget -qO - https://deb.packager.io/key | sudo apt-key add - | |
echo "deb https://deb.packager.io/gh/pkgr/gogs trusty pkgr" | sudo tee /etc/apt/sources.list.d/gogs.list | |
sudo apt-get update | |
sudo apt-get install gogs | |
# Put down a webserver and mysql | |
APP_NAME="gogs" |
NewerOlder