Skip to content

Instantly share code, notes, and snippets.

@velenux
velenux / prepare_images.sh
Last active November 9, 2018 00:54
Create a 1080p and a 2160p images from a starting image and apply a watermark
#!/bin/bash
# iterates over all the .jpg files in a directory
# * creates a 1080p version with a 50% transparent signature (if not already present)
# * creates a 2160p version with a 8% transparent signature (if not already present)
FILE_sign_1080=signature_1080.png
FILE_sign_2160=signature_2160.png
@velenux
velenux / ethinfo.sh
Created April 27, 2018 11:02
print the relevant hardware information about the network interfaces
#!/bin/bash
# show all the relevant hardware information from network interfaces
for DEV in /sys/class/net/* ; do
dev_name=$(basename "${DEV}")
echo "# $dev_name ========================================="
hardware_path=$(udevadm info --query=path --path=${DEV} 2>&1)
if [ -z "$hardware_path" ]; then
echo "Could not find the hardware path, skipping."
@velenux
velenux / extract_timeline_appearance.py
Created March 31, 2018 01:05
elezioni.tracking.exposed data timeline viz
# encoding: utf-8
import json
import pprint
import codecs
import iso8601
import datetime
# this is the json from https://elezioni.tracking.exposed/campaign/opendata/
filename = 'archive.json'
@velenux
velenux / download_crmsh.sh
Created March 15, 2018 16:39
download crmsh packages
#!/bin/bash
# for some reason, this repo is having problems with yum
base_url="https://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/noarch/"
file_tmp=$(mktemp)
/usr/bin/curl -sS -Lo "$file_tmp" "$base_url"
if [ "x$?" != "x0" ]; then
@velenux
velenux / rails-puma.service
Created June 3, 2015 22:38
systemd service to start rails/puma
# based on https://gist.github.com/twtw/5494223
# create systemd service file for rails/puma startup
# 0. [if required: rvm use ruby@default]
# 1. rvm wrapper default systemd rails
# 2. put this file in /etc/systemd/system/rails-puma.service
# 3. systemctl enable rails-puma
# 4. systemctl start rails-puma
[Unit]
Description=Rails-Puma Webserver
@velenux
velenux / corosync.conf
Created April 29, 2015 15:32
Configuration for Corosync 2.x + Pacemaker 1.1 2-node cluster on Ubuntu 14.04 LTS
# Please read the corosync.conf.5 manual page
compatibility: whitetank
totem {
# cluster name
cluster_name: coro01
# totem parameters
version: 2
secauth: off
@velenux
velenux / visual_hash.sh
Last active May 22, 2017 09:04
Quickly create a visual representation of a hash checksum in bash using Unicode color-coded characters
#!/bin/bash
# outputs a visual hash for the system is running on:
# useful to identify which system you are running your commands on
# first two bytes for the unicode sequence, by default we use 28
# since the braille character set is fully compliant and easy to identify
# the characters will be: u+${BASE_UNICODE}${first_hex}${second_hex}
# good values are: 14, 22, 25, 28, 2F, 34, A5, FB, 106, 131
BASE_UNICODE=14
@velenux
velenux / recursive_dir_md5.py
Created July 23, 2014 19:51
Recursively calculate a "directory md5sum" based on it's content filename, size and mtime
import os
import hashlib
# calc directory checksum
def calc_dir_sum(path):
for root, dirs, files in os.walk(path):
dir_hash = hashlib.md5()
# calc checksum for each file
# based on file name, size and mtime
@velenux
velenux / opencl-headers.sh
Created February 11, 2012 21:01
Download OpenCL headers
#!/bin/bash
# based on http://www.streamcomputing.eu/blog/2011-06-24/install-opencl-on-debianubuntu-orderly/
DIR=/usr/include/
for VERSION in 1.1 1.2; do
echo "Downloading headers for version ${VERSION}..."
mkdir -p "${DIR}/CL-${VERSION}"
@velenux
velenux / xpath_factory.rb
Created May 17, 2011 16:51
Select a link via XPath by it's content and container class
# encoding: utf-8
# using XPath 1.0, ref: http://www.exampledepot.com/egs/org.w3c.dom/xpath_GetElemByText.html
class XPathFactory
# build a XPath to find any link with content "content" inside a
# container with class "class_name"
def by_container_class_and_link_content(class_name, content)
"//*[@class and contains(concat(' ',normalize-space(@class),' ')," +
"' #{class_name} ')]//a[contains(translate(.,'abcdefghijklmnopqrstuvwxyz'," +