Skip to content

Instantly share code, notes, and snippets.

@jpralves
jpralves / Makefile
Created November 6, 2024 18:17
Makefile without tabs
.RECIPEPREFIX = >
.PHONY: all
CFLAGS = -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wc++-compat -Wundef -Wswitch-default -Wconversion
%.o : %.c
> $(CC) -c $(CFLAGS) -o $@ $<
all: helloworld
helloworld: helloworld.c
> $(CC) $(CFLAGS) -o $@ $<
@jpralves
jpralves / getdockerenv.sh
Created June 23, 2021 12:11
get all docker constraints in variables
#!/bin/bash
# getdockerenv.sh v1.0
# 2021-06-23 - João Alves
# This script sets a group of variables that can be useful in a containerized environment
# It is specially tuned for docker but might (not tested) work in other environments
# Exported variables:
# CGROUPS - v1, v2, none
@jpralves
jpralves / merge_json_ansible.md
Created November 25, 2020 16:15
Merge the content of a json file with another json file

Ansible instructions to merge two json files.

Assumes files: original.json, merge.json and new.json

---
- name: get content of original file
  slurp:
    src: "original.json"
 register: original_config
@jpralves
jpralves / DockerTWINs-withoutDocker.md
Created October 20, 2020 08:45
Docker TWINs without docker

Docker TWINs without docker

This is a new example on how to use docker along docker without docker, confused?, I'm using the docker API to create and run containers.

In this particular example the image self-replicates itself running multiple images.

To build:

docker build . --tag twin-api:latest
@jpralves
jpralves / BatchNotifyDesktop.md
Created May 18, 2020 22:02
batch notify to desktop from scripts

batch notify to desktop from scripts

To be able to send notifications to the logged in user you must add the file session-local.conf to folder /etc/dbus-1/session.d Then you can use the command in notify-command.sh to display a message. Don't forget to match the UID with the one currently running the session.

This was tested in Fedora 31/32.

@jpralves
jpralves / DockerTWINs.md
Created May 18, 2020 21:59
DockerTWINs - Self Replicating docker containers

Docker TWINs

This is a simple example on how to use docker along docker.

In this particular example the image self-replicates itself running multiple images.

To build:

docker build . --tag twin:latest
@jpralves
jpralves / PBEWITHMD5andDES_cipher.py
Created January 14, 2020 23:39
Python 3 implementation of PBEWITHMD5andDES Java
from Crypto.Hash import MD5
from Crypto.Cipher import DES
import base64
import random
import sys
def randomBytes(n):
return bytearray(random.getrandbits(8) for i in range(n))
@jpralves
jpralves / gimme-secret-list-from-docker-swarm.sh
Created October 28, 2019 16:00
Obtain list of docker swarm secrets used by each stack
for s in $(docker service ls --format "{{.Name}}"); do echo $s; docker service inspect $s --format '{{range .Spec.TaskTemplate.ContainerSpec.Secrets}}{{println " " .SecretName}}{{end}}'; done
FROM centos:7 AS BUILD
ARG COMPILEFOLDER=/tmp/build
ARG INSTALLBASESSHD=/opt/.ssh
ARG INSTALLBASESSSL=/opt/.ssl
RUN yum -y -q install gcc make perl glibc-static wget
RUN mkdir -p "$COMPILEFOLDER/root"
@jpralves
jpralves / puppeteer-json.js
Last active September 20, 2019 15:02
simple node script to get headers and data from a webpage. Uses puppeteer.
'use strict'
const puppeteer = require('puppeteer');
const fs = require('fs');
var args = process.argv.slice(2);
if (!(Array.isArray(args) && args.length)) {
console.log('puppeteer-json.js url [fileprefix]');
process.exit(1);
}