Skip to content

Instantly share code, notes, and snippets.

View tappoz's full-sized avatar

Alessio Gottardo tappoz

View GitHub Profile
@tappoz
tappoz / first-class-functions-in-go.md
Last active March 13, 2018 10:29
First class functions in Go
@tappoz
tappoz / lxde-tricks.md
Last active December 3, 2018 11:31
LXDE setup

Add SQL Operations Studio icon

This is a desktop launcher for SQL Operations Studio (https://github.com/Microsoft/sqlopsstudio).

Assuming the application is unpacket to $HOME/src/sqlops-linux-x64, then:

  • create the desktop launcher with: touch ~/.local/share/applications/sqlopsstudio.desktop;
  • the desktop launcher should contain:
[Desktop Entry]
@tappoz
tappoz / kafka-golang.md
Last active November 27, 2017 16:27
Apache Kafka and Golang

Trubleshooting Kafka

  • To consume existing topics: ./bin/kafka-console-consumer.sh --bootstrap-server <IP_ADDR>:9092 --topic my-custom-topic --from-beginning
  • To check a list of topics: ./bin/kafka-topics.sh --list --zookeeper <IP_ADDR>:2181

Go sample

The following code snippets make use of sarama the Go library to connect to a cluster of Apache Kafka instance.

@tappoz
tappoz / js-node-js-tricks.md
Created August 30, 2017 14:24
Javascript / Node.js tricks

Moment.js durations

var moment = require('moment-timezone');

var _timeConsumingFunc = () => {
  // wait a few seconds
  for (i = 0; i < 1000000000; i++) { 
    // do nothing
 }
@tappoz
tappoz / go-code-snippets.md
Last active August 16, 2017 12:24
Go code snippets

Go database operations

The following go/golang snippet:

  • connect to a MS-SQL database via ODBC;
  • INSERTs a new record into a table;
  • disconnects from the database.
package main
@tappoz
tappoz / python-multiprocessing-with-global-timeout.md
Last active February 28, 2025 15:00
Python multiprocessing with global timeout

How to join processes with timeout

The process.join(NUM_SECONDS) does not fit, because the normal for loop to join all the processes waits NUM_SECONDS for each process before joining it.

We want a global amount of NUM_SECONDS to be timed out on to kill (terminate) all the outstanding processes that are still alive after NUM_SECONDS elapsed (i.e. not yet been joined already).

The following code snippet has been heavily inspired by:

@tappoz
tappoz / ansible-install-docker-and-other-tricks.md
Last active November 23, 2017 13:41
Ansible playbook to install docker and other tricks

Docker stuff

This playbook works on Ubuntu and should work also on debian:

---
- name: Make sure docker is installed and configured
  hosts: my_hosts_group # cf. the hosts file below for this group of hosts
  sudo: yes
  tasks:
@tappoz
tappoz / Shell-tricks.md
Last active October 25, 2021 08:00
command line tricks

How to find and list all the symbolic links created for a particular file?

$ ls -li
# take note of the symlink ID
$ find / -follow -inum 5097642 2>/dev/null
# you'll have a list of symlink to that inode

Useful bash configuration

@tappoz
tappoz / aws-commands-cheatsheet.md
Created December 9, 2016 17:41
AWS CLI cheatsheet

EC2

Generate ssh key

To be used for a user in an EC2 instance:

$ ssh-keygen -b 4096 -t rsa -f ~/.ssh/$(whoami)-<suffix-for-ec2-environment>
@tappoz
tappoz / db-cheatsheet.md
Last active December 9, 2016 17:17
cheatsheet for common tasks using Postgres or MySQL

Postgres

Command to display active connections to a PostgresDB: SELECT * FROM pg_stat_activity;

Connection to Redshift

$ psql -h <ENDPOINT_NAME>.us-east-1.redshift.amazonaws.com -p 5439 -d <DB_NAME> -U <DB_USERNAME>