Skip to content

Instantly share code, notes, and snippets.

View mitghi's full-sized avatar

Mike Taghavi mitghi

  • Köln, Germany
View GitHub Profile
@mitghi
mitghi / dmfc.py
Created November 20, 2019 06:10
Discrete mathematics in Python
def digits(n):
result = []
l = 0
while n > 0:
d = n % 10
result.insert(0, d)
n = n // 10
l += 1
return (l, result)
@mitghi
mitghi / set.go
Created November 20, 2019 06:18
Set
/* MIT License
*
* Copyright (c) 2018 Mike Taghavi <mitghi[at]gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
@mitghi
mitghi / init.el
Last active January 31, 2020 02:55
Emacs init file
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
(when no-ssl
(warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
@mitghi
mitghi / list.rs
Created August 4, 2021 15:22
Linked List in Rust
use std::fmt;
struct Element<T> {
value: T,
next: Option<Box<Element<T>>>,
}
struct List<T> {
head: Option<Box<Element<T>>>,
}
@mitghi
mitghi / list2.rs
Created August 4, 2021 16:18
Linked List in Rust
use std::fmt;
struct Element<T> {
value: T,
next: Option<Box<Element<T>>>,
}
struct List<T> {
head: Option<Box<Element<T>>>,
@mitghi
mitghi / refcount.rs
Created August 24, 2021 11:44
reference count
use std::rc::Rc;
use std::cell::RefCell;
struct A {
value: Rc<RefCell<Vec<i64>>>,
}
struct B {
value: Rc<RefCell<Vec<i64>>>,
}
@mitghi
mitghi / llist3.rs
Created August 24, 2021 12:43
Linked List in rust
struct Node {
value: i64,
next: Option<Box<Node>>,
}
struct List {
head: Option<Box<Node>>,
}
@mitghi
mitghi / nasty.rs
Created August 28, 2021 08:28
Bad Rust
struct A {
value: *mut i64,
}
impl A {
fn new() -> A {
A{value: std::ptr::null_mut()}
}
}
@mitghi
mitghi / doublili.rs
Created January 13, 2023 21:53
doublili
use std::{rc::{Rc, Weak}, cell::RefCell};
struct Node<T>{
data: T,
next: Option<Rc<RefCell<Node<T>>>>,
prev: Option<Weak<RefCell<Node<T>>>>,
}
struct Doublili<T> {
head: Option<Rc<RefCell<Node<T>>>>,
@mitghi
mitghi / eval.hs
Created March 19, 2023 08:19
stack machine
data Expr = Val Int | Add Expr Expr
data Op = EVAL Expr | ADD Int
value :: Expr -> Int
value e = eval e []
eval :: Expr -> [Op] -> Int
eval (Val n) stack = exec stack n
eval (Add lexpr rexpr) stack = eval lexpr ((EVAL rexpr):stack)