Skip to content

Instantly share code, notes, and snippets.

View saiintbrisson's full-sized avatar
🦀

Luiz Carvalho saiintbrisson

🦀
View GitHub Profile
use std::{marker::PhantomPinned, mem::ManuallyDrop, ops::Deref, pin::Pin};
use flatbuffers::{Follow, ForwardsUOffset, Vector, Verifiable};
fn main() {
let data = vec![0];
let event = OwnedEvent::<Vector<'_, ForwardsUOffset<&str>>>::from(data).unwrap();
let foo = event.get(0);
drop(event);
println!("{foo}");
// Tests the invalid SEQs sent by the listener
// which are then dropped by the client.
`./common/defaults.sh
./common/set_sysctls.py /proc/sys/net/ipv4/tcp_shrink_window=0`
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+0 bind(3, ..., ...) = 0
+0 listen(3, 1) = 0

Aprendendo Rust

Sobre

Rust é uma linguagem de programação de sistemas desenvolvida pela Mozilla, projetada para ser usada no Servo, motor de renderização do Firefox, lançada em 2015, mas anunciada pela primeira vez em 2009, é considerada nova. Destaca-se pela segurança de memória, velocidade e suporte à concorrência, utilizando um sistema de ownership e controle de lifetime das variáveis, evitando bugs comuns sem precisar de um coletor de lixo. A linguagem incorpora vários conceitos da programação funcional, já primeira versão foi escrita em OCaml, e inspirada na mesma. Alguns exemplos:

Imutabilidade por Padrão

let x = 5; // x é imutável por padrão
use std::{
collections::{hash_map::Entry, BTreeSet, HashMap, HashSet},
fs::File,
path::{Path, PathBuf},
};
use memmap2::Mmap;
use smol_str::SmolStr;
fn main() {
package me.saiintbrisson;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
String name = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_";
byte[] encoded = encode(name);
String decoded = decode(encoded);
@saiintbrisson
saiintbrisson / email.rs
Last active April 7, 2021 13:31
Simple email validation
pub enum AreaType {
Quoted,
Unquoted,
}
impl AreaType {
fn is_char_valid(&self, c: char) -> bool {
if matches!(self, AreaType::Unquoted) {
return !matches!(c, '\\' | '"' | '/' | '.' | ',' | ':' | ';' | '(' | ')' | '[' | ']' | '<' | '>');
}
pub enum RangeType {
Unquoted,
SingleQuoted,
DoubleQuoted,
}
pub enum SplitState {
Backslash,
Char,
Empty,
@saiintbrisson
saiintbrisson / regex.txt
Created July 3, 2020 01:22
HTTPS URL Regex
PCRE: ^((?i)https?):\/\/((([\w\-]{1,63})\.)+([\w\-]{1,63}))(\/([\S]*)?)?
JAVASCRIPT: ^([hH][tT][tT][pP][sS]?):\/\/((([\w\-]{1,63})\.)+([\w\-]{1,63}))(\/([\S]*)?)?
import os
import time
import tidalapi
from dotenv import load_dotenv
load_dotenv()
current_milli_time = lambda: int(round(time.time() * 1000))
def get_author_name(author):