Skip to content

Instantly share code, notes, and snippets.

View themisir's full-sized avatar
🐒
monke sees, monke does

Misir themisir

🐒
monke sees, monke does
View GitHub Profile
@themisir
themisir / lifetimes.md
Last active September 8, 2023 08:34
article draft

Lifetimes

Just mark it with '_, 'a or 'static and hope one of them works was my first go-to solutions when dealign with rust borrow checker. I had no clue what lifetimes meant to represent, or how their values are inferred since unlike type generics there's not a single point where the type can be inferred from the context.

let mut values = Vec::new();
values.push(Route { path: "/home" });

There, the second line calls Vec::push(&mut self, value: T) function with a value of Route { path: "/home" } which is an instance of the type Route. There compiler can infer that the type argument T can be implicitly set to Route and fill the missing gaps for us. You might be thinking, what if you wanted to store different implementations of Route, aka how does it deal with inheritance. The answer is, we don't need to worry about that because rust doesn't have a concept of inheritance. As a matter of fact, it is completely unnecessary in this context, since we are dealing with data not

@themisir
themisir / vm.awk
Last active April 16, 2023 14:28
A Turing complete virtual machine implementation with AWK..
#!/usr/bin/awk -f
BEGIN {
split("", stack);
split("", locals);
split("", lookback);
split("", labels);
skip_ops = 0;
// Translated from https://github.com/leeoniya/transformation-matrix-js/blob/master/src/matrix.js
export class Matrix {
public constructor(
private readonly a: number,
private readonly b: number,
private readonly c: number,
private readonly d: number,
private readonly e: number,
private readonly f: number
@themisir
themisir / systemctl.md
Created October 17, 2022 22:36 — forked from adriacidre/systemctl.md
Systemctl Cheatsheet

Service Management

Starting and Stopping Services

Starting

sudo systemctl start application.service

or simply

sudo systemctl start application
@themisir
themisir / README.md
Last active November 13, 2021 18:54
Add dark mode to your flutter apps within seconds

Darkest

Place Darkest widget above widgets (or pages) you want to enable dark mode for. And it magically makes your app use state of art technology powered by latest Machine Learning trends to convert graphics into dark mode compatible style.

Darkest(
  enabled: true,
 child: MyWidget(),
@themisir
themisir / Task.kt
Created June 26, 2021 18:20
Simple abstraction on top of java.util.Timer for scheduling one time and periodic actions
package com.themisir.utils
import java.util.*
class Task(private val timer: Timer) {
companion object {
fun schedule(delay: Long, func: () -> Unit): Task {
return Task(Timer().also {
it.schedule(createTimerTask(func), delay)
})
bool matchesWithoutNormalization(String url, String baseUrl) {
return url.startsWith(baseUrl);
}
bool matchesWithNormalization(String url, String baseUrl) {
if (!baseUrl.endsWith('/')) baseUrl = '$baseUrl/';
return url.startsWith(baseUrl);
}
void main() {
typedef Func<T> = T Function();
abstract class ServiceDefinition<T> {
factory ServiceDefinition.singleton(T instance) = _SingletonServiceDefinition;
factory ServiceDefinition.factory(Func<T> create) = _FactoryServiceDefinition;
const ServiceDefinition._();
T instantiate();
bool matches<E>() => E == T;
@themisir
themisir / models.dart
Created October 29, 2020 13:03
Quran in Dart
class Surah {
final String arabic;
final String latin;
final int verseCount;
final int index;
final String type;
final List<Verse> verses;
const Surah({
this.type,
@themisir
themisir / README.md
Last active October 25, 2020 18:37
Telegram web full width

Telegram Web Tweak Script

This script makes sure telegram web to use full screen width by replacing styles. The script works with scripting utilities like TamperMonkey.

Click this link to install user script.