Skip to content

Instantly share code, notes, and snippets.

View Mec-iS's full-sized avatar

Lorenzo Mec-iS

View GitHub Profile
@Mec-iS
Mec-iS / socket_echo_server.rs
Created February 2, 2023 17:12
An echo server using Polling (Rust)
use std::collections::HashMap;
use std::net::{TcpListener, TcpStream};
use std::os::unix::io::AsRawFd;
use nix::sys::socket::{setsockopt, sockopt::Nonblock};
use nix::poll::{poll, PollFd, EventFlags};
const STATE_REQ: u32 = 0;
const STATE_RES: u32 = 1;
const STATE_END: u32 = 2;
package main
import(
"fmt"
"math/rand"
"os"
"strconv"
"time"
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# -*- coding: utf-8 -*-
__doc__ = """Fast hierarchical clustering routines for R and Python
Copyright © 2011 Daniel Müllner
<http://math.stanford.edu/~muellner>
This module provides fast hierarchical clustering routines. The "linkage"
method is designed to provide a replacement for the “linkage” function and
its siblings in the scipy.cluster.hierarchy module. You may use the methods
in this module with the same syntax as the corresponding SciPy functions but
@Mec-iS
Mec-iS / definition_of_truth.md
Last active August 23, 2022 18:58
Truth as Eigenform

Definition of Truth

Jason the Goodman <jasonthegoodman@....com>:

How about defining "truth" with "stability" of the coupling loop between "the object" and the cognitive system coupling with the "object"? If the process stabilizes and an eigenvalue of the loop emerges, we say "a truth" is found. This would refocus our attention from the "object" itself to the nature of the cognitive system, which may include animals and robots in addition to humans. My tentative way to upgrade from first-order thinking to the second-order thinking. Then, instead of searching for "truth", we search for the "Lyapunov potential function" for the situation if we could find one...

Louis H Kauffman <kauffman@....edu>

Eigenform is important way to formalize a kind of stability. Truth is a special kind of eigenform, not just any eigenform. Truth means the truth of a PROPOSITION about something. So we need to have a language involved and the notion that the propositions are talking about some domain where it is possible to c

@Mec-iS
Mec-iS / python-ext-wasmer-1_0.md
Last active May 24, 2019 11:21
Requirements for python-ext-wasmer

Ideas for python-ext-wasmer

Guideines to adoption/contribution

  • Read the Instance.rs documentation to understand how WASM binaries are ported to Python modules via pyo3 Rust crate.
  • Simply put the workflow looks something like:
  1. Developer defines Rust functions and compile them via wasm32-unknown-unknown target
  2. WASM binary (.wasm) is placed in a Python project
  3. With the tools imported via pip install wasmer, developer can load the WASM binary and use the exported functions. This way Rust-defined functions can be called transparently from Python. Great Wasmer!

Ideas for a stable interface

@Mec-iS
Mec-iS / rust_merge.rs
Created April 18, 2019 15:23
Merge subroutine like a rustaceans
fn Merge(c: Vec<i32>, d: Vec<i32>) -> Vec<i32> {
let l: usize = c.len() + d.len();
// initialize result array
let mut b: Vec<i32> = vec!(0; l);
// initialize readers indexes
let mut i: usize = 0;
let mut j: usize = 0;
@Mec-iS
Mec-iS / divergent_functions.rs
Last active April 11, 2019 13:25
[RUST] Functions that are exception to uniformity of return type (forever loops, break, exits ...)
/// Taken from "Programming Rust" by Jim Blandy and Jason Orendorff
// Expressions that don’t finish normally are assigned the special type ! ,
// and they’re exempt from the rules about types having to match.
// You can see ! in the function signature of `std::process::exit()`:
fn exit(code: i32) -> !
// The ! means that exit() never returns. It’s a divergent function.
// You can write divergent functions of your own using the same syntax,
// and this is perfectly natural in some cases:
@Mec-iS
Mec-iS / labeled_loop.rs
Created April 11, 2019 13:13
[RUST] labeling nested loops
/// Taken from "Programming Rust" by Jim Blandy and Jason Orendorff
// A loop can be labeled with a lifetime. In the following example, 'search: is a label for
// the outer for loop. Thus break 'search exits that loop, not the inner loop.
'search:
for room in apartment {
for spot in room.hiding_spots() {
if spot.contains(keys) {
println!("Your keys are {} in the {}.", spot, room);
@Mec-iS
Mec-iS / ubuntu-avahi-cleanup.md
Created February 5, 2019 13:04
Cleanup Ubuntu netwoking

So:

  1. sudo apt-get --purge remove avahi-autoipd avahi-daemon avahi-utils (this is causing A LOT of issues, and it is not needed for Linux networking).
  2. Open file /etc/systemd/resolved.conf
  3. Edit like this:
[Resolve]
DNS=172.16.21.2
#FallbackDNS=
Domains=local