Feb 17, 2012

Troubleshooting GitHub Enterprise

I don't know why, but I'm always unlucky with Linux...

Two years ago I decided to stop using linux (Ubuntu) when a supposedly safe upgrade broke my graphical interface just before a demo. Since both, my patience and time, are very limited, I decided to switch to Mac and I've been a happy user.

But today, I had to setup an Ubuntu box for testing. For the first time I really liked what I saw. The graphical interface and new HUD were clean and useful...

I installed OpenSSH, the client and the server, I generated the ssh keys and got my personal GitHub account working fine...

$ ssh-keygen -t rsa
...
$ ssh -T git@github.com
Hi bitparagon! You've successfully authenticated, 
but GitHub does not provide shell access.


And everything was going okay... until I had to setup the GitHub Enterprise in our corporate environment... a then

$ ssh -T git@git.corp.bitparagon.com
...
Connection closed by 10.10.203.53
fatal: The remote end hung up unexpectedly


Then inspecting in detail

$ ssh -Tv git@git.corp.bitparagon.com
...
...
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_1000' not found
debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_1000' not found
debug1: Unspecified GSS failure.  Minor code may provide more information
debug1: Next authentication method: publickey
debug1: Offering public key: /home/bitparagon/.ssh/id_rsa
# authentication by public key then proceeded quickly
...

After googling, regenerating the ssh key several times and cleaning the ~/.ssh/ directory, finally the solution was to generate the ssh key using dsa instead or rsa. So odd... so weird...

$ ssh-keygen -t dsa

This is one of the things I will keep complaining about Linux, in a Mac you never have to dig so deep to solve something that shouldn't be an issue... anyway I'll give my Ubuntu box one more chance...




Feb 16, 2012

On the other side of the Pacific, again...

I cannot complain, I've had many adventures in my life... but I've had never imagined the Ruby will take me to this side of the Pacific Ocean again.

A day like today, one year ago, I was on the coast of Japan waking up at 6:00am, removing the ice from the windshield, warming up the engine, taking Alex for a walk and getting ready to take the train at 7:30am to arrive at 9:00am to the office...

Now I'm on the coast of California, I wake up at 7:30am... I bake some bread for breakfast... and arrive to the office at 8:30am...  in a beautiful sunny day.

I though immigration was a very complicate process... well now that I think it again, yeah it was... but I think I learnt a lot and I should share all what I learnt...



Dec 11, 2010

Splitting a Japanese String, the old Ruby way

If you are lucky enough, you should be using ruby 1.9 right now. In that case this post makes no sense.

But if you are stuck in an older version of ruby (1.8.6~1.8.7) and you tried to process a Japanese (or non-single byte encoding) string, then you know what I mean.

For example
text = "日本語能力試験"
text.slice(0,3) # Returns the first 3 bytes
will give you the first 3 bytes, not the first 3 characters as you would expect.

In older versions of ruby previous to 1.9, most of the string functions operate at byte level.

A horrible workaround I found very useful is to match the text with a regular expression to select the part of the text you want to process.

text = "日本語能力試験"
text.scan(/.{3}/)[0] # Returns the first 3 characters

This is very useful for parsing web pages (specially the old ones!), which usually are a terrible combination of encodings.




Dec 4, 2010

Getting the Number of Pages in PDF Files with Ruby

Just a brief snippet on how to get the number of pages in a PDF file.
It works most of the time for conventional PDF files (not encrypted and not protected by password).

file = File.open('myfile.pdf','rb') 
# 'rb' Required for windows!!!
text = file.read
file.close

keyword_c = text.scan(/Count\s+(\d+)/).size
keyword_t = text.scan(/\/Type\s*\/Page[^s]/).size

pages = keyword_c > keyword_t ? keyword_c : keyword_t

puts "Total pages: #{pages}"