Skip to content

Instantly share code, notes, and snippets.

View jbgutierrez's full-sized avatar

Javier Blanco Gutiérrez jbgutierrez

View GitHub Profile
@jbgutierrez
jbgutierrez / CheckItunesLibrary.java
Created June 7, 2009 17:24
Así es como tenía consistente el catálogo de iTunes antes de conocer http://dougscripts.com/itunes/
import com.sun.org.apache.bcel.internal.classfile.JavaClass;
import java.util.Arrays;
import javax.xml.xpath.*;
import java.io.File;
import java.io.FileInputStream;
import org.xml.sax.InputSource;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.HashSet;
import java.net.URLDecoder;
@jbgutierrez
jbgutierrez / rm_empty_folders.sh
Created June 24, 2009 22:13
Borra directorios vacíos de un repositorio de subversion
#!/bin/bash
# init
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
# look for empty dir
for SUBDIR in `find . -type d | grep -v .svn`; do
if [ ! "$(ls $SUBDIR)" ]; then
rm -rf $SUBDIR
echo "$SUBDIR is Empty"
@jbgutierrez
jbgutierrez / migrateSVNwithGIT.sh
Created September 24, 2009 07:13
Migrate SVN repository with git-svn
git config --global svn.addAuthorFrom true
git config --global svn.useLogAuthor true
git svn clone NEW_URL new
git svn clone ORIGINAL_URL original
cd original
git push ../new/.git master:refs/heads/original
cd ../new
git filter-branch --msg-filter 'sed -e /^git-svn-id:/d' original
echo `git rev-list original | tail -1` `git rev-list master | tail -1` >> .git/info/grafts
git merge original
@jbgutierrez
jbgutierrez / gist:211888
Created October 16, 2009 16:46
Solution for the Rubylearning Challenge #2 (http://tinyurl.com/ydyc2kv)
require 'time'
def average_time_of_day(args)
sum = 0
args.each do |arg|
sum += Time.parse(arg).to_i
sum += 60 * 60 * 24 unless arg =~ /^1[01].*pm$/ # My friend arrival is scheduled at 10pm so any time outside 10:00pm and 11:59pm means he arrived on the very next day
end
average = sum / args.length
Time.at(average).strftime("%l:%M%p").strip.downcase
end
@jbgutierrez
jbgutierrez / gist:214669
Created October 20, 2009 22:14
RAILS SHELL APPLICATION IN 10 STEPS
RAILS SHELL APPLICATION IN 10 STEPS !!!
1.- rails shell -d mysql
2.- cd shell
3.- Edit config/database.yml
4.- rake db:create
5.- ruby script\generate scaffold Command execute:string
6.- rake db:migrate
7.- Delete public/index.html
8.- Edit config/routes.rb
map.resources :commands
<script>
var toggle = function(){
alert("She loves me!");
var that = toggle;
toggle = function(){
alert("She loves me not!");
toggle = that;
}
}
#!/bin/bash
##
# *1 Tiene algo que ver con los saltos de línea pero no sé muy bien! :-(
OLDIFS=$IFS
IFS=$'\n'
FILE_NAME=$1
LINES=`svn log $FILE_NAME`
##
@jbgutierrez
jbgutierrez / find_redundant_resistors.rb
Created November 2, 2009 00:48
Solution for the Rubylearning Challenge #3 (http://tinyurl.com/yzjh4x9)
require "test/unit"
class TestFindRedundantResistors < Test::Unit::TestCase
def test_find_redundant_resistors
actual = find_redundant_resistors [
[ 'A', 'B', 50],
[ 'A', 'D', 150],
[ 'B', 'C', 250],
[ 'B', 'E', 250],
[ 'C', 'E', 350],
[ 'C', 'D', 50],
@jbgutierrez
jbgutierrez / suggested_tags_retrival.rb
Created November 13, 2009 16:52
Suggested tags retrieval with DeliciousApi
#!/usr/bin/env ruby -wKU
require 'rubygems'
require 'delicious_api'
require 'pp'
DeliciousApi::Base.wrapper = DeliciousApi::Wrapper.new 'user', 'secret'
bookmark = DeliciousApi::Bookmark.find :url => 'http://www.yahoo.com'
# bookmark = DeliciousApi::Bookmark.new 'http://www.yahoo.com' if you don't have this bookmark in your account
pp bookmark.suggested_tags