Skip to content

Instantly share code, notes, and snippets.

@bussiere
bussiere / one_flask.py
Created May 5, 2021 10:37 — forked from mikefromit/one_flask.py
a one file flask app for trying stuff
# THIS PROJECT IS AN EXAMPLE APP. SOME CODE MAY NOT BE ACTUALLY USEFUL
# FOR DEMONSTRATION PURPOSES ONLY
# YOUR MILEAGE MAY VARY
# Requirements are Flask, Flask-WTF, Flask-SQLAlchemy
import os
from flask import (Flask,
Blueprint,
redirect,
@bussiere
bussiere / srd_5e_monsters.json
Created January 14, 2021 21:44 — forked from tkfu/srd_5e_monsters.json
A JSON file with all the D&D 5e SRD monster data
[
{
"name": "Aboleth",
"meta": "Large aberration, lawful evil",
"Armor Class": "17 (Natural Armor)",
"Hit Points": "135 (18d10 + 36)",
"Speed": "10 ft., swim 40 ft. ",
"STR": "21",
"STR_mod": "(+5)",
"DEX": "9",
@bussiere
bussiere / config.go
Created December 18, 2020 20:49 — forked from chazcheadle/config.go
Golang Viper config read into struct
package main
import (
"fmt"
"github.com/spf13/viper"
)
// Create private data struct to hold config options.
type config struct {
@bussiere
bussiere / go-worker.go
Created February 16, 2020 19:58 — forked from System-Glitch/go-worker.go
A resilient service worker written in Go
package main
// This is an example of a resilient service worker program written in Go.
//
// This program will run a worker every 5 seconds and exit when SIGINT or SIGTERM
// is received, while ensuring any ongoing work is finished before exiting.
//
// Unexpected panics are also handled: program won't crash if the worker panics.
import (
@bussiere
bussiere / cantor_pairing.go
Created February 14, 2020 20:14 — forked from dyoo/cantor_pairing.go
Cantor pairing function
// http://en.wikipedia.org/wiki/Pairing_function
package main
import (
"fmt"
"math"
)
func InvertedCantorPairing(z int) (int, int) {
w := int(math.Floor((math.Sqrt(float64(8*z+1)) - 1) / 2))
@bussiere
bussiere / graphql-go-mongodb-example.go
Created November 1, 2019 17:28 — forked from aquiseb/graphql-go-mongodb-example.go
Minimal example of GraphQL Golang and MongoDB playing nicely together. Edit
// Embedded in this article https://medium.com/p/c98e491015b6
package main
import (
"fmt"
"log"
"net/http"
"time"
"github.com/graph-gophers/graphql-go"
@bussiere
bussiere / csvtomap.go
Created May 18, 2019 17:23 — forked from drernie/csvtomap.go
Golang Convert CSV Records to Dictionaries using Header Row as Keys
// CSVToMap takes a reader and returns an array of dictionaries, using the header row as the keys
func CSVToMap(reader io.Reader) []map[string]string {
r := csv.NewReader(reader)
rows := []map[string]string{}
var header []string
for {
record, err := r.Read()
if err == io.EOF {
break
}
@bussiere
bussiere / cuter.py
Created February 24, 2019 15:01 — forked from sigilioso/cuter.py
Python PIL Example: get a thumbnail by resizing and cropping an image.
# -*- coding: utf-8 -*-
import Image
def resize_and_crop(img_path, modified_path, size, crop_type='top'):
"""
Resize and crop an image to fit the specified size.
args:
img_path: path for the image to resize.
@bussiere
bussiere / HaversinFormula.go
Last active January 16, 2019 21:47 — forked from cdipaolo/HaversinFormula.go
Golang functions to calculate the distance in meters between long,lat points on Earth.
import "math"
// haversin(θ) function
func hsin(theta float64) float64 {
return math.Pow(math.Sin(theta/2), 2)
}
// Distance function returns the distance (in meters) between two points of
// a given longitude and latitude relatively accurately (using a spherical
// approximation of the Earth) through the Haversin Distance Formula for
@bussiere
bussiere / migrate-django.md
Created January 5, 2019 13:10 — forked from sirodoht/migrate-django.md
How to migrate Django from SQLite to PostgreSQL

How to migrate Django from SQLite to PostgreSQL

Dump existing data:

python3 manage.py dumpdata > datadump.json

Change settings.py to Postgres backend.

Make sure you can connect on PostgreSQL. Then: