Skip to content

Instantly share code, notes, and snippets.

View berkes's full-sized avatar
🌱
Founding a Startup

Bèr Kessels berkes

🌱
Founding a Startup
View GitHub Profile
@berkes
berkes / keyb-cheat.sh
Created August 20, 2024 12:24
Langtu 69% keyboard cheat sheet
#!/bin/bash
# Function to print the multimedia key table
print_multimedia_table() {
echo "+------------------------------------------------+"
echo "| Win system key combination |"
echo "+------------------------------------------------+"
echo "| Multimedia function keys must be pressed with |"
echo "| the FN+CTRL key combination |"
echo "| (Ice blue light appears underneath the FN |"
#!/bin/bash
current=$(dconf read /org/gnome/desktop/input-sources/xkb-options)
swapped="['caps:swapescape']"
capslock="['caps:capslock']"
echo "Current status: $current"
if [ "$current" == "$swapped" ]
then
echo "Making caps and escape WORK NORMALLY"
@berkes
berkes / main.rs
Created January 27, 2024 19:16
"Benchmarking" some micro optimizations: strange behaviour.
use std::time::Instant;
fn main() {
let iterations = 1_000_000;
let mut odd_count = 0;
// Using modulus
let start_modulus = Instant::now();
for i in 0..iterations {
if i % 2 != 0 {
@berkes
berkes / python_iterators.py
Created February 9, 2024 12:18
One-line to multiline block iterators
from itertools import chain, repeat
# Define the inventory as a dictionary
inventory = {
"banana": 3,
"apple": 2,
"pear": 1,
"berry": 4,
}
<div class="block content has-background-light p-4">
<strong>Discussions around the web:</strong>
<div id="comment" data-discussion-url="https://www.joelonsoftware.com/2000/04/06/things-you-should-never-do-part-i">
<ul></ul>
</div>
<p class="pt-2">Powered by <a href="https://discu.eu">discu.eu</a>.</p>
</div>
@berkes
berkes / final.rs
Last active October 4, 2022 13:30
mod domain {
use std::{fmt::Display, ops::Deref};
#[derive(Debug)]
pub enum DomainError {
InvalidEmailAddress,
InvalidResponseCode,
}
#[derive(Clone, PartialEq)]
@berkes
berkes / main.rs
Created October 4, 2022 09:56
ViewCount With Sum
mod domain {
use std::ops::Deref;
pub struct ViewCount { value: usize }
impl ViewCount {
pub fn new(value: usize) -> Self {
Self { value }
}
}
struct Point {
x: usize,
y: usize
}
@berkes
berkes / main.rs
Created October 4, 2022 09:55
ViewCount Example
mod domain {
pub struct ViewCount {
value: usize,
}
impl ViewCount {
pub fn new(value: usize) -> Self {
Self { value }
}
pub fn value(&self) -> usize {
self.value
impl PageSize {
pub fn new_from_kilobytes(value: usize) -> Result<Self, DomainError> {
Ok(Self { value })
}
pub fn as_bytes(&self) -> usize {
&self.value / 1_000
}
pub fn as_kilobytes(&self) -> usize {
self.value
}