Skip to content

Instantly share code, notes, and snippets.

View nroi's full-sized avatar

Fabian Muscariello nroi

  • Frankfurt am Main, Germany
View GitHub Profile
#!/usr/bin/env python3
import argparse
import datetime
import requests
import tarfile
import tempfile
import gzip
import os
import hashlib
[3.116006287s] [INFO ] [alacritty] glutin event: DeviceEvent { device_id: DeviceId(X(DeviceId(15))), event: Key(KeyboardInput { scancode: 29, state: Pressed, virtual_keycode: Some(LControl), modifiers: (empty) }) }
[3.116068624s] [INFO ] [alacritty] glutin event: WindowEvent { window_id: WindowId(X(WindowId(144703490))), event: KeyboardInput { device_id: DeviceId(X(DeviceId(3))), input: KeyboardInput { scancode: 29, state: Pressed, virtual_keycode: Some(LControl), modifiers: CTRL }, is_synthetic: false } }
[3.471187498s] [INFO ] [alacritty] glutin event: DeviceEvent { device_id: DeviceId(X(DeviceId(15))), event: Key(KeyboardInput { scancode: 37, state: Pressed, virtual_keycode: Some(K), modifiers: CTRL }) }
[3.471222794s] [INFO ] [alacritty] glutin event: WindowEvent { window_id: WindowId(X(WindowId(144703490))), event: KeyboardInput { device_id: DeviceId(X(DeviceId(3))), input: KeyboardInput { scancode: 37, state: Pressed, virtual_keycode: Some(K), modifiers: CTRL }, is_synthetic: false } }
[3.528097763s] [I
[0.096346981s] [INFO ] [alacritty] glutin event: DeviceEvent { device_id: DeviceId(X(DeviceId(15))), event: Key(KeyboardInput { scancode: 28, state: Released, virtual_keycode: Some(Return), modifiers: (empty) }) }
[1.787554907s] [INFO ] [alacritty] glutin event: DeviceEvent { device_id: DeviceId(X(DeviceId(15))), event: Key(KeyboardInput { scancode: 29, state: Pressed, virtual_keycode: Some(LControl), modifiers: (empty) }) }
[1.787633465s] [INFO ] [alacritty] glutin event: WindowEvent { window_id: WindowId(X(WindowId(144703490))), event: KeyboardInput { device_id: DeviceId(X(DeviceId(3))), input: KeyboardInput { scancode: 29, state: Pressed, virtual_keycode: Some(LControl), modifiers: CTRL }, is_synthetic: false } }
[2.681567809s] [INFO ] [alacritty] glutin event: DeviceEvent { device_id: DeviceId(X(DeviceId(15))), event: Key(KeyboardInput { scancode: 25, state: Pressed, virtual_keycode: Some(P), modifiers: CTRL }) }
[2.681635087s] [INFO ] [alacritty] glutin event: WindowEvent { window_id: WindowId(X(WindowId
// #![deny(warnings)]
use std::time::Duration;
use futures::executor::block_on;
use std::net::{TcpListener, TcpStream};
use std::sync::atomic::{AtomicUsize, Ordering};
static REQUEST_COUNT: AtomicUsize = AtomicUsize::new(0);
#[tokio::main]
@nroi
nroi / extract_tar_from_binary.ex
Created April 21, 2019 12:29
Decompressing a tar.gz archive in Elixir with Erlang's :erl_tar module.
@doc"""
Returns a map containing all files and their contents from the compressed tar archive.
"""
def extract_tar_from_binary(binary) do
with {:ok, files} <- :erl_tar.extract({:binary, binary}, [:memory, :compressed]) do
files
|> Enum.map(fn {filename, content} -> {to_string(filename), content} end)
|> Map.new
end
end
@nroi
nroi / postgresql-etl.sql
Last active July 28, 2018 19:17
Various bits and pieces of code that turned out to be useful for the 'Load' step of ETL with PostgreSQL.
-- Various bits and pieces of code that turned out to be useful for the 'Load' step of ETL
-- (i.e., loading big chunks of data into postgres tables).
-- postgres' COPY is more efficient than a bunch of INSERT statements:
\copy table_name (col1, col2, …) from '/path/to/file.txt'
-- If the text file to load the data from is unusually large, it can also be unzipped. Note that, regardless of which of the
-- two methods is used (loading directly from a file or unzipping it first with zcat), this will *not* load the entire file
-- into memory, so this method can also be used for very large files even if both server and client have little memory available.
\copy table_name (col1, col2, …) from program 'zcat /path/to/file.txt.gz'
@nroi
nroi / germany-de-nuts-3-regions.geojson
Last active July 26, 2018 20:09
GeoJSON file of Germany split into its NUTS-3 regions. Source: http://ec.europa.eu/eurostat/de/web/gisco/geodata/reference-data/administrative-units-s © EuroGeographics for the administrative boundariestatistical-units/nuts
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nroi
nroi / MIT-License
Created December 25, 2016 22:12
License for all public gists on https://gist.github.com/nroi
Copyright (c) 2016 Fabian Muscariello
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE U
@nroi
nroi / seeker.py
Created September 8, 2016 20:06
Demonstrate bug in mpd
#!/usr/bin/env python3
import socket
from time import sleep
import sys
hostname = 'alarm.local'
port = 6600
password = 'secret123'