Skip to content

Instantly share code, notes, and snippets.

View panta's full-sized avatar

Marco Pantaleoni panta

  • /*jupiter jazz*/
  • Padova
View GitHub Profile
### Keybase proof
I hereby claim:
* I am panta on github.
* I am mpanta (https://keybase.io/mpanta) on keybase.
* I have a public key ASBlrf84tM1kT1bX3d-dotvBNsZVtnDisa19ZqcHpJgeAAo
To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am panta on github.
  • I am panta (https://keybase.io/panta) on keybase.
  • I have a public key ASDUiEThogcBU_9EUVhqmG6v2v8lDrUxi6qip7lYAPxHSAo

To claim this, I am signing this object:

@panta
panta / logging.go
Last active October 28, 2024 18:56
zerolog with file log rotation (lumberjack) and console output
package logging
import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"gopkg.in/natefinch/lumberjack.v2"
"os"
"path"
"io"
)
@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"
@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 / 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-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 / 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 / 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 / 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);