Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View taqtiqa-mark's full-sized avatar

Mark Van de Vyver taqtiqa-mark

View GitHub Profile
@taqtiqa-mark
taqtiqa-mark / newtype_pattern.rs
Created March 31, 2022 06:23 — forked from nyinyithann/newtype_pattern.rs
The newtype pattern with Deref/DerefMut trait implementation
/*
To implement a trait on a type, the trait or the type has to be local to the code you work on. It is called the orphan rule.
To get around this restriction, we can use the newtype pattern which involves creating a new type in a tuple struct.
Both Vec<T> and Display trait are from the standard library and neither is local to our code.
We are not able to implement Display trait to Vec<T>. But we can construct a wrapper type holding an instance of Vec<T> and implement Display trait on it.
In the following example, VecWrapper<T> struct wraps Vec<T> and implements Display trait.
To get all the methods of Vec<T> available to VecWrapper, Deref trait is implemented on it.
ref: https://doc.rust-lang.org/book/ch19-03-advanced-traits.html?search=borrow%20and%20asref
*/
@taqtiqa-mark
taqtiqa-mark / mre-tracing.rs
Created October 25, 2021 22:46
Tracing setup for Tokio+Hyper trace output
```rust
async fn main() {
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 6831));
// Build a Jaeger batch span processor
let jaeger_processor = opentelemetry::sdk::trace::BatchSpanProcessor::builder(
opentelemetry_jaeger::new_pipeline()
.with_service_name("mre-jaeger")
.with_agent_endpoint(addr)
// Issue #
.with_trace_config(opentelemetry::sdk::trace::config().with_resource(
@taqtiqa-mark
taqtiqa-mark / rust-backtrace-issue-88148.log
Created August 19, 2021 00:29
Rust backtrace: issue #88148
This file has been truncated, but you can view the full file.
error: BUG: failed to parse .ll file; please submit a bug report with Rust source code. Details (include the _first_ LLVM item, e.g. `define .. { .. }`, in the report):
Failure(("define internal fastcc void @_ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h8e015ee00e90a135E(void ()* nocapture nonnull %f) unnamed_addr #1 personality i32 (i32, i32, i64, %\"unwind::libunwind::_Unwind_Exception\"*, %\"unwind::libunwind::_Unwind_Context\"*)* @rust_eh_personality {\nstart:\n %dummy.i = alloca {}, align 1\n tail call void %f()\n %0 = bitcast {}* %dummy.i to i8*\n call void @llvm.lifetime.start.p0i8(i64 0, i8* nonnull %0)\n call void asm sideeffect \"\", \"r,~{memory},~{dirflag},~{fpsr},~{flags}\"({}* nonnull %dummy.i) #32, !srcloc !29\n call void @llvm.lifetime.end.p0i8(i64 0, i8* nonnull %0)\n ret void\n}\n\n; std::sync::once::Once::call_once::{{closure}}\n; Function Attrs: inlinehint nonlazybind uwtable\ndefine internal void @\"_ZN3std4sync4once4Once9call_once28_$u7b$$u7b$closure$u7d$$u7d$17h4e
0.000000 execve("/usr/local/bin/packer", ["packer"], 0x7ffe34f913c8 /* 189 vars */) = 0
0.000627 arch_prctl(ARCH_SET_FS, 0x7f17990) = 0
0.000122 sched_getaffinity(0, 8192, [0, 1]) = 8
0.000079 openat(AT_FDCWD, "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", O_RDONLY) = 3
0.000102 read(3, "2097152\n", 20) = 8
0.000052 close(3) = 0
0.000226 uname({sysname="Linux", nodename="desktop.local.lan", ...}) = 0
0.000063 openat(AT_FDCWD, "/proc/version", O_RDONLY) = 3
0.000055 read(3, "Linux version 5.4.0-54-generic ("..., 512) = 157
0.000288 close(3) = 0
0.000000 execve("/usr/local/bin/packer", ["packer"], 0x7fff34d639d8 /* 189 vars */) = 0
0.060214 arch_prctl(ARCH_SET_FS, 0x7d24bb0) = 0
0.117569 sched_getaffinity(0, 8192, [0, 1]) = 8
0.000099 openat(AT_FDCWD, "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", O_RDONLY) = 3
0.000081 read(3, "2097152\n", 20) = 8
0.000065 close(3) = 0
0.000041 uname({sysname="Linux", nodename="desktop.local.lan", ...}) = 0
0.000052 openat(AT_FDCWD, "/proc/version", O_RDONLY) = 3
0.000056 read(3, "Linux version 5.4.0-54-generic ("..., 512) = 157
0.000044 close(3) = 0
@taqtiqa-mark
taqtiqa-mark / gist:7d301f7ab6fcef1987dd6b34f8803819
Created January 29, 2020 20:26
droplet discovery over digitalocean private networks

Digital Ocean recently released private networking support in their NYC2 Data center.

They also published a blog post on how to setup a new droplet with private networking. But one thing the post doesn't do is tell you how to scale your private network for many boxes. One approach is obviously to edit /etc/hosts (but this gets annoying when you add a new box). A better way is to create an internal DNS zone (via the digital ocean web interface) and have your droplets use it:

Steps

setup the internal DNS zone file

  1. Login to digital ocean
  2. Click "DNS" on the right hand menu
@taqtiqa-mark
taqtiqa-mark / gist:9bb2f807f2f607bdb2e1402a59370eeb
Created January 29, 2020 20:25 — forked from so0k/gist:cdd24d0a4ad92014a1bc
droplet discovery over digitalocean private networks

Digital Ocean recently released private networking support in their NYC2 Data center.

They also published a blog post on how to setup a new droplet with private networking. But one thing the post doesn't do is tell you how to scale your private network for many boxes. One approach is obviously to edit /etc/hosts (but this gets annoying when you add a new box). A better way is to create an internal DNS zone (via the digital ocean web interface) and have your droplets use it:

Steps

setup the internal DNS zone file

  1. Login to digital ocean
  2. Click "DNS" on the right hand menu
@taqtiqa-mark
taqtiqa-mark / ...headless.rb
Last active December 11, 2015 23:29
Config DSL example use case (Vagrant)
vm.customize do |cvm|
cvm.memory_size = 1024
cvm.vram_size = 12
cvm.cpu_count = 2
cvm.accelerate_3d_enabled = false
cvm.accelerate_2d_video_enabled = false
cvm.monitor_count = 1
cvm.bios.acpi_enabled = true
cvm.bios.io_apic_enabled = false
@taqtiqa-mark
taqtiqa-mark / install.sh
Last active December 11, 2015 06:48 — forked from kysnm/install.sh
ubuntu lucid: install tmux 1.7
#!/usr/bin/env bash
export TMUX_INSTALL_VERSION=1.6
wget -q -O - "https://gist.github.com/raw/4561674/install_tmux_${TMUX_INSTALL_VERSION}_on_ubuntu_10.04.sh" | sudo bash
@taqtiqa-mark
taqtiqa-mark / traceroute.txt
Created January 4, 2013 01:50
traceroute when AWS CF distribution is inaccessible.
Every 0.1s: traceroute www.cookbooks.io. Fri Jan 4 12:45:35 2013
traceroute to www.cookbooks.io. (54.240.176.220), 30 hops max, 60 byte packets
1 192.168.1.1 (192.168.1.1) 2.170 ms 2.693 ms 3.721 ms
2 10.1.1.1 (10.1.1.1) 3.922 ms 4.627 ms 4.852 ms
3 nexthop.nsw.iinet.net.au (203.215.19.247) 19.622 ms 19.895 ms 21.551 ms
4 te1-1.syd-mas-bdr2.iinet.net.au (203.215.18.20) 22.949 ms te1-1.syd-mas-bdr1.iinet.net.au (203.215.18.18) 27.372 ms 27.608 ms
5 xe-1-1-0-0.syd-mas-core1.iinet.net.au (203.215.20.94) 28.053 ms 29.516 ms te1-2.syd-mas-bdr1.iinet.net.au (203.215.20.153) 31.803 ms
6 xe-1-1-0-0.syd-mas-core1.iinet.net.au (203.215.20.94) 32.698 ms te7-0-0.bdr1.syd4.internode.on.net (150.101.197.189) 19.010 ms xe-1-1-0-0.syd-mas-core1.iinet.net.au (203.215.20.94) 71.439 ms
7 gi7-0-0-100.bdr1.syd4.internode.on.net (150.101.197.153) 18.504 ms 21.391 ms 22.368 ms