Skip to content

Instantly share code, notes, and snippets.

View svantelidman's full-sized avatar

Svante Lidman svantelidman

  • Stockholm, Sweden
View GitHub Profile
@svantelidman
svantelidman / java_scheduling_kubernetes.md
Created December 2, 2018 18:13
What do the resource requests and limits mean in OpenShift and how might they effect your Java application?

What do the resource requests and limits mean in OpenShift and how might they effect your Java application?

Java resource management

To the extent it is implementation specific the discussion below is based on the OpenJDK HotSpot runtime.

Threads

The JVM maps threads in Java to OS threads 1:1 , i.e., there are no "green threads" in Java like there are in some other virtual machines, for example BEAM, the Erlang virtual machine.

A thread in the JVM can be in one of the following states:

  • thread_new: a new thread in the process of being initialized
@svantelidman
svantelidman / Base64.md
Created April 12, 2019 13:08 — forked from barrysteyn/Base64.md
OpenSSL Base64 En/Decode: Portable and binary safe.

OpenSSL Base64 Encoding: Binary Safe and Portable

Herewith is an example of encoding to and from base64 using OpenSSL's C library. Code presented here is both binary safe, and portable (i.e. it should work on any Posix compliant system e.g. FreeBSD and Linux).

License

The MIT License (MIT)

Copyright (c) 2013 Barry Steyn

@svantelidman
svantelidman / day2.rs
Last active December 2, 2019 22:15
Advent of code 2019 day 2
use std::io::{self, BufRead};
fn main() {
let mut loaded_program: Vec<i32> = load_program();
run_program(&mut loaded_program);
println!("{}", loaded_program[0]);
}
fn run_program(program: &mut Vec<i32>) -> i32 {
use std::io::{self, BufRead};
fn main() {
let (w1, w2) = load_wires();
let tw1 = transform_wire(&w1);
let tw2 = transform_wire(&w2);
let intersections = find_intersections(tw1, tw2);
let dist = find_min_distance(&intersections);
println!("Min distance: {}", dist);
let steps = find_min_steps(&intersections, &w1, &w2);
fn main() {
let range = 235741..=706948;
let n_matches = range.into_iter().filter(|n| match_criteria(*n)).count();
println!("Number of matches: {}", n_matches)
}
fn match_criteria(candidate: i32) -> bool {
let n1 = candidate % 10;
let n2 = (candidate / 10) % 10;
let n3 = (candidate / 100) % 10;
use std::io::{self, BufReader, BufRead};
use std::env;
use std::fs::File;
fn main() {
let args: Vec<String> = env::args().collect();
let program_file = &args[1];
let mut loaded_program: Vec<i32> = load_program(program_file);
run_program(&mut loaded_program);
use std::io::{BufReader, BufRead};
use std::env;
use std::fs::File;
use std::collections::HashMap;
fn main() {
let args: Vec<String> = env::args().collect();
let orbit_file = &args[1];
let orbits = load_orbits(orbit_file);
let com = planet_code("COM");
use std::io::{BufReader, BufRead};
use std::env;
use std::fs::File;
use std::collections::HashSet;
fn main() {
let args: Vec<String> = env::args().collect();
let program_file = &args[1];
let program: Vec<i32> = load_program(program_file);
const INPUT: &str = "2222220220222222222220222222221221222222122221222220222122222022222222212221222210222222222020222202222222222220202222220022222222222222002222222022202222222220222222222221222222220220222222022222222221222122222022222222002221222220222222222222222222222222222222222222222222222222222222012222222222220222222220222222122221222220221222222222122221222222222122222022222222202221222212222222222220222222222222222221102222220222222222222222212222222222202222220221222222022222222222220221222222122221222221222022222022222222002222222200222222222221222222222222222220102222222122222222222222102222222122211222222221222222122222222222220222222222022221202222222122222122222222002222222201222222222222222212222222222222122222220222222222222222022222222222221222221220222222122222222221221221222222122222222222222122222222222222122222222222222222222221222212222222222221022222221122222222222222112222222022201222220222222222222222222222222220222222122220212221222022222022222222002222222202222222222021222202222
use std::io::{BufReader, BufRead};
use std::fs::File;
fn main() {
let program_file = "prog".to_string();
let program: Vec<i64> = load_program(&program_file);
let mut machine = Machine {
prog_ptr: 0,
relative_base: 0,