Skip to content

Instantly share code, notes, and snippets.

View barafael's full-sized avatar
💭
fighting the red and yellow squiggles

Rafael Bachmann barafael

💭
fighting the red and yellow squiggles
View GitHub Profile
@barafael
barafael / monster.java
Created June 21, 2016 17:20
Stream monstrosity
private static Map<Integer, List<Integer>> makeFriendlists(List<Map<String, List<Integer>>> hashes) {
Map<Integer, List<Integer>> result = new ConcurrentHashMap<>(); // concurrent put might happen in parallelstream
// 1.: parallel stream all maps in list
// 2.: parallel stream all entries in entrysets of hashes
// 3.: for each entry in streamed hash, add it to the index list
hashes.parallelStream().map(hashmap -> hashmap.entrySet().parallelStream())
.forEach(entries -> entries.forEach(e -> {
List<Integer> friends = e.getValue();
for (Integer index : friends) {
if (result.containsKey(index)) {
@barafael
barafael / main.rs
Created February 8, 2017 22:37
Attempting to link to extern C code in this simple rust echo program
extern crate rustyline;
use rustyline::error::ReadlineError;
use rustyline::Editor;
#[link(name = "mpc")]
extern {
fn mpc_new(s: &str) -> *mut mpc_parser_t;
}
fn main() {
@barafael
barafael / main.rs
Last active March 22, 2017 14:04
Simplified rust ownership problem
mod timesheet;
fn main() {
let mut ts = timesheet::Session::new();
println!("{:?}", ts);
}
@barafael
barafael / main.rs
Created March 23, 2017 17:13
Calling external git command 'git config user.email'
use std::process::Command;
fn main() {
println!("{}", git_name().unwrap_or("".to_string()));
}
pub fn git_name() -> Option<String> {
let output = Command::new("git")
.arg("config user.name")
@barafael
barafael / main.rs
Created March 23, 2017 18:19
Confused about error handling
use std::process::Command;
fn main() {
println!("{}", git_name().unwrap_or("".to_string()));
}
pub fn git_name() -> Option<String> {
let output = Command::new("git")
.arg("config")
#[macro_use]
extern crate clap;
#[macro_use]
extern crate serde_derive;
mod timesheet;
fn main() {
//! # Toolbar, Scrollable Text View and File Chooser, Cairo Widget
extern crate gtk;
extern crate cairo;
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::File;
use gtk::DrawingArea;
class ModelSerializer implements JsonSerializer<FHEMModel> {
private final List<String> permissions;
public ModelSerializer(List<String> permissions) {
this.permissions = permissions;
}
@Override
public JsonElement serialize(FHEMModel model, Type type, JsonSerializationContext jsc) {
/* All the other adapters set non-permitted or empty fields to null */
@barafael
barafael / test.json
Created July 12, 2017 13:36
incorrect json file
{
"Identifier": [
{
"name": "incorrectJSON",
"note": "the comma",
},
]
}
#include <Servo.h>
// Assign your channel in pins
#define THROTTLE_IN_PIN 8
volatile uint16_t unThrottleInShared;
uint32_t ulThrottleStart;
void setup()