Skip to content

Instantly share code, notes, and snippets.

View manuelmorales's full-sized avatar

Manuel Morales manuelmorales

View GitHub Profile
@manuelmorales
manuelmorales / install_solr_340.sh
Created June 6, 2012 10:11
Installing Solr 3.4.0 in Ubuntu 11.10
wget http://apache.rediris.es/lucene/solr/3.4.0/apache-solr-3.4.0.tgz
tar zxvf apache-solr-3.4.0.tgz
cd apache-solr-3.4.0/
mkdir ../solr
cp -r example/* ../solr/
# cp -r ../ey-cloud-recipes/cookbooks/solr/files/default/conf/ ../solr/solr/
mkdir ../solr/solr/lib
cp dist/apache-solr-cell-3.4.0.jar ../solr/solr/lib/
cp contrib/extraction/lib/*jar ../solr/solr/lib/
cd ../solr
@manuelmorales
manuelmorales / format_pendrive.sh
Created June 3, 2012 11:47
Format pendrive Ubuntu
# Guess which device is it
$ sudo cat /etc/mtab | grep /media/Pendrive
/dev/sdb1 /media/Pendrive vfat rw,utf8,umask=007,gid=46 0 0
# Unmount and format
sudo umount /media/Pendrive
sudo mkfs.vfat -n Pendrive -I /dev/sdb1
@manuelmorales
manuelmorales / delete_old_dirs.sh
Created May 28, 2012 07:32
Delete dirs older (last modified before) than a week
# From http://systembash.com/content/delete-directories-older-than-week/
for i in `find /home/backup/ -maxdepth 1 -type d -mtime +7 -print`; do echo -e "Deleting directory $i";rm -rf $i; done
@manuelmorales
manuelmorales / select_values.rb
Created May 23, 2012 13:32
How to make ActiveRecord return just an array of values
User.connection.select_values User.select('id').to_sql
# => [1,2,3,4]
@manuelmorales
manuelmorales / log_methods.rb
Created May 22, 2012 15:36
How to log every single call to a ruby instance
# From http://stackoverflow.com/questions/5513558/executing-code-for-every-method-call-in-a-ruby-module
class ChattyArray < Array
Array.instance_methods.each do |name|
m = instance_method(name)
define_method name do |*args, &block|
# puts caller.grep(/app_name/) if name == :certain_method
puts ([name] + args).inspect
m.bind(self).(*args, &block)
end
end
@manuelmorales
manuelmorales / ssh_keys_examples.sh
Last active October 4, 2015 23:47
Common ssh keys operations
# Generate fingerprint from public key
ssh-keygen -lf id_rsa.pub
# Forward keys
# ~/.ssh/config
host *
ForwardAgent yes
# Make forwarded keys available to root
sudo su -l -c "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK; bash"
@manuelmorales
manuelmorales / nslookup_example.rb
Last active October 4, 2015 22:58
Resolve DNS with the command line
`nslookup my.workshare.com 8.8.8.8`
list = %w{
8.8.8.8
8.8.4.4
156.154.70.1
156.154.71.1
208.67.222.222
208.67.220.220
198.153.192.1
@manuelmorales
manuelmorales / merge_only_one_file_from_another_branch.sh
Created May 10, 2012 10:15
How to merge just one file from a another branch with Git
## Lets suppose that we want to merge path/to/my/file.txt from branch_a into branch_b
# We start in branch_b
git checkout branch_b
# We create an intermediate branch
git checkout -b intermediate_branch
# We merge merge_a into that
git merge branch_a
@manuelmorales
manuelmorales / gist:2558759
Created April 30, 2012 14:24 — forked from lennart/gist:1717337
A Gentoo startup script for the newrelic server monitor daemon
#!/sbin/runscript
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
depend() {
need net
}
start() {
@manuelmorales
manuelmorales / audio_to_mp3.rb
Created April 27, 2012 21:57
Reencode audio of an AVI to MP3
#!/usr/bin/ruby
ARGV.each do |input_f|
everything_ok = true
# Escapes single quotes
input_f = input_f.split("'").join("\'\\'\'")
# Extracts the file name without extension
file_name = input_f.split(".")[0..-2].join(".")