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 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 / 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 / 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 / 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 / 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 / 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.

@juanje
juanje / Berksfile
Created December 10, 2012 03:41
Example of config for bootstraping an Aentos project
site :opscode
cookbook 'mongodb'
cookbook 'postgresql', '= 2.0.0'
cookbook 'apt'
cookbook 'sudo'
cookbook 'conf'
cookbook 'rvm', git: 'git://github.com/fnichol/chef-rvm.git', branch: "v0.9.0"
cookbook 'aentos-bootstrap', git: 'git://github.com/aentos/cookbook-aentos-bootstrap.git'
@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: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 / 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" ]
}