Skip to content

Instantly share code, notes, and snippets.


Philipp Keller philippkeller

View GitHub Profile
for i in {1..10000}; do
echo $min
import multiprocessing
import queue
import time
def worker(input, output):
for line in iter(input.get, None):
if __name__ == '__main__':
num_processes = 3
philippkeller / Default (Windows).sublime-keymap
Created Jun 1, 2017
Make Sublime Keybindings on Windows same as on MacOS
View Default (Windows).sublime-keymap
* these keybindings are taken over from OSX with:
* - super (aka mac key) replaced by alt (because alt is at the same position as the mac key)
* - keybindings with super+alt removed (except the layout keycombos like super-alt-2 to make two columns are replaced by alt-2, etc.)
* - ctrl-a, ctrl-e, etc which are provideed by Mac (aka Emacs keybindings) are added additionally
* - fixed some of the keybindings commands (e.g. on Windows it's prompt_open_file, on Mac it was prompt_open)
/* "Emacs" keybindings which come on mac but not on windows, added "by hand" */
{ "keys": ["ctrl+a"], "command": "move_to", "args": {"to": "bol", "extend": false} },
philippkeller /
Created Mar 9, 2017
Benchmarking libc::random vs. XorShiftRng
extern crate test;
extern crate rand;
use rand::Rng;
extern "C" {
pub fn random() -> i64;
$ python
Printing current values ...
Object a contains value 1
Object b contains value 2
Writing data for loop number 0 ...
Change json data (y/n) ? --type 'exit' to quit-- : y
philippkeller /
Created Jan 9, 2017
catch SIGINT and SIGTERM and write them into a log file to investigate signal sending
extern crate libc;
use libc::{c_int, SIGTERM, SIGINT, SIG_ERR, signal, pause};
use std::fs::OpenOptions;
use std::io::Write;
fn sig(sig:c_int) {
let mut file = OpenOptions::new().append(true).open("/tmp/signals.txt").expect("cannot open");
match sig {
SIGINT => file.write_all(b"sigint\n"),
extern crate libc;
use std::sync::mpsc::channel;
use std::sync::{Arc, Mutex};
use libc::{fork, setbuf, c_char, c_int, STDOUT_FILENO, fdopen, usleep, FILE};
const N: usize = 10;
extern "C" {
pub fn putc(arg1: c_int, arg2: *mut FILE) -> c_int;
extern crate chan;
extern crate chan_signal;
extern crate libc;
use chan_signal::Signal;
use std::thread;
use libc::fork;
fn main() {

bottom line: Life is too short to switch OS for no obvious reason

path to windows from mac

what I liked while trying to switch

pub trait LibcResult<T> {
/// returns None if the result is empty (-1 if an integer, Null if a pointer)
/// and Some otherwise
/// # Example
/// if let Some(fd) = libc::creat(fd1, FILE_MODE).to_option() {
/// fd
/// } else {
/// panic!("{}", io::Error::last_os_error());
/// }