Skip to content

Instantly share code, notes, and snippets.

View orende's full-sized avatar

orende orende

View GitHub Profile
@orende
orende / main.rs
Created January 9, 2024 09:27
Functional programming patterns in Rust
#![allow(non_snake_case)]
use derive_builder::Builder; // cargo add derive_builder
use std::time::{SystemTime, Duration};
/// A pure function to reverse a string.
fn reverseString(input: &str) -> String {
let idxs = input.char_indices().rev();
let mut output = String::new();
for (_,c) in idxs {
@orende
orende / build.rs
Created December 1, 2023 09:44
Minimal code to use .tmx and .tsx files with agbrs/agb.
use std::env;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;
use quote::quote;
macro_rules! p {
($($tokens: tt)*) => {
println!("cargo:warning={}", format!($($tokens)*))
@orende
orende / Main.java
Last active September 20, 2023 18:45
All the major features from JDK 21 in one file
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.*;
import java.util.function.Supplier;
import java.util.stream.IntStream;
public class Main {
@orende
orende / splash.py
Last active September 5, 2023 16:25
Splash screen with blocking operation in PygObject and GTK 3
import time
import gi
import threading
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib
class SplashScreen(Gtk.Dialog):
__gtype_name__ = "SplashScreen"
@orende
orende / Java9Features.java
Created September 23, 2017 12:20
De mest intressanta nyheterna i Java 9 sammanfattade i en Java-klass
package se.citerus;
import java.util.Optional;
import java.util.Scanner;
import java.util.concurrent.Flow;
import java.util.concurrent.SubmissionPublisher;
import java.util.stream.IntStream;
public class Java9Features {
@orende
orende / fizzbuzz.kt
Last active September 5, 2023 16:44
Fizzbuzz in Kotlin without if-statements
fun main() {
(1..100).forEach {
"".plus(
"fizz".repeat(it.rem(2).equals(0).compareTo(false)) // convert the bool to an int...
.plus("buzz".repeat(it.rem(3).equals(0).compareTo(false))) // ...and repeat the string 1 or 0 times
.plus(it.toString().repeat(Math.abs((it.rem(2).equals(0) || it.rem(3).equals(0)).compareTo(true)))))
.let { println(it) }
}
}
if (maybeNumber is Number) {
maybeNumber = maybeNumber.plus(2)
}
if (maybeNumber instanceof Integer) {
maybeNumber = ((Integer) maybeNumber).plus(1);
}
data class Result(val result: Int, val status: String)
fun function(): Result {
return Result(200, “OK”)
}
val (result, status) = function()
println("$result $status")
val myMap = mapOf("alfa" to 123, "beta" to 456, "gamma" to 789)
for ((key, value) in myMap) {
print(“$key: $value”)
}