Skip to content

Instantly share code, notes, and snippets.

View pior's full-sized avatar

Pior Bastida pior

View GitHub Profile
@pior
pior / utils.go
Created July 21, 2021 13:38
Benchmark tools
package badger
import (
"fmt"
"os"
"path/filepath"
"time"
"github.com/montanaflynn/stats"
)
package app
import (
"context"
"flag"
"reflect"
"testing"
"time"
"github.com/stretchr/testify/require"
@pior
pior / dynconfig.go
Last active October 13, 2020 15:04
package main
import "strconv"
/////// pkg/dynconfig/key.go
type FloatKey struct {
name string
fallback string
}
func BackgroundWithValues(contextForValues context.Context) context.Context {
return cancellationBlockerContext{context.Background(), contextForValues}
}
type cancellationBlockerContext struct {
context.Context
valueCtx context.Context
}
#!/usr/bin/env python3
import argparse
import fileinput
import re
import sys
from subprocess import run, PIPE, STDOUT
def title(msg):
print(f'\n🍄 {msg}\n')
@pior
pior / fetch_ssl_certificate.py
Last active February 11, 2018 18:59
Fetch a remote SSL certificate without hostname check
import socket
import ssl
def fetch_ssl_certificate(hostname, port=443):
ctx = ssl.create_default_context()
ctx.check_hostname = False
sock = ctx.wrap_socket(socket.socket())
sock.connect((hostname, port))
return sock.getpeercert()
@pior
pior / Dockerfile
Created December 5, 2017 18:50
Tensorflow lib in Docker
FROM golang:1.9
ENV LANG=en_US.utf8
RUN apt-get update && apt-get install -y curl git build-essential
RUN curl -L "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.4.0.tar.gz" \
| tar -xzC /usr/local && \
ldconfig
@pior
pior / pytest_background_proc.py
Last active November 23, 2017 16:16
Control a background process during a test (typically for an integration test)
import os
import subprocess
import tempfile
import time
import pytest
ENABLE = os.environ.get('WITH_INTEGRATION_TESTS')
integration_test = pytest.mark.skipif(not ENABLE, reason="Integration tests skipped")
@pior
pior / ejson.py
Created November 8, 2017 21:30
EJSON decryption in Python with pynacl
import json
import os
import pathlib
from base64 import b64decode
from binascii import unhexlify
from nacl.public import Box, PrivateKey, PublicKey
PRIVATE_KEYS_DIR = '/opt/ejson/keys'
@pior
pior / gcs.py
Created October 10, 2017 21:19
import google.cloud.exceptions
import google.cloud.storage
class GCSFileStore:
def __init__(self, credentials_path, bucket_name):
Client = google.cloud.storage.Client
client = Client.from_service_account_json(credentials_path)
self._bucket = client.bucket(bucket_name)