Skip to content

Instantly share code, notes, and snippets.

View cosimo's full-sized avatar
🇳🇴

Cosimo Streppone cosimo

🇳🇴
View GitHub Profile
@cosimo
cosimo / Dockerfile
Last active March 25, 2024 15:42
Dockerfile to build libvmod-dynamic 7.4 (https://github.com/nigoroll/libvmod-dynamic)
# Build libvmod_dynamic.so from source (https://github.com/nigoroll/libvmod-dynamic@7.4)
FROM ubuntu:20.04
ENV TZ=Etc/UTC
ENV VARNISH_VERSION 7.4
# Avoid tzdata terminal configuration that would halt the build
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
@cosimo
cosimo / hetzner.vimrc
Last active February 29, 2024 13:03
Hetzner rescue mode /root/.vimrc file
"=======================================================================
" Vim settings file by Andreas Schneider <mail at cynapses.org>
" with parts from Ciaran McCreesh <ciaranm at gentoo.org>
" and Sven Guckes <setup-vimrc.forall at guckes.net>
"
" Most recent update: Do Mär 01 11:35:54 CET 2007
"
" Get the latest version from:
" http://www.cynapses.org/tmp/setup/
"
@cosimo
cosimo / wss.py
Created August 29, 2023 08:44
Python: connect to a websocket and send a message without any asyncio complications
#
# Requirements:
# - websocket-client==1.6.2
#
from websocket import create_connection
def select_origin_header(extra_headers):
origin = None
@cosimo
cosimo / py3-poetry-ci.yml
Created March 30, 2023 15:36
GHA ci workflow for Python 3 projects based on Poetry
name: CI
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
ci:
strategy:
import os
import dotenv
from langchain import PromptTemplate, HuggingFaceHub, LLMChain
# Add your HuggingFace hub token in a `.env` file, as:
#
# ```
# HUGGINGFACEHUB_API_TOKEN=hf-....
# ```
@cosimo
cosimo / gcp-list-nat-ips.py
Created November 28, 2022 15:07
How to list Google Cloud NAT ips for a project
#!/usr/bin/env python3
# encoding: utf-8
"""
Lists all the GCP CloudNat IP addresses in a list of projects
Usage:
./gcp-list-nat-ips.py --project <gcp-project-name>
"""
// Modified from http://www.stargazing.net/kepler/jsmoon.html
//
// This page works out some values of interest to lunar-tics
// like me. The central formula for Moon position is approximate.
// Finer details like physical (as opposed to optical)
// libration and the nutation have been neglected. Formulas have
// been simplified from Meeus 'Astronomical Algorithms' (1st Ed)
// Chapter 51 (sub-earth and sub-solar points, PA of pole and
// Bright Limb, Illuminated fraction). The libration figures
@cosimo
cosimo / sun_moon_position.js
Created November 20, 2022 16:41
Calculate position of the Sun and Moon from the Earth frame of reference (equatorial coordinates)
// https://stackoverflow.com/a/11760121/11303
function julian_days() {
const date = new Date();
//const jd = Math.floor((date / 86400000) - (date.getTimezoneOffset() / 1440) + 2440587.5);
const jd = (date / 86400000) - (date.getTimezoneOffset() / 1440) + 2440587.5;
console.log("jd=" + jd);
return jd;
}
// https://en.wikipedia.org/wiki/Position_of_the_Sun
@cosimo
cosimo / huggingface-bert-inference.py
Created November 6, 2022 19:37
Inference of Italian language BERT models via huggingface/Pytorch
"""
Example of inference of masked LM models via Huggingface
and transformers/bert in Italian language
"""
import torch
from torch.nn import functional as F
from transformers import AutoModel, AutoModelWithLMHead, AutoTokenizer
#model_name = "dbmdz/electra-base-italian-xxl-cased-discriminator"
@cosimo
cosimo / geoip2_lookup.py
Created September 16, 2022 16:16
Simple GeoIP2 IP latitude, longitude lookup in Python 3
#!/usr/bin/env python3
"""
Looks up an IP address using GeoLite2 City Database
"""
from functools import lru_cache
import geoip2.database
import geoip2.errors