Skip to content

Instantly share code, notes, and snippets.

View RomeoV's full-sized avatar
👨‍🎓

RomeoV RomeoV

👨‍🎓
View GitHub Profile
@RomeoV
RomeoV / boost_graph_example.cpp
Last active September 19, 2019 12:08
The main purpose of this file is to showcase how to use the BGL as cleanly as possible, reducing boilerplate code.
/** @author Romeo Valentin
* @date 19.09.2019
* @brief Clean usage of boost graph library
*
* The main purpose of this file is to showcase how to use the BGL as cleanly as possible, reducing boilerplate code.
* Since I keep coming back to the BGL, I hope this will help me for future reference.
*
* Compile with `g++ -lboost_graph -std=c++14 boost_graph_example.cpp`
*/
@RomeoV
RomeoV / cpp20_compiletime_expression.cpp
Created September 19, 2019 12:07
Showcases c++20 compile-time syntax using constexpr std::transform. Currently compiles with clang 10.0 experimental version.
#include <array>
#include <algorithm>
constexpr int factorial(int n) {
return n == 0 ? 1 : n * factorial(n - 1);
}
template <typename T, std::size_t N, typename F>
constexpr std::array<std::result_of_t<F(T)>, N>
transform(std::array<T, N> array, F f) {
@RomeoV
RomeoV / cpp20_compiletime_fibonacci_sum.cpp
Last active September 25, 2019 13:07
Solves the second ProjectEuler problem completely during compile time. Uses C++20 features (currently only in gcc head).
#include <array>
using uint = unsigned int;
constexpr uint fib(std::size_t n) {
return (n <=1)? 1 : fib(n-1) + fib(n-2);
}
template<typename T>
constexpr bool predicament(T num) {
@RomeoV
RomeoV / youtube_music_extractor.py
Created October 4, 2019 23:45
A tool that queries youtube for a video name/topic and then tries to extract the song name(s) from the description. Afterwards, they can be pasted in some online service and exported as a spotify playlist.
from googleapiclient.discovery import build
import re
youtube = build('youtube','v3',developerKey=...)
video_ids = []
for run_nbr in range(30):
search_response = youtube.search().list(q='tf2 JOTW ' + str(run_nbr),part='id',type='video',maxResults=1).execute()
for search_result in search_response.get('items',[]):
# Implementation details:
# Note that the device_ch is unbuffered.
# Thus, the spawned thread loads data X to gpu and then waits at the
# `put!` command until the previously batch is consumed by the main thread.
"Asynchronously apply data transform to batches and bring one batch to the device."
async_data_prep(train_loader, transform_fn, device; num_threads=4) =
Channel{Batch_t}(spawn=true) do device_ch
transformed_data = throttled_parallel_data_transform(
train_loader, transform_fn, num_threads)
for (X, Y) in transformed_data
@RomeoV
RomeoV / Manifest.toml
Last active February 8, 2023 06:39
Bugreport PyCallChainRules.jl Issue 29
# This file is machine-generated - editing it directly is not advised
julia_version = "1.9.0-beta3"
manifest_format = "2.0"
project_hash = "0dcb1be53cdfb37b6d1a06796f509eec646f7a67"
[[deps.AbstractFFTs]]
deps = ["ChainRulesCore", "LinearAlgebra"]
git-tree-sha1 = "69f7020bd72f069c219b5e8c236c1fa90d2cb409"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@RomeoV
RomeoV / README.md
Last active January 9, 2024 14:41
Run own LLM on GCP instance.

Brief summary of how to run a llamafile on a GCP instance and connect to it via e.g. gptel.el to have nice access to an LLM. The server is about $1.20 per hour. We'll present how to shut of the server automatically once no requests have been made for 1h.

Essentially, I'm presenting

  • A systemd service that starts our llm on port 8081.
  • A systemd service that monitors port 8081 and pipes requests to a file
  • A systemd service that monitors the file and shuts down the instance when the file's last modification is >1h.
  • A small configuration snippet to connect to it from emacs.

Installation

@RomeoV
RomeoV / configuration.nix
Last active May 7, 2024 20:03
Setup invidious on NixOS
{ config, lib, pkgs, ... }: {
networking.hostName = "mycloud-nixos";
services.tailscale = {
enable = true;
};
services.invidious = {
enable = true;
port = 8090;
};
networking.firewall = {