Skip to content

Instantly share code, notes, and snippets.

@FedericoPonzi
FedericoPonzi / CI.yml
Last active March 22, 2024 16:54
Ready to use Github workflow for cross-compiling a rust binary to many Linux architectures.
# 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 / socket_portable.c
Last active March 8, 2024 01:36
C sockets portable in windows/linux example
// As seen on http://www.di.uniba.it/~reti/LabProRete/Interazione(TCP)Client-Server_Portabile.pdf
#if defined WIN32
#include <winsock.h>
#else
#define closesocket close
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#endif
#include <stdio.h>
@FedericoPonzi
FedericoPonzi / big-o-java-collections.md
Last active December 30, 2023 18:05
Big O notation for java's collections

The book Java Generics and Collections has this information (pages: 188, 211, 222, 240).

List implementations:

                      get  add  contains next remove(0) iterator.remove
ArrayList             O(1) O(1) O(n)     O(1) O(n)      O(n)
LinkedList O(n) O(1) O(n) O(1) O(1) O(1)
@FedericoPonzi
FedericoPonzi / not_expected_to_understand_this.md
Created December 18, 2016 11:38
Line 2238 Unix V6 Comment: You are not expected to understand this.

Here is the famous line 2238 of Unix V6 which is part of some of the most delicate parts of the kernel, context switching.

This comment received huge publicity and just may be the the most famous source code comment in computing history.

2230	/*
2231	 * If the new process paused because it was
2232	 * swapped out, set the stack level to the last call
3333	 * to savu(u_ssav).  This means that the return
2235	 * actually returns from the last routine which did

2236 * the savu.

@FedericoPonzi
FedericoPonzi / trie.py
Created April 28, 2022 20:34
Tries in python
class Trie:
def __init__(self):
self.children = {}
self.isTerminal = False
def setIsTerminal(self):
self.isTerminal = True
def insert(self, word: str) -> None:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#define MAX_BUF 1024
#define pipename "\\\\.\\pipe\\LogPipe"
int main()
{
HANDLE pipe = CreateFile(pipename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (pipe == INVALID_HANDLE_VALUE)
@FedericoPonzi
FedericoPonzi / md5cracker.go
Created December 23, 2015 20:05
A md5 bruteforce cracker multithreaded in go.
package main
import (
"fmt"
"io/ioutil"
"strings"
"sync"
"log"
"time"
"crypto/md5"
@FedericoPonzi
FedericoPonzi / Main.java
Last active January 21, 2021 06:47
Google's compression and decompression challange
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 / hsvThreshold.py
Last active January 20, 2021 17:52
Find thresholds for hsv for opencv (inRange opencv function) using your webcam. From: https://raw.githubusercontent.com/saurabheights/IPExperimentTools/master/AnalyzeHSV/hsvThresholder.py
# Preview: https://raw.githubusercontent.com/FedericoPonzi/LegoLab/master/media/hsv-colour.png
import cv2
import sys
import numpy as np
def nothing(x):
pass
useCamera=False
@FedericoPonzi
FedericoPonzi / Stack.java
Last active October 22, 2020 13:32
Amount of recursive function calls before SO in different languages
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){