Skip to content

Instantly share code, notes, and snippets.

Avatar

Federico Ponzi FedericoPonzi

View GitHub Profile
@FedericoPonzi
FedericoPonzi / ffun_interpreter.sml
Created Aug 23, 2020
Project for my Programming languages exam, an interpreter for a programming language called ffun.
View ffun_interpreter.sml
datatype ffun = const of int (* Possiamo trovare delle costanti intere *)
| plus of (ffun*ffun) (* Addizione *)
| var of string (* Variabili di tipo stringhe *)
| llet of (string*ffun*ffun) (* La funzione let, che prende una variabile stringa, e due oggetti di tipo ffun *)
| fffun of (string*ffun) (* Una funzione *)
| ycombinator of (ffun)
| appl of (ffun*ffun)
| ifelse of (ffun*ffun*ffun)
| minus of ffun
| prod of (ffun*ffun);
@FedericoPonzi
FedericoPonzi / no-copy.rs
Created May 9, 2020
On the difference between Copy and Clone
View no-copy.rs
struct Test{
i : String,
}
fn update_i(i: String) {
}
fn update_test(i: &Test) {
//Error: String doesn't implement Copy trait. Solved with clone()
update_i(i.i);
@FedericoPonzi
FedericoPonzi / CI.yml
Last active Sep 24, 2021
Ready to use Github workflow for cross-compiling a rust binary to many Linux architectures.
View CI.yml
# Instruction + template repo: https://github.com/FedericoPonzi/rust-ci
# Search and replace <YOUR_BINARY_NAME> with your binary name.
name: CI
on:
pull_request:
push:
branches:
- master
tags:
@FedericoPonzi
FedericoPonzi / top_sort.rs
Created Jan 20, 2020
Topological sort in rust
View top_sort.rs
use crate::error::Result;
use crate::formats::Service;
use std::collections::BTreeMap;
/// Get a starting executon order
/// Result is a vector of vectors(batches) of Service.
/// Each batch has no dependence between each other so they can be started in parallel.
/// TODO: this might deadlock if `services` is not a DAG.
/// TODO: this topological sorting works, every process in set index i + 1 has only
/// dependencies in `0...i`. But, this might lead to a non optimal solution, because if a process j + 1 has a dependency
@FedericoPonzi
FedericoPonzi / main.rs
Created Aug 27, 2019 — forked from codesections/main.rs
Warp_proof_of_concept
View main.rs
use futures::{Async, Future, Poll};
use tokio::io::{AsyncRead, AsyncWrite, Error, ReadHalf, WriteHalf};
use tokio::net::TcpStream;
use warp::{path, Filter, Stream};
struct Receiver {
rx: ReadHalf<TcpStream>,
}
impl Stream for Receiver {
type Item = String;
@FedericoPonzi
FedericoPonzi / first.sh
Last active Aug 20, 2019
Setup typescript project
View first.sh
#from: https://basarat.gitbooks.io/typescript/docs/quick/nodejs.html
npm init -y
npm install typescript --save-dev
npm install @types/node --save-dev
npx tsc --init --rootDir src --outDir lib --esModuleInterop --resolveJsonModule --lib es6,dom --module commonjs
# Done! use `code .` to fireup visual studio.
@FedericoPonzi
FedericoPonzi / Main.java
Last active Jan 21, 2021
Google's compression and decompression challange
View Main.java
package me.fponzi;
class Main {
static class Pair{
// Result string
String ret;
// Position of the consumed portion of the string.
int val;
public Pair( String ret, int val) {
@FedericoPonzi
FedericoPonzi / Dockerfile
Created Sep 19, 2018
Dockerfile for spring boot + gradle.
View Dockerfile
FROM gradle:jdk8-alpine
VOLUME gradle-cache:/home/gradle/.gradle
VOLUME /tmp
USER root
ADD . /home/gradle/project
WORKDIR /home/gradle/project
RUN chown gradle:gradle -R /home/gradle
USER gradle
RUN gradle bootJar
#Start from a java:8
@FedericoPonzi
FedericoPonzi / client.py
Created Aug 24, 2018
Hackerrank sorted set solution
View client.py
import struct
import socket
import os
import sys
class NetworkHandler():
def __init__(self, sock):
self.sock = sock
def myreceive(self):
@FedericoPonzi
FedericoPonzi / Stack.java
Last active Oct 22, 2020
Amount of recursive function calls before SO in different languages
View Stack.java
class Stack {
public static int f(int v) {
System.out.println(v);
return 0 + f(v + 1);
}
public static void main(String[] args) {
try{
f(0);
}catch(java.lang.StackOverflowError e){