Skip to content

Instantly share code, notes, and snippets.

View Enet4's full-sized avatar

Eduardo Pinho Enet4

View GitHub Profile
@Enet4
Enet4 / youtube-transcription-IbDAmvUwo5c.md
Last active December 7, 2021 16:28
Transcription to YouTube video "The Tyrannical Mods of Stack Overflow"

00:00 - It starts by showing this question and reading it out loud

0:00 - "I have this string. I want to split it on the pipe, but I don't know how. I don't want to split it at the white-space, only at the pipe. Is this possible?"

0:10 - The comments below the question are presented and read out loud:

Is it Programming?

  • Execution

    • Purist: executed by a machine with a generic processor
    • Neutral: executed by some machine
    • Chaotic: executed by something or someone
  • Purpose

    • Purist: well defined goal with well known requirements
  • Neutral: well defined goal with vague requirements

@Enet4
Enet4 / dicom-rs-findscu.rs
Created July 4, 2021 15:29
FIND SCU for DICOM-rs, draft
use dicom::core::smallvec;
use dicom::{core::dicom_value, dictionary_std::tags};
use dicom::{
core::{DataElement, PrimitiveValue, VR},
encoding::transfer_syntax,
object::{mem::InMemDicomObject, open_file, StandardDataDictionary},
transfer_syntax::TransferSyntaxRegistry,
};
use dicom_ul::pdu::Pdu;
use dicom_ul::{

Most examples in the SNAFU guide show the following pattern:

#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
    #[snafu(display("Could not read data set token: {}", source))]
    #[non_exhaustive]
    ReadToken {
        #[snafu(backtrace)]
// Best real time: 0.46s
use std::fs::File;
use std::io::{BufRead, BufReader};
fn is_blank(s: &str) -> bool {
s.chars().all(|c| c.is_whitespace())
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = File::open("biggest.txt")?;
// Best real time: 0.80 s
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <clocale>
#include "utf8.h"
using namespace std;
@Enet4
Enet4 / is_blank.py
Last active November 7, 2019 20:12
# Best real time: 2.05 s
def is_blank(s):
return not s or s.isspace()
k = 0
for line in open("biggest.txt"):
if is_blank(line):
k += 1
@Enet4
Enet4 / migrating-safe-transmute-0.11.md
Last active June 24, 2019 13:58
Migrating safe-transmute to 0.11

This guide starts with a forewarning: safe-transmute had many safety issues before this version, which means that there is a chance of your dependent project facing undefined behavior. Migrating to version 0.11 is recommended as soon as possible, even if it might lead to a sub-optimal solution.

Organization

The crate is now organized with the following major categories:

  • base contains all baseline conversion functions. They are only protected against out of boundary access, like trying to create an 8-byte type from 7 bytes. However, they are still unsafe: any
@Enet4
Enet4 / with_order.md
Last active December 11, 2018 18:00
byteordered::with_order macro rendered docs
macro_rules! with_order {
( ($($src: expr ),*), $endianness: expr, |$($bo: ident ),*| $e: expr ) => { ... }
($src: expr, $endianness: expr, |$bo: ident| $e: expr ) => { ... }
}

Creates a scope for reading or writing with run-time byte order awareness.

The condition of whether to read or write data in big endian or little

@Enet4
Enet4 / index_gpu_use.rs
Created April 12, 2018 19:59
usage of an index on both cpu and gpu in faiss-rs
let res = StandardGpuResources::new()?;
// create an index and place it on GPU memory
let mut index = index_factory(8, "Flat", MetricType::L2)?
.into_gpu(&res, 0)?;
index.add(get_data())?;
let my_query = get_query();
let result = index.search(&my_query, 5)?;
assert_eq!(result.labels, vec![2, 1, 0, 3, 4]);