Skip to content

Instantly share code, notes, and snippets.

Avatar

Juanje Ojeda juanje

View GitHub Profile
@juanje
juanje / Tipical bash script option menu
Created Dec 3, 2010
This is a very simple shellscript menu.
View Tipical bash script option menu
#!/bin/bash
while [ "$#" -gt 0 ]
do
case $1 in
-h | --help)
echo "Show program help for $(basename $0)"
shift
;;
View init.rb
#
# vendor/plugins/redmine_gist/init.rb
#
require 'redmine'
require 'open-uri'
Redmine::Plugin.register :redmine_gist do
name 'Redmine Gist embed plugin'
author 'Yasushi Abe <yasushi.abe@gmail.com>'
description 'This is a plugin for Redmine'
@juanje
juanje / gist:1012207
Created Jun 7, 2011
Delete a remote branch
View gist:1012207
# Let's say you've created a branch 'my_changes' you have pushed to Github, but now
# you want to remove it.
# Let's also set the remote which point to your Github account is 'origin'
# These are the needed steps:
# 1 - Delete the branch locally
git -D my_changes
# 2 - Push those changes (the delete) to Github
@juanje
juanje / update-hwmime.py
Created Aug 11, 2011
A protoype of a update script for the hardware mimetypes
View update-hwmime.py
#!/usr/bin/env python
from xdg import BaseDirectory
from xdg.IniFile import IniFile
from os import path
from glob import glob
desktop_files = []
for dirname in BaseDirectory.xdg_data_dirs:
@juanje
juanje / get_exe_from_hwtype.py
Created Aug 11, 2011
Get the app that should be launched for a specific hardware Type
View get_exe_from_hwtype.py
#!/usr/bin/env python
from xdg import IniFile, BaseDirectory, DesktopEntry
from os import path
import pynotify
# Desktop Notifications Specification: http://www.galago-project.org/specs/notification/0.9/index.html
title = "HANS: Device detected"
message = "An ebook has been plugged"
timeout = pynotify.EXPIRES_DEFAULT
@juanje
juanje / gist:1210545
Created Sep 12, 2011
Ruby class template based on attribs and a passed hash
View gist:1210545
class Base
def initialize args
update args
end
def update args
args.each do |k,v|
send "#{k}=", v if respond_to? k
end
@juanje
juanje / gist:1213900
Created Sep 13, 2011
Ruby class template based on attribs and a passed hash using mixins
View gist:1213900
module Base
def initialize args
update args
end
def update args
args.each do |k,v|
instance_variable_set "@#{k}", v if respond_to? k
end
@juanje
juanje / Chuletas.markdown
Created Sep 22, 2011
Archivos de apoyo a un mini curso de VIM
View Chuletas.markdown

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 Oct 21, 2011
Chef ohai plugin for home users
View home_users.rb
provides 'home_users'
require 'etc'
home_users Mash.new
etcpasswd = []
Etc.passwd do |entry|
etcpasswd << entry
end
@juanje
juanje / gist:1310403
Created Oct 24, 2011
Use Ruby as AWK or Grep
View gist:1310403
# A few examples about how to use Ruby for parsing files as we could do
# with Awk or Grep. This is based on what I learn fro this post:
# http://code.joejag.com/2009/using-ruby-as-an-awk-replacement/
# Split each line with ':' and print the first $F[0] field
awk -F: '{ print $1 }' /etc/passwd
ruby -F: -nae 'puts $F[0]' /etc/passwd
# Parse the 'ps aux' output
# It'll print the ID process for the 'jojeda' user