Skip to content

Instantly share code, notes, and snippets.

View fgiobergia's full-sized avatar

Flavio Giobergia fgiobergia

View GitHub Profile
@fgiobergia
fgiobergia / refreshpoli.rb
Created February 18, 2014 14:03
Refresh every 60 seconds waiting for some exam's results to be published
require ('uri');
require ('net/https');
headers = {
# Your cookies here
'Cookie' => 'DEV_PORTAL=;OHS-didattica.polito.it-443='
}
uri = URI('https://didattica.polito.it/pls/portal30/sviluppo.esami_da_registrare')
req = Net::HTTP.new(uri.host,uri.port)
@fgiobergia
fgiobergia / hex.c
Created October 25, 2014 18:18
Hex "editor": display, search and replace patterns in binary files
/*
* Hex "editor": display, search and replace patterns in binary files
* http://fgiobergia.com
* The MIT License (MIT)
* Copyright (c) 2014 Flavio Giobergia
* http://opensource.org/licenses/MIT
*/
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define f(x,y,z) ((x&y)|(~x&z))
#define g(x,y,z) ((x&z)|(y&~z))
#define h(x,y,z) (x^y^z)
#define i(x,y,z) (y^(x|~z))
#define ror(x,c) ((x<<c)|(x>>(32-c)))
/* https://www.youtube.com/watch?v=7yDmGnA8Hw0 */
#include <stdio.h>
#define LEN 4
int slowest (int *p) {
return (p[0] > p[1]) ? p[0] : p[1];
}
int try (int *side1, int *side2, int index, int time) {
// using current and other for readability purposes
@fgiobergia
fgiobergia / switch-touchpad.c
Created October 20, 2013 10:09
Touchpad switch, for enabling/disabling the touchpad (using xinput)
#include <stdio.h>
#include <string.h>
/*
* `xinput list` shows a list
* of devices from which you
* can get your device's id.
*/
#define DEVICE 12
@fgiobergia
fgiobergia / peg_solitaire.c
Last active January 2, 2016 10:28
Peg Solitaire Solver (using a graph and backtracking)
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int a;
int w;
void *next;
} *List;
typedef struct {
from lxml import html
import requests
import numpy
page = requests.get('https://cloud.google.com/compute/pricing')
tree = html.fromstring(page.content)
lowest = tree.xpath('//table/tbody/tr/th[text()="Preemptible price"]/../../tr/td[5]/text()')[:18]
lowest_preempt = tree.xpath('//table/tbody/tr/th[text()="Preemptible price"]/../../tr/td[8]/text()')[:18]
"""
GPLv3 yadda yadda
Flavio Giobergia
https://gist.github.com/fgiobergia/395fb9b4727790e0a9a2d24d936526f1
"""
def _merge(a: str, b: str, elisione: bool = True, spacing: bool = False, use_e : bool = False) -> str:
"""Utility function to merge two strings, following a bunch of rules,
as explained in the documentation for int2ita
"""
"""
Code snippet to generate a scatter plot from a given image (mask).
"""
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
im = Image.open("image.png")
mask = (np.array(im) > 0).any(axis=2) # masking condition
@fgiobergia
fgiobergia / word_embeddings_demo.ipynb
Last active September 29, 2024 08:04
Demo for "A quick (and practical) introduction to word embeddings" (Research Bites @ Data Science Lab)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.