View rust_snippet_runner.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rsr() {( | |
## | |
## Use 'runner' on a string instead of a file. | |
## | |
## If code is on stdin, all arguments are passed on. Otherwise, | |
## arg1: the string to run | |
## arg2+: passed on to the executable | |
## | |
## Examples: | |
## rsr 'println!("{}", "hi");' my_arg |
View python_release.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function python_release() { | |
## | |
## Upload a new release for a python package | |
## | |
## Requirements: | |
## - ~/.pypirc exists and contains both testpypi and pypi | |
## - Active virtual environment | |
## - setup.py exists | |
## | |
## Besides the above, will verify that: |
View json2table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Render json as a text table. | |
Input should be a list of dictionaries: | |
[{"name": "first", "a": 1, "b": null, "x": true}, {"b": 2, "name": "second", "x": false}, {"a": 123, "name": "third", "x": null}] | |
Output will be a table: |
View rs_ws_ssl_server_client.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate env_logger; | |
#[macro_use] | |
extern crate log; | |
extern crate openssl; | |
extern crate proc_macro; | |
extern crate url; | |
extern crate ws; | |
use std::collections::HashMap; | |
use std::fs::File; |
View parallel_map.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate num_cpus; | |
extern crate scoped_pool; | |
use scoped_pool::Pool; | |
use std::fmt::Debug; | |
use std::sync::mpsc::sync_channel; | |
use std::vec::Vec; | |
/// Transform a collection to another collection using a closure, | |
/// with execution happening in parallel on a new thread pool with one thread per cpu. |
View voronoi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This divides the images in small patches by means of minimal distance to random points. | |
It then computes the average color of each patch, and gives the whole patch that color. | |
This code is NOT fast, O(N^2) for N number of pixels (~1min). It's pretty short and easy though. | |
""" | |
from random import randint, seed | |
from time import time | |
from matplotlib.pyplot import subplots, show |
View rust_modulo_from_rem.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Define a modulo operation, in the mathematical sense. | |
/// This differs from Rem because the result is always non-negative. | |
pub trait Modulo<T> { | |
type Output; | |
#[inline] | |
fn modulo(self, other: T) -> Self::Output; | |
} |
View playground.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unfortunately no polymorphism | |
struct Alpha {} | |
trait Beta { | |
fn p(&self, z: &Beta) -> bool; | |
} | |
trait Gamma: Beta {} |
View identifier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Encode/decode an incrementing integers as an alphanumeric identifier. | |
Uses digits and case-insensitive letters (produces caps, accepts both), minimum length 3. | |
Does not cryptographically hide the original id. | |
""" | |
def to_code(nr): | |
assert nr >= 0 | |
nr *= 7 | |
code = '' |
View django-bootstrap4-field-errors.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bootstrap4.renderers import FormRenderer, FieldRenderer | |
from bootstrap4.text import text_value | |
class FieldErrorFormRenderer(FormRenderer): | |
""" | |
Adapted version of Bootstrap 4 FormRenderer, that shows error messages | |
at the field, rather than at the top. | |
""" |
NewerOlder