Skip to content

Instantly share code, notes, and snippets.

View cbonesana's full-sized avatar
👾
bip bip bip

Claudio Bonesana cbonesana

👾
bip bip bip
View GitHub Profile
@cbonesana
cbonesana / archive.sh
Created June 8, 2017 11:38
Archive multiple file to each zip with a counter in Ubuntu.
#!/bin/bash
# zip all the files that end in 'sql', creating a zip foreach file
find . -name '*.sql' -print -exec zip '{}'.zip '{}' \; &
# execute a while loop where we compare the old files (number and size) against the zipped files (number and size) with a sleep of 1 second
while true; do clear; echo 'ZIP:'; ls -l *zip | wc -l; du -ch *zip | grep total; echo 'SQL:'; ls -l *.sql | wc -l; du -ch *sql | grep total; date; sleep 1; done
# output:
# ZIP:
@cbonesana
cbonesana / raspy-can.sh
Last active July 2, 2021 04:06
Install and use the can-utils package on a Raspberry Pi 3 B
# Board: Raspberry Pi 3 Model B
# OS: Raspbian Jessie Lite (https://www.raspberrypi.org/downloads/raspbian/)
# GPIO reference image: http://imgur.com/a/Cqi9p
# Requirements
# - 4GB at least compatible SD card
# - LAN connection for configuration
# - CAN enabled module
# - HDMI cable for first configuration
@cbonesana
cbonesana / beautify-json.py
Last active June 22, 2022 16:51
Basic Python script that merge and beautify multiple JSONs files in subfolders. Given an input folder, it scans the directory tree, merging together the JSONs file found in a file in the parent folder called "<folder>-output.json". This script has one only CLI argument, i.e. "python beautify-json.py <root-folder>"
import json
import os
import sys
encoding = 'utf-8'
indentNum = 4
def clean(data):
return json.dumps(data, sort_keys=True, indent=indentNum, separators=(',', ': '))
@cbonesana
cbonesana / holiday.py
Created December 19, 2017 14:24
A beautiful Christmas Tree for you holidays!
# *
# * + *
# * +++ *
# * +++++ *
# * +++++++ *
# * +++++++++ *
# M
def holiday(n):
print(' ' * (n + 2) + '*')
@cbonesana
cbonesana / userDefineLang_Cypher_dark.xml
Last active June 15, 2023 22:35 — forked from nicolewhite/userDefineLang_Cypher.xml
A Cypher syntax highlighter for Notepad ++ with colors for a dark theme.
<NotepadPlus>
<UserLang name="Cypher" ext="cypher" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="yes" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00// 01 02 03// 04</Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
@cbonesana
cbonesana / TweetDecompressApplication.java
Created August 12, 2018 16:18
Just an experimental project to work with a relative big amount of tweets from a single JSON file compressed in BZip2. The idea is to work in parallel on many tweets and avoiding to load everything in memory.
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONObject;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
@cbonesana
cbonesana / ZipInZipApplication.java
Created August 13, 2018 09:24
Just an example to solve the issue of opening a zip archive containing multiples zip archives, without enough space to extract everything on the disk first.
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
@cbonesana
cbonesana / history_reader.py
Created August 11, 2019 16:51
Download all the messages, known as history or logs in previous version, from a Discord server using access via token using python 3.7.
import argparse
import asyncio
import json
import os
import discord
client = discord.Client()
dirHistory = 'history'
@cbonesana
cbonesana / convert_timezone.py
Created August 12, 2019 09:19
Just to remember how to convert UTC to GMT with time zones.
# source: https://stackoverflow.com/questions/5280692/python-convert-local-time-to-another-time-zone
from datetime import datetime
from pytz import timezone
format = '%Y-%m-%d %H:%M:%S'
now_utc = datetime.now(timezone('UTC'))
print(now_utc.strftime(format))
# 2019-08-12 09:14:33
@cbonesana
cbonesana / install-docker-sh
Last active August 25, 2019 11:45
Single-script installer for the latest stable Docker for Ubuntu. Source: https://docs.docker.com/install/linux/docker-ce/ubuntu/
#!/bin/bash
# SET UP THE REPOSITORY
# Update the apt package index:
apt update
# Install packages to allow apt to use a repository over HTTPS:
apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
# Add Docker’s official GPG key: