Skip to content

Instantly share code, notes, and snippets.

View lw's full-sized avatar

Luca Wehrstedt lw

View GitHub Profile
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream lettura ("input.txt");
ofstream scrittura ("output.txt");
vector<int> stati;
@lw
lw / binary.cpp
Created December 24, 2011 20:22
Binary Tree to set/add/sum/max
#include <iostream>
#include <string>
#include <algorithm>
#include <limits>
using namespace std;
// The height of the tree (ok, the name is counter-intuitive...)
#define DEPTH 20
// The 'undefined' value for the 'set' field
@lw
lw / get_flags.py
Last active July 11, 2022 21:18
Python script to get country flags from Wikipedia
#!/usr/bin/env python3
# Copyright 2013 Luca Wehrstedt
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
#!/usr/bin/env python3
import sys
import time
import urllib.request
import hashlib
import subprocess
url = sys.argv[1]
#!/usr/bin/env python3
import argparse
import random
def genera_codice():
result = ""
c1 = random.randint(1, 3);
for i in range(c1):
import re
def camelcase_to_underscore(name):
return "_".join(w.lower() for w in re.findall("(?:[A-Z][a-z]+|[A-Z]+(?:$|(?=[A-Z][a-z])))", name))
@lw
lw / snake.py
Created August 6, 2014 10:56
Snake
import sys
import random
import pygame
pygame.init()
grid = (39, 29)
cell = (20, 20)
width = grid[0] * cell[0]
height = grid[1] * cell[1]
@lw
lw / kahn.ml
Created May 7, 2015 16:17
Projet SysRes
module type S = sig
type 'a process
type 'a in_port
type 'a out_port
val new_channel: unit -> 'a in_port * 'a out_port
val put: 'a -> 'a out_port -> unit process
val get: 'a in_port -> 'a process
val doco: unit process list -> unit process
val return: 'a -> 'a process
@lw
lw / run_stress_test.sh
Created January 29, 2018 12:18
CMS stress test
./scripts/cmsDropDB -y > /dev/null;
./scripts/cmsInitDB > /dev/null;
./cmscontrib/AddAdmin.py admin -p admin > /dev/null
# -w is the number of workers (there need to be enough already listed in cms.conf).
# -s is the number of submissions, each of 50 (?) testcases.
# also, in Worker.__init__ set fake_time to 0.1.
python cmstestsuite/RunTimeTest.py -w 16 -s 10
@lw
lw / bezier_calc.py
Created September 6, 2018 09:41
Utils from my M1 internship to draw Bezier curves in LaTeX. Find the coordinate of a point along a curve given by its TikZ parameters, split a curve in two at a given point, find the best curve for an arc.
import math
fixed = 0.552284749831 / math.sqrt(2)
fixed = 0.3915
print(fixed)
def get_point_along_bezier(p1, p2, r, out_d, in_d, rel, out_l, in_l, t):
dx = p2[0] - p1[0]
dy = p2[1] - p1[1]