Skip to content

Instantly share code, notes, and snippets.

View hartfordfive's full-sized avatar

Alain Lefebvre hartfordfive

View GitHub Profile
@5j9
5j9 / wsgiref_flask.py
Created December 21, 2020 16:13
running flask app using python's built-in wsgiref
# call this server using the following js command from the browser console:
# (await fetch('http://localhost:5000/', {method: "POST", body: '5'})).text()
# note: wsgiref is only good for development and in that case Werkzeug is
# usually preferred. See http://mitsuhiko.pocoo.org/wzdoc/wsgihowto.html
from wsgiref.simple_server import make_server
from flask import Flask, request, Response
app = Flask(__name__)
groups:
- name: datetime
rules:
- record: daily_saving_time_belgium
expr: |
(vector(0) and (month() < 3 or month() > 10))
or
(vector(1) and (month() > 3 and month() < 10))
or
(
@portante
portante / sum-es-indices.py
Last active January 21, 2021 21:10
A script to generate a report of Elasticsearch index usage (from _cat/indices?v&bytes=b) by prefix for a set of known date suffixes.
#!/usr/bin/env python2
# A script to generate a report of Elasticsearch index usage
# (from _cat/indices?v&bytes=b) by prefix for a set of known
# date suffixes.
#
# E.g.
# $ curl -X GET http://localhost:9200/_cat/indices?v\&bytes=b -o indices.lis
# $ ./sum-es-indices.py indices.lis
#
@franchb
franchb / main.go
Created February 20, 2018 11:17
reuse response Body in Golang
// read the response body to a variable
bodyBytes, _ := ioutil.ReadAll(response.Body)
// Use io.Copy to just dump the response body to the file. This supports huge files
err := ioutil.WriteFile("tmp/asdf.png", bodyBytes, 0644)
if err != nil {
log.Fatal(err)
}
fmt.Println("Captcha image saving success!")
//reset the response body to the original unread state
response.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
@mxschmitt
mxschmitt / cmd.bat
Last active April 18, 2024 21:48
Golang example of cmd stderr / stdout merge to a single channel
@echo off
echo Stdout
echo Stderr 1>&2
@sanchezzzhak
sanchezzzhak / clickhouse-get-tables-size.sql
Created January 18, 2018 13:43
clickhouse get tables size
SELECT table,
formatReadableSize(sum(bytes)) as size,
min(min_date) as min_date,
max(max_date) as max_date
FROM system.parts
WHERE active
GROUP BY table
@alex-leonhardt
alex-leonhardt / main.go
Created August 11, 2017 16:37
mini golang app to connect and return a message from consul kv
package main
import (
"encoding/json"
"net/http"
consul "github.com/hashicorp/consul/api"
)
func getKVdata() *consul.KVPair {
@matryer
matryer / term_context.go
Last active March 10, 2022 05:23
Making Ctrl+C termination cancel the context.Context
func main() {
ctx := context.Background()
// trap Ctrl+C and call cancel on the context
ctx, cancel := context.WithCancel(ctx)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
defer func() {
signal.Stop(c)
@justincbagley
justincbagley / How_to_Convert_Markdown_to_PDF.md
Last active June 14, 2024 22:42
How To Convert Markdown to PDF

How to convert markdown to PDF:

This post reviews several methods for converting a Markdown (.md) formatted file to PDF, from UNIX or Linux machines.

Using Pandoc:

$ pandoc How_I_got_svg-resizer_working_on_Mac_OSX.md -s -o test1.pdf
@StandoffVenus
StandoffVenus / Acceptor.go
Last active January 15, 2019 00:41
Gale-Shapley Algorithm in Golang
package Village
type Acceptor struct {
Name string
preferences map[*Proposer]int
Free bool
partner *Proposer
proposalPool []*Proposer
}