Skip to content

Instantly share code, notes, and snippets.

Avatar

Juanje Ojeda juanje

View GitHub Profile
@juanje
juanje / description.md
Last active Apr 13, 2020
Filter json file with jq
View description.md

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 Apr 13, 2020
Connect services with docker-compose at multirepo project
View description.md

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 Apr 13, 2020
Example of Karma configuration to test Js with Chrome Headless
View karma.js
// 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 Apr 13, 2020
Example of Rules configuration for Firebase/Firestore
View rules.js
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 Apr 19, 2020
Example for an User class in Python with dataclasses
View user.py
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 Apr 13, 2020
Check what makes your Docker image fat
View shell.sh
# 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 Apr 22, 2020
Smoke tests for a web server with TestInfra
View test_web.py
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 Aug 29, 2015
Las playas más cercanas
View index.html
<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 Aug 29, 2015
Playas con bandera azul en España, por regiones
View index.html
<!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 Aug 29, 2015
Testing cartodb.js with Chart.js
View index.html
<!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{
}