Skip to content

Instantly share code, notes, and snippets.

View juanje's full-sized avatar

Juanje Ojeda juanje

View GitHub Profile
@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 / 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 / gist:9603938
Created March 17, 2014 17:20
Install gem before to require it at Test-Kitchen

Install gem before to require it at Test-Kitchen

Context

I was trying some TDD with [Tesk-Kitchen][1] and [ServerSpec][2] when I found myself in the following case scenario:

I have a integration test like this:

# cookbook_webtest/test/integration/default/serverspec/localhost/webtest_spec.rb
@juanje
juanje / gist:3797207
Created September 28, 2012 00:08
Some useful lines for my Vagrantfiles
# To have the last stable version of Chef (10.14.4)
# with the official Vagrant boxes
config.vm.provision :shell,
:inline => "gem search -i chef -v 10.14.4 || gem install chef -v 10.14.4 --no-rdoc --no-ri"
# with the official Opscode boxes
config.vm.provision :shell,
:inline => "/opt/chef/embedded/bin/gem search -i chef -v 10.14.4 || /opt/chef/embedded/bin/gem install chef -v 10.14.4 --no-rdoc --no-ri"
@juanje
juanje / Berksfile
Last active April 10, 2017 07:27
Simplified Vagrant config for setting up a logstash server with Chef solo
cookbook 'apt'
cookbook 'monit'
cookbook 'logstash', git: 'git://github.com/lusis/chef-logstash.git'
@juanje
juanje / listdiff.py
Created March 29, 2012 00:12
listdiff is just a silly script which merge two list and give you the elements which are not in the first list.
#!/usr/bin/python
# -*- coding: utf8 -*-
#
# Copyright (c) 2008-2012, Juanje Ojeda Croissier <jojeda@emergya.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
@juanje
juanje / Rakefile
Created April 12, 2012 07:46
Example of Rake tasks for dealing with Vagrant
load 'rake/helper.rb'
desc "Set up the VM"
task :up do
vm = VM.new
vm.cli('up')
end
desc "Shutdown the VM"
task :graceful_down do
@juanje
juanje / pushover_handler.rb
Created January 3, 2013 20:33
Example of Chef hanfler for sending run fails to Pushover (notifications to iPhone and Android) https://pushover.net/
# cookbook/files/default/pushover_handler.rb
require "net/https"
module MyOrg
class PushOver < Chef::Handler
def initialize(config={})
@config = config
end
@juanje
juanje / gist:2558286
Created April 30, 2012 13:17
Simple Vagrantfile for testign Django with Chef-solo
Vagrant::Config.run do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "base"
# Assing IP to the VM
config.vm.network :hostonly, "10.0.33.10"
# Share directory between the host and the VM
config.vm.share_folder "git","/opt/git","/home/anarey/git/djandoapps"
@juanje
juanje / web_assertions.rb
Last active December 10, 2015 02:28
Examples of custom assertions for remote conections with MiniTest

This is a short and simple example of custom assertions for Minitest.

They are very basic, but they help me to learn it. And I can use the to test some very simple use case of remote conection without install a bunch of gems.

I learn what I needed for this from this article and the minitest-chef-handler's code.

It can be improved a lot using Nokogiri and other Ruby libraries.