Skip to content

Instantly share code, notes, and snippets.

View juanje's full-sized avatar

Juanje Ojeda juanje

View GitHub Profile
@juanje
juanje / Chuletas.markdown
Created September 22, 2011 00:28
Archivos de apoyo a un mini curso de VIM

f -> (find) buscar siguiente caracter. Se posiciona en dicho caracter
t -> (?) buscar el caracter, pero posicionarse justo antes
b -> (begin word) principio de la palabra (o anterior si se está al principio)
w -> (word) ir al principio de la siguiente palabra
e -> (end of word) va al final de la palabra en la que está o de la siguiente
$ -> (end of line) va al final de la línea
0 -> (col 0) va a la columna 0. El principio de la línea
^ -> (begin of line) va al principio del texto de la línea

d[orden] -> (delete) borra lo que se le diga detrás:

@juanje
juanje / home_users.rb
Created October 21, 2011 09:12
Chef ohai plugin for home users
provides 'home_users'
require 'etc'
home_users Mash.new
etcpasswd = []
Etc.passwd do |entry|
etcpasswd << entry
end
@juanje
juanje / Vagrantfile.rb
Created November 1, 2011 13:27
Vagrant and Chef stuff
# Vagrantfile for node: vagrant-vm
Vagrant::Config.run do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "ubuntu-11.04-server"
# The Opscode Platform uses HTTPS. Substitute your organization for
# ORGNAME in the URL and validation key.
#
config.vm.provision :chef_client do |chef|
@juanje
juanje / autocommit_monitor.sh
Last active September 28, 2015 00:38
Commit any changes on a specific directory
#!/bin/sh
#
# autocommit_monitor is a simple script to monitorize a directory and commit to
# the Git repo inside all the changes on files (files added, removed, changed, etc).
# It uses inotify to be aware of thos changes and you need to have installed
# the tool 'inotifywait'.
#
# Copyright (C) 2011-2014, Juanje Ojeda
# Author: Juanje Ojeda <juanje.ojeda@gmail.com>
#
@juanje
juanje / cookbooks_foo_libraries_file.rb
Created November 15, 2011 22:53
Add include? and replace(str, str2) to Chef::Resource::File
class Chef
class Resource
class File
def include?(str)
return false unless ::File.exists?(@path)
file_content = IO.read @path
if file_content =~ /#{str}/
Chef::Log.info("file[#{@path}] contains the string '#{str}'")
true
@juanje
juanje / gist:1386361
Created November 22, 2011 17:52
Split a subdirectory into a new Git repo
# You need to install the command git-subtree from here:
# https://github.com/apenwarr/git-subtree
# Let's say you got a subdirectory 'lib-abc' under 'project' git repo that you like to
# split into a new repository
# First you need to create a bare repository, i.e. a Github project called 'lib-abc'
# Your new remote could be somethings like 'git@github.com:yourname/lib-abc.git'
cd project/
@juanje
juanje / gist:1474442
Created December 13, 2011 23:23
Install required library
diff --git a/providers/bookmarks.rb b/providers/bookmarks.rb
index ac470fa..f75fe11 100644
--- a/providers/bookmarks.rb
+++ b/providers/bookmarks.rb
@@ -1,4 +1,8 @@
-require ('sqlite3')
+begin
+ require 'sqlite3'
+rescue LoadError => e
+ Chef::Log.warn("Dependency 'gem' not loaded: #{e}")
@juanje
juanje / home_users.json
Created December 18, 2011 23:03
Cambio de home_users a users
{
:home_users => {
"pepe" => {
:username => "pepe",
:gid => 1000,
:uid => 1000,
:gecos => "Pepe,,,"
},
"damian" => {
:username => "damian",
@juanje
juanje / update_sources_list.rb
Created January 9, 2012 12:27
Update sources_list data_bag
#!/usr/bin/env ruby
require 'debsfromrepos'
require 'chef/config'
require 'chef/data_bag'
Chef::Config.from_file('./.chef/knife.rb')
data_bag = 'sources_list'
@juanje
juanje / get_sources.rb
Created January 19, 2012 11:14
Get sources_list and put into a data_bag
#!/usr/bin/env ruby
require 'chef/search/query'
require 'chef/config'
require 'chef/data_bag'
require 'uri'
# get the config from the closer config file
repo_config_file = File.join('.', '.chef', 'knife.rb')
home_config_file = File.join(ENV['HOME'], '.chef', 'knife.rb') if ENV['HOME']