Skip to content

Instantly share code, notes, and snippets.

View juanje's full-sized avatar

Juanje Ojeda juanje

View GitHub Profile
@juanje
juanje / description.md
Last active March 26, 2024 11:44
Connect services with docker-compose at multirepo project

Connect services with docker-compose at multirepo project

Sometimes you have a project with different services (or microservices) and each one of them has its own repository. At those cases, tests the whole project (and its interactions) can be challenging.

With Docker and Docker Compose you can run easily each service from its repo, but for making them to see each other you (usually) need to manually create a network with Docker, assume so facts (as directories names) or do some crazy network configurations.

TL;DR

You have the final configuration here.

@juanje
juanje / podman_comands.sh
Created June 10, 2020 14:53
Run Redis with Podman. As a Systemd service and as a Pod.
# This is a simple example of how to run a basic service inside a container with Podman
# Podman
## Pull the Docker image
podman pull docker.io/redis
## Run the container as you would do with Docker
podman run -d --name redis_server -p 6379:6379 redis
# But Podman facilitate some extra ways:
@juanje
juanje / Description.md
Last active November 30, 2023 19:29
Limit Chrome from eating all the memory and CPU

I was tired of Chrome eating all my laptop resources so I decided to put some limit to it with cgroup.

As I was using Ubuntu 12.04 with support for cgroup, I installed the package cgroup-bin and add the following group to the file /etc/cgconfig.conf:

group browsers {
    cpu {
#       Set the relative share of CPU resources equal to 25%
        cpu.shares = "256";
 }
@juanje
juanje / winrm_setup.bat
Last active March 4, 2023 21:34
Batch script for activating the remote administration on Windows vía WinrRM
@ECHO ON
REM This batch script is almost identical to http://code.can.cd/winrm_setup.bat
REM To use this from powershell on windows in a one liner:
REM (New-Object System.Net.WebClient).DownloadFile('https://gist.github.com/juanje/8496054/raw/winrm_setup.bat','winrm_setup.bat') ; .\winrm_setup.bat
cmd.exe /c winrm quickconfig -q
cmd.exe /c winrm quickconfig -transport:http
cmd.exe /c winrm set winrm/config @{MaxTimeoutms="1800000"}
cmd.exe /c winrm set winrm/config/winrs @{MaxMemoryPerShellMB="300"}
cmd.exe /c winrm set winrm/config/service @{AllowUnencrypted="true"}
@juanje
juanje / user.py
Last active February 21, 2023 09:51
Example for an User class in Python with dataclasses
from dataclasses import dataclass
DOMAIN = 'example.com'
@dataclass
class User:
user_id: str = None
name: str = None
email: str = None
role: str = 'standard'
@juanje
juanje / gist:3797297
Created September 28, 2012 00:38
Mount apt cache of a Vagrant box in the host to spin up the packages installation

This is a little trick I use to spin up the packages instalation on Debian/Ubuntu boxes in Vagrant.

I add a simple function that checks if a directory named something similar to ~/.vagrant.d/cache/apt/opscode-ubuntu-12.04/partial (it may have another path in Windows or MacOS) and create the directory if it doesn't already exist.

def local_cache(basebox_name)
  cache_dir = Vagrant::Environment.new.home_path.join('cache', 'apt', basebox_name)
  partial_dir = cache_dir.join('partial')
  partial_dir.mkdir unless partial_dir.exist?
 cache_dir
@juanje
juanje / gist:3081998
Created July 10, 2012 08:21
A simple Logstash conffile with a custom grok filter
input {
tcp {
type => "linux-syslog"
port => 3333
}
file {
type => "linux-syslog"
path => [ "/var/log/auth.log" ]
}
@juanje
juanje / compose_variables.yml
Last active February 21, 2021 10:52
Different ways to compose variables from other variables in Ansible
---
- name: Compose variables and merge lists
hosts: localhost
connection: local
gather_facts: no
vars:
api_versions:
- 1
- 2
@juanje
juanje / try_until.sh
Last active October 9, 2020 20:07
Example of function to try something a max number of times (and wait between retries).
#!/bin/bash
URL="http://ipv4.download.thinkbroadband.com/50MB.zip"
function get_file() {
# Declare these local variables as integer
local -i count
local -i max_retries
local -i wait_time
local filename
@juanje
juanje / cmdline.sh
Last active October 9, 2020 18:57
RPM tips & tricks
# Just a place to write down notes for old time Debian/Ubuntu user
# that has just moved into Fedora/RedHat world
# Show which package provides the file '/bin/ls'
# Similar to 'dpkg -S /bin/ls'
$ rpm -qf /bin/ls
coreutils-8.5-7.fc14.i686
# The same but showing only the package name (without version)
$ rpm -qf /bin/ls --queryformat '%{NAME}\n'