Skip to content

Instantly share code, notes, and snippets.

View rsperl's full-sized avatar

Richard rsperl

  • North Carolina, United States
View GitHub Profile
@rsperl
rsperl / flask_app.py
Last active July 25, 2022 16:14
flask app template #python #rest #snippet
#!/usr/bin/env python3
"""
Documentation
See also https://www.python-boilerplate.com/flask
"""
import os
import argparse
from flask import Flask, jsonify, send_file
from flask_cors import CORS
@rsperl
rsperl / RetryRestDecorator.py
Last active July 25, 2022 16:13
decorator class, base class, and implementation class to provide customized retries for rest calls #python #rest #snippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# src: https://powerfulpython.com/blog/making-unreliable-apis-reliable-with-python/
#
# example usage:
# retry_on_auth_failure = RetryOnAuthFailure()
# retry_on_server_failure = RetryOnServerFailure(retries=5)
#
# @retry_on_server_failure
@rsperl
rsperl / guid2string.py
Last active July 25, 2022 16:09
convert a binary guid from ldap or active directory to a hex string #python #ldap #snippet
#!/usr/bin/python3
import uuid
def guid_to_string(binary_guid: bytes) -> str:
return str(uuid.UUID(bytes_le=binary_guid)).lower()
@rsperl
rsperl / copy_file.go
Last active July 25, 2022 16:08
copy a file #go #snippet
import (
"io"
"os"
)
func cp(dst, src string) error {
s, err := os.Open(src)
if err != nil {
return err
}
@rsperl
rsperl / install_python-ldap.sh
Last active July 25, 2022 16:07
fix sasl.h is required error #python #ldap #snippet
# when you get the error "sasl.h is required"
xcrun --show-sdk-path
sudo ln -s <the_path_from_above_command>/usr/include /usr/include
# if you get "Operation not permitted," you probably need to disable SIP:
# reboot, hold down cmd-R, choose Utilities -> Terminal, type "csrutil disable,"
# reboot, try the steps above again
pip install python-ldap
@rsperl
rsperl / multiprocessing.py
Last active July 25, 2022 16:07
multiprocessing #python #snippet
from multiprocessing import Process
def method_to_call(*args, **kwargs):
# do what you do
pass
def main():
#
rows = ("job1", "job2")
procs = []
@rsperl
rsperl / monitor_debug.go
Last active July 25, 2022 16:06
monitor debug vars #go #snippet
package main
import (
_ "expvar"
"fmt"
"net/http"
"os"
)
// use expvarmon to monitor:
@rsperl
rsperl / download_binary_file.go
Last active July 25, 2022 16:05
download binary file #go #snippet
import (
"encoding/binary"
"fmt"
"io/ioutil"
"net/http"
"os"
)
func download() string {
client := &http.Client{}
@rsperl
rsperl / run_external_command.go
Last active July 25, 2022 16:05
run external command #go #snippet
package main
import (
"bytes"
"fmt"
"log"
"os/exec"
"strings"
)
@rsperl
rsperl / singleton.go
Last active July 25, 2022 16:04
singleton #go #singleton #snippet
import "sync"
var (
r *repository
once sync.Once
)
func Repository() *repository {
if r == nil {
once.Do(func() {