Skip to content

Instantly share code, notes, and snippets.

View detro's full-sized avatar
🇺🇦
I may be slow to respond.

Ivan De Marino detro

🇺🇦
I may be slow to respond.
View GitHub Profile

Latency numbers (cheat sheet)

Operation nanosec microsec millisec notable 1Bx
L1 cache reference 0.5 ns 0.5 s
Branch mispredict 5 ns 5 s
L2 cache reference 7 ns 14x L1 cache 7 s
Mutex lock/unlock 25 ns 25 s
Main memory reference 100 ns 20x L2 cache, 200x L1 cache 1.6 m
Compress 1K bytes with Zippy 3,000 ns 3 µs `5
@detro
detro / build_terraform_for_os_arch.md
Last active July 22, 2022 15:52
Compiling Terraform against a target OS/ARCH, not available from HashiCorp

Background

Sometimes you need a specific version of Terraform a build for your combination of Operating System / Architecture doesn't exist. This can be because that combination came out later than the version of Terraform you are after, or some other reason.

But, no fear, Golang compiler is great, and the Terraform codebase is pretty easy.

Disclaimer

This describes a build process that produces a working binary,

@detro
detro / README.md
Last active May 1, 2020 18:22
Install Folding@Home on your Linux home server

Introduction

If you, like me, want to contribute to Folding@Home from your Linux home server, it takes just few easy steps.

Setup

  1. Create your Folding@Home Passkey here (needed in a sec)
  2. Install the Folding@Home Client (instructions)
  3. Configure it at /etc/fahclient/config.xml
@detro
detro / resolution_error.rs
Created January 8, 2019 19:04
Is there a better way to write this?
use http::Error as HttpError;
use std::{fmt, error};
type Result<T> = std::result::Result<T, ResolutionError>;
/// A type of `Error` emitted by `Resolver`
///
/// It contains a description and an optional `HttpError` that might have caused it
#[derive(Debug)]
@detro
detro / XZCompressorInputStreamAdapter.java
Last active December 1, 2017 18:54
XZCompressorInputStreamAdapter: shows how to overcome a limit in https://commons.apache.org/proper/commons-compress/index.html, that doesn't provide a "compressing" InputStream (the same can be done to create a "decompressing" OutputStream). It avoid the use of any thread and it uses just a single buffer to hold on to data in transition.
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream;
import javax.validation.constraints.NotNull;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Wraps a generic InputStream into a XZ Compressed InputStream.
*
@detro
detro / keybase.md
Created February 12, 2017 18:48
keybase.md

Keybase proof

I hereby claim:

  • I am detro on github.
  • I am ivandemarino (https://keybase.io/ivandemarino) on keybase.
  • I have a public key ASAqluqfdxEe_p__agBOYpFKA_rnlPdZmi3YWIpyt90w8go

To claim this, I am signing this object:

@detro
detro / main.rs
Created December 28, 2015 00:59
Rust very lean way to parse CLI params AND handle error cases
fn main() {
// This might seem like a lot of lines for just catching the 2nd argument,
// parse the string to int and store it in a variable, but what this also covers is
// the absence of such value (first error case) or the non-parsability of the argument (second error case).
//
// I'm liking this stuff so far.
let n = match env::args().skip(1).next() {
Some(x) => match x.parse::<usize>() {
Ok(y) => y,
@detro
detro / 1password.conf
Created August 10, 2015 21:19
1PasswordAnywhere + Dropbox + Upstart = 1Password for Ubuntu
description "Starts a SimpleHTTPServer to host 1 Password Anywhere"
author "Ivan De Marino <detronizator@gmail.com>"
version "1.0.0"
# When to start/stop
start on runlevel [2345]
stop on runlevel [016]
# Keep it running
respawn
private LogEntries getRemoteEntries(String logType) {
Object raw = executeMethod.execute(DriverCommand.GET_LOG, ImmutableMap.of(TYPE_KEY, logType));
@SuppressWarnings("unchecked")
List<Map<String, Object>> rawList = (List<Map<String, Object>>) raw;
List<LogEntry> remoteEntries = Lists.newArrayListWithCapacity(rawList.size());
for (Map<String, Object> obj : rawList) {
remoteEntries.add(new LogEntry(LogLevelMapping.toLevel((String)obj.get(LEVEL)),
(Long) obj.get(TIMESTAMP),
(String) obj.get(MESSAGE)));
@detro
detro / 0_reuse_code.js
Created November 4, 2013 17:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console