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 April 13, 2020 15:50
Filter json file with jq

Filter json file with jq

Let's say we have the file data.json with a json compacted in one line:

$ cat data.json
{"employees":[{"name":"Shyam","email":"shyamjaiswal@example.com"},{"name":"Bob","email":"bob32@example.com"},{"name":"Jai","email":"jai87@example.com"}]}

We can use the command jq to see it in with nicer format:

@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 / karma.js
Created April 13, 2020 15:38
Example of Karma configuration to test Js with Chrome Headless
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
@juanje
juanje / rules.js
Created April 13, 2020 15:36
Example of Rules configuration for Firebase/Firestore
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isAdmin() {
let adminData = get(/databases/$(database)/documents/permissions/admin).data;
return isCompany() && request.auth.uid in adminData.userIds
}
@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 / shell.sh
Created April 13, 2020 15:26
Check what makes your Docker image fat
# The command to see the space used under each directory is `du -sh /*`
# The `2> /dev/null` at the end is to avoid get lost with a lot of minor errors.
# For the example 'mydockerimage' is the name of the Docker image to be checked.
# Another way is to use Dive (https://github.com/wagoodman/dive), a really nice tool for this.
docker run --rm -u root --entrypoint "" mydockerimage du -sh /* 2> /dev/null
@juanje
juanje / test_web.py
Last active April 22, 2020 19:58
Smoke tests for a web server with TestInfra
import requests
def test_website_1(host):
"""Check if the website is recheable from outside the managed host,
using the standar Python's library Requests.
It also check for the website content.
"""
host_ip = host.interface("eth0").addresses[0]
result = requests.get(f'http://{host_ip}')
@juanje
juanje / index.html
Last active August 29, 2015 14:04
Las playas más cercanas
<html>
<head>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
<![endif]-->
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
<style>
html, body {width:100%; height:100%; padding: 0; margin: 0;}
#map { width: 100%; height:90%; background: black;}
@juanje
juanje / index.html
Last active August 29, 2015 14:04
Playas con bandera azul en España, por regiones
<!doctype html>
<html>
<head>
<title>Playas con bandera azul en España, por regiones</title>
<script src="http://www.chartjs.org/assets/Chart.js"></script>
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
<style>
canvas{
}
@juanje
juanje / index.html
Last active August 29, 2015 14:04
Testing cartodb.js with Chart.js
<!doctype html>
<html>
<head>
<title>Testing cartodb.js with Chart.js with some random data</title>
<script src="http://www.chartjs.org/assets/Chart.js"></script>
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
<style>
canvas{
}