Skip to content

Instantly share code, notes, and snippets.

View gdetor's full-sized avatar

Georgios Is. Detorakis gdetor

View GitHub Profile
@gdetor
gdetor / vimrc
Created February 6, 2023 23:48
Sample of vimrc file
"
"0 run vim -V9myvimlog - creates a vim runtime log file at debug level 9
" Pathogen calls
"
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
@gdetor
gdetor / cropping.sh
Last active February 7, 2023 00:02
A simple script for cropping pdf files within a directory (bash-tested)
#!/bin/bash
file=`which parallel`
echo $file
for file in *.pdf;
do
echo "Now cropping file: $file"
pdfcrop $file $file > /dev/null 2>&1
@gdetor
gdetor / split_pdf.sh
Created February 7, 2023 00:02
Simple bash script for splitting a pdf file into multiple pages
#!/bin/bash
# This script exctracts a specific number of pages from a pdf file.
#
# Arguments: $1 -> Input file
# $2 -> Outout file
# $3 -> First page (to cut)
# $4 -> Last page
#
# Example: pdf_split input.pdf output.pdf 1 5
#
@gdetor
gdetor / shorenurl.sh
Created February 7, 2023 00:03
A script for shortening a long URL (bash-tested)
#!/usr/bin/bash
echo -n "Original URL: "
read url
short_url=$(curl -s http://tinyurl.com/api-create.php?url=${url})
echo "Short URL: ${short_url}"
@gdetor
gdetor / wclatex.py
Created February 7, 2023 00:05
Words counting for LaTeX files (Python, bash)
#!/usr/bin/python
# A minimal script that counts the number of words in a LaTeX file.
# Example of use:
# localhost@name$ wclatex filename
import re
import sys
def word_counter(filename):
@gdetor
gdetor / array_alignment.c
Created February 7, 2023 00:26
Example of POSIX memalign in C
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 1000000
typedef struct {
float *x;
} test_s;
@gdetor
gdetor / c_script.sh
Created February 7, 2023 00:28
C might be a scripting language
#!/usr/bin/bash
tail -n+3 "$0" | gcc -xc - && ./a.out ; exit
#include <stdio.h>
int main()
{
printf("C is a scripting language!\n");
}
@gdetor
gdetor / closure.c
Created February 7, 2023 00:32
Closure in C
#include <stdio.h>
typedef struct TClosure {
int (*code)(struct TClosure *env, int);
int state;
} Closure;
int call(Closure *c, int x) {
return c->code(c, x);
@gdetor
gdetor / close_raii.c
Created February 7, 2023 00:33
RAII in C (close a file)
#include <stdio.h>
/* #include <stdlib.h> */
static inline void fclosep(FILE **fp) { if (*fp) fclose(*fp); *fp=NULL; }
#define _cleanup_fclose_ __attribute__((cleanup(fclosep)))
void example_usage(void)
{
_cleanup_fclose_ FILE *logfile = fopen("logfile.txt", "w+");
fputs("hello logfile!", logfile);
@gdetor
gdetor / viewbin.c
Created February 7, 2023 00:38
View the content of a binary file
#include <stdio.h>
#include <stdlib.h>
void print_buffer(void *, int);
void catbin(char *);
int main(int argc, char **argv) {
if (argc == 2){ viewbin(argv[1]); }
else{
printf("Please type the name of the binary input file!\n");
printf("Example: viewbin foo.dat \n");