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. |
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
!! | |
!! f2py -c -m search search.f90 | |
!! | |
subroutine find_first(needle, haystack, haystack_length, index) | |
!! | |
!! Find the first index of `needle` in `haystack`. | |
!! | |
implicit none |
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 |
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: |
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: |
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; |
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 |
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; | |
} |
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 {} |
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 = '' |
NewerOlder