Skip to content

Instantly share code, notes, and snippets.

View panta's full-sized avatar

Marco Pantaleoni panta

  • /*jupiter jazz*/
  • Padova
View GitHub Profile
@panta
panta / its-l6-es4-mandelbrot.c
Last active April 20, 2022 10:32
ITS Meccatronico - Lezione 6 Esercizio 4 - Programma di partenza (Mandelbrot - single threaded)
/*
* for an intro to the Mandelbrot set:
* - https://simple.wikipedia.org/wiki/Mandelbrot_set
*
* for ppm format, see:
* - http://netpbm.sourceforge.net/doc/ppm.html
*
* install ImageMagick:
* debian/ubuntu: apt-get install imagemagick
* macos: brew install imagemagick
@panta
panta / its-l6-es3-mt-dot-product.c
Created April 20, 2022 10:20
ITS Meccatronico - Soluzione esercizio 3 lezione 6
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
// Data la definizione di prodotto scalare
// tra vettori enunciata qui sopra,
// scrivere un programma single-threaded
// che calcoli il prodotto scalare tra
// due vettori di double di grande
@panta
panta / raylib-lines.c
Created March 21, 2022 11:48
Simple raylib example which draws lines on the screen.
/*
* raylib-lines.c
*
* To compile:
* clang -Wall $(pkg-config --cflags raylib) -o raylib-lines raylib-lines.c $(pkg-config --libs raylib)
*
* Copyright (C) 2022 Marco Pantaleoni.
*/
#include <time.h>
@panta
panta / shared-memory.c
Created March 21, 2022 10:37
Simple example of shared memory between parent and child using mmap() and fork().
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
int main(int argc, char *argv[]) {
size_t size = 4096;
char *smem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
@panta
panta / process-child-output-example.c
Last active January 31, 2022 18:19
Example showing how to
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/wait.h>
const char *handle_child_process_output(const char *buffer, ssize_t count) {
// we just print it, but we could do any other processing here...
write(STDOUT_FILENO, buffer, (size_t)count);
@panta
panta / command-pipe-example.c
Created January 31, 2022 17:28
Command pipe example in C - execute "ls / | wc -l"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main(void) {
/* set up pipe. */
int pfd[2];
if (pipe(pfd) < 0) {
perror("pipe()");
@panta
panta / unipd-fdi-2021-float-representation.c
Created December 10, 2021 13:40
UNIPD FdI 2021-2022 - Conversioni float da/verso codifica a 32 bit.
#include <stdio.h>
#include <stdint.h>
// NOTA: queste funzioni operano correttamente solo sulle piattaforme
// in cui float occupa esattamente 32 bit!
// (Solitamente vero in C99 e garantito in C99 su x86 e amd64)
// float_to_repr32() ritorna l'intero a 32 bit
// che "codifica" il float passato come argomento
// secondo IEEE754.
@panta
panta / unipd-fdi-2021-stack-example-struct.c
Created December 9, 2021 17:48
UNIPD FdI 2021-2022 - Esempio di stack in C (con struct e variabili locali)
#include <stdio.h>
#include <stdint.h>
#define STACK_SIZE 1000
struct stack {
int elements[STACK_SIZE];
int sp;
};
@panta
panta / unipd-fdi-2021-stack-example-globals.c
Last active December 9, 2021 17:42
UNIPD FdI 2021-2022 - Esempio di stack in C (con variabili globali)
#include <stdio.h>
#include <stdint.h>
#define STACK_SIZE 1000
// ATTENZIONE!
// qui utilizziamo delle variabili globali a titolo di esempio
// ma dovremmo invece utilizzare una struttura e passare
// il puntatore alla struttura a tutte le funzioni che operano
@panta
panta / logging.go
Created July 4, 2018 14:14
zap logging to console (colors) and file with rotation (lumberjack)
package logging
import (
"go.uber.org/zap/zapcore"
"go.uber.org/zap"
//"github.com/natefinch/lumberjack"
"gopkg.in/natefinch/lumberjack.v2"
"os"
"path"
"strings"