Skip to content

Instantly share code, notes, and snippets.

View kriogenia's full-sized avatar

Soto Estévez kriogenia

View GitHub Profile
@kriogenia
kriogenia / graph.gist
Last active January 15, 2020 15:53
ESPAÑ4J
= ESPAÑ4J
:neo4j-version: 2.3.0
:author: Andrea López Suárez, Manuel Lorenzo Vega, Ricardo Soto Estévez
Para la realización de este trabajo hemos decidido elegir como dominio de la aplicación una representación del mapa de España, empleando sus provincias y sus relaciones fronterizas, añadiendo además que lenguas se hablan en ellas, con que mares limitan y las comunidades autónomas a la que pertenecen.
image::https://i.imgur.com/qZ4pkmf.jpg[]
image::https://i.imgur.com/n7z4dxW.jpg[]
@kriogenia
kriogenia / student_record_u8.rs
Last active May 16, 2022 17:58
Generics on Rust - StudentRecord Non-Generic
use std::collections::HashMap;
pub struct StudentRecord {
student_id: u32,
marks: Vec<u8>,
}
impl StudentRecord {
pub fn new(student_id: u32) -> Self {
Self {
@kriogenia
kriogenia / student_record.rs
Created May 16, 2022 18:00
Generics on Rust - StudentRecord Generic No-Extra
use std::collections::HashMap;
pub struct StudentRecord<T> {
student_id: u32,
marks: Vec<T>,
}
impl<T> StudentRecord<T> {
pub fn new(student_id: u32) -> Self {
Self {
@kriogenia
kriogenia / main.rs
Last active May 18, 2022 15:11
Generify with compiler errors - Starting function
fn sum(numbers: &[i32]) -> i32 {
let mut total = numbers[0];
for i in numbers.into_iter().skip(1) {
total += *i;
}
total
}
fn main() {
let numbers = vec![23, -4, 3, 10];
@kriogenia
kriogenia / main.rs
Last active May 18, 2022 15:14
Generify with compiler errors - No bounds function
fn sum<T>(numbers: &[T]) -> T {
let mut total = numbers[0];
for i in numbers.into_iter().skip(1) {
total = total + *i;
}
total
}
@kriogenia
kriogenia / main.rs
Created May 18, 2022 15:40
Generify with compiler errors - Adding starting with zero
fn sum<T>(numbers: &[T]) -> T
where
T: Add<Output = T> + Copy + Zero,
{
let mut total: T = T::zero();
for i in numbers.into_iter() {
total = total + *i;
}
total
}
@kriogenia
kriogenia / main.rs
Last active May 18, 2022 16:05
Generify with compiler errors - Bounded function
fn sum<T>(numbers: &[T]) -> T
where
T: Add<Output = T> + Copy,
{
let mut total = numbers[0];
for i in numbers.into_iter().skip(1) {
total = total + *i;
}
total
}
@kriogenia
kriogenia / main.rs
Last active June 3, 2022 11:43
if let
fn overflow(n: i32, max: i32) -> Option<i32> {
if n > max {
Some(n - max)
} else {
None
}
}
fn main() {
let n = 15;
@kriogenia
kriogenia / main.rs
Last active June 3, 2022 12:19
Result alias
enum ReadingError {
OutOfBounds,
InvalidBuffer
}
trait InsteadOfThis {
fn next_char() -> Result<u8, ReadingError>;
fn next_line() -> Result<String, ReadingError>;
fn char_at(pos: usize) -> Result<u8, ReadingError>;
}
@kriogenia
kriogenia / main.rs
Created June 3, 2022 12:28
include_str and include_bytes
const TOKEN_AS_STR: &'static str = include_str!("./token.txt");
const TOKEN_AS_BYTES: &[u8] = include_bytes!("./token.txt");
fn main() {
assert_eq!("HelLoWoRLd", TOKEN_AS_STR);
assert_eq!("HelLoWoRLd".as_bytes(), TOKEN_AS_BYTES);
}