Skip to content

Instantly share code, notes, and snippets.

View benjaminalt's full-sized avatar

Benjamin Alt benjaminalt

View GitHub Profile
@benjaminalt
benjaminalt / install-update-cursor.sh
Created October 15, 2025 09:11
Script to install and update Cursor on Ubuntu. Tested on 24.04.
#!/bin/bash
# Define colors and styling
RED='\e[1;31m'
GREEN='\e[1;32m'
BLUE='\e[1;34m'
YELLOW='\e[1;33m'
CYAN='\e[1;36m'
PURPLE='\e[1;35m'
NC='\e[0m' # No Colora
@benjaminalt
benjaminalt / killable_xmlrpc_server.py
Created December 15, 2022 10:31
Killable XMLRPC server
from xmlrpc.server import SimpleXMLRPCServer
from typing import Tuple
class RPCServer(SimpleXMLRPCServer):
def __init__(self, addr: Tuple[str, int], **kwargs):
super().__init__(addr, **kwargs)
self.quit = False
def serve_forever(self):
self.quit = False
@benjaminalt
benjaminalt / plot_grad_flow.py
Created February 13, 2020 15:24
Plot gradient flow
def plot_grad_flow(named_parameters):
'''Plots the gradients flowing through different layers in the net during training.
Can be used for checking for possible gradient vanishing / exploding problems.
Usage: Plug this function in Trainer class after loss.backwards() as
"plot_grad_flow(self.model.named_parameters())" to visualize the gradient flow'''
ave_grads = []
max_grads= []
layers = []
@benjaminalt
benjaminalt / real_time_plotter.py
Last active December 1, 2019 21:08
Real-time plotting with matplotlib
import numpy as np
import matplotlib.pyplot as plt
import time
import multiprocessing as mp
from queue import Empty
class PlotterProcess(mp.Process):
def __init__(self, queue, series_labels, shutdown_event, output_filename):
super(PlotterProcess, self).__init__()
@benjaminalt
benjaminalt / data_augmentation.py
Created May 20, 2019 20:48
Parallel memory-efficient data augmentation
import argparse
import multiprocessing
import os
import time
import random
import tables
import numpy as np
import pandas as pd
from tqdm import tqdm
@benjaminalt
benjaminalt / printTree.cpp
Created April 13, 2018 07:19
Print a boost::property_tree
std::string indent(int level)
{
std::string s;
for (int i = 0; i<level; i++) s += " ";
return s;
}
void printTree(boost::property_tree::ptree &pt, int level)
{
if (pt.empty())
@benjaminalt
benjaminalt / model.json
Created August 3, 2017 12:49
Keras LSTM model (for bug report)
{"class_name": "Model", "keras_version": "2.0.6", "config": {"layers": [{"class_name": "InputLayer", "inbound_nodes": [], "config": {"dtype": "float32", "batch_input_shape": [null, 5, 3], "name": "input_1", "sparse": false}, "name": "input_1"}, {"class_name": "LSTM", "inbound_nodes": [[["input_1", 0, 0, {}]]], "config": {"recurrent_activation": "tanh", "trainable": true, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"seed": null, "gain": 1.0}}, "use_bias": true, "bias_regularizer": null, "return_state": false, "unroll": false, "bias_initializer": {"class_name": "Zeros", "config": {}}, "units": 10, "unit_forget_bias": true, "dropout": 0.0, "recurrent_dropout": 0.0, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"distribution": "uniform", "scale": 1.0, "seed": null, "mode": "fan_avg"}}, "kernel_constraint": null, "activation": "tanh", "stateful": false, "activity_regularizer": null, "recurrent_regularizer": null, "name": "lstm_1", "bias_constraint": null, "go_backwards": f
cmake_minimum_required(VERSION 2.8.11)
project(restfs_client)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(
include
usr/include/Poco/Net
)
@benjaminalt
benjaminalt / exec.cpp
Created September 24, 2016 17:01
Execute command and capture stdout in C++
#include <cstdio>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
std::string exec(const char* cmd) {
char buffer[128];
std::string result = "";
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
@benjaminalt
benjaminalt / edit_distance_chars.py
Created June 26, 2016 10:52
Edit distance (dynamic programming)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Author: Benjamin Alt (benjamin_alt@outlook.com)
Calculate the character-level edit distance between a reference string and one or multiple hypotheses.
"""
from __future__ import print_function