Skip to content

Instantly share code, notes, and snippets.

Philipp Keller philippkeller

View GitHub Profile
View test_min_value.sh
min=40000
for i in {1..10000}; do
a=$(./test)
min=$((a<min?a:min));
done
echo $min
View queue_and_workers_read_file_example.py
import multiprocessing
import queue
import time
def worker(input, output):
for line in iter(input.get, None):
output.put(len(line))
if __name__ == '__main__':
num_processes = 3
@philippkeller
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
philippkeller / bench.rs
Created Mar 9, 2017
Benchmarking libc::random vs. XorShiftRng
View bench.rs
#![feature(test)]
#![feature(rand)]
extern crate test;
extern crate rand;
use rand::Rng;
extern "C" {
pub fn random() -> i64;
View running_script.sh
$ python script.py
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
philippkeller / catch_signals.rs
Created Jan 9, 2017
catch SIGINT and SIGTERM and write them into a log file to investigate signal sending
View catch_signals.rs
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"),
View fork_and_mutex.rs
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;
View chan-and-fork.rs
#[macro_use]
extern crate chan;
extern crate chan_signal;
extern crate libc;
use chan_signal::Signal;
use std::thread;
use libc::fork;
fn main() {
View switching-to-windows.md

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

View libcresult.rs
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());
/// }
You can’t perform that action at this time.