Bikepacking to China Camp in CA

I did it! I finally did it! I went on a small adventure by myself! and it was exciting, vibrant and scary at times!
I wanted to do a quick recap on how things went hence this post

For the longest time I wanted to do a bikepacking trip, but what’s exactly bikepacking?
It comes from mixing two other sports: cycling and backpacking.
You ride your bike loaded with your camping gear to get to a certain spot, camp and so on. Think about it as a different type of bike touring (or perhaps they are the same thing!)

Planning

I ended up removing the orange bag from the frame

Since this was the first time I was going to try bikepacking I decided to start with a manageable distance and a some-what controlled camping experience.

  • The start/end point: San Francisco Ferry Building.
  • The destination: China Camp State Park in San Rafael, CA.
  • Distance:  48 Km on day 1, 46.4 Km on day 2 for a total of 94.4 Km
  • Bike: Marin Gestalt II
  • Tires: 35mm 700x30c
  • Bags: 15L Mission Workshop bag plus a big Saddle bag.
  • Camping Gear: Nemo Hornet 1 person tent,  Nemo 15F sleeping bag, Sea to Summit sleeping pad
  • Extras: food, toiletries and headphones
  • Navigation: Garmin Fenix 5 loaded with a GPX map that I made

The Route

All paved and nice road!

I started riding late (10:45 am) so I could get there just in time to check-in to my campsite (2 pm). I knew I was going to make several stops and generally riding slow just so I could enjoy the route more. This part of the plan was a success. I stopped at Crissy Field, The Golden Gate Bridge, Sausalito and finally grabbed a byte at Andy’s local market in Marin County.
100% of this route is paved. Most of it is really enjoyable, except a 5km stretch in San Rafael where there’s a highway cross. Be careful over there!

Camping

Home sweet home
My spooky friend

The camping experience wasn’t five stars but that’s on me. I left a banana peal in my backpack and its smell attracted a deer who started to sniff around my head at 2 am. That took me by surprise and really scared me. I managed to snap a picture of her though! 

Regarding the facilities, China Camp is great! camp grounds are marked, clean and there’s also showers and a couple of big restrooms. This is a kid friendly spot so expect to see them, hear them and be around them.

What worked

  • The overall plan was a success. I made it in-n-out safely
  • Navigation was great even though I only used the breadcrumbs the watch was giving me
  • 35mm tires where big enough and rolled fast enough
  • Saddle bag was great! I couldn’t have done the trip without it. Thanks Mike!
  • Packing strategy was good, enough food, clothes and gear for both days

What can be improved

  • I will never ride again with so much weight on my back. I never ride with a backpack so having one (and heavy!) for hours on me definitely took a toll. Seriously, don’t go bikepacking like this. Better to install a pannier on your bike and just ride like that
  • I need to get better at sleeping outside. My nose gets super dry and my body gets super hot. I’m sure I can adjust some variables regarding my equipment so I make this experience more  fun
  • I need a portable pillow
  • No more leaving the trash in my backpack…

What’s next

There were ups and downs in this trip but I’ll definitely stick to it. Even though this wasn’t a big ride I got to meet good people on the road (Rancho Shazam) and the overall positive vibe I got on the road was heartwarming. I’ll welcome that anytime!

I hope to go out there again before the end of the year to get more practice so on 2019 I can do this in South America! or perhaps Europe? who knows! we can pedal the world!

Cheers!

Resources

2018 in review

Work in progress…

2018 is wrapping up and I didn’t want to let the year slip by without making a reflection of what it meant to me. It was an exciting year! full of learning experiences and challenges.

I’ll break the yearly review in several topics:

  • Engineering/Career
  • Sports / Training
  • Nutrition / Cooking
  • Mental health
  • Travel
  • Creative outlet

Expect a link on every topic once the corresponding post is ready!

Sieve of Eratosthenes

I had a bad experience with the Sieve of Eratosthenes during a college test. I became traumatized by it and tried to avoid it. During this holiday break I  successfully implemented it ruby

My favorite parts of this algorithm were:

* The fact that I don’t have to iterate the whole sieve! I can do it just for _sqrt(n) _since the factors of any number are always composed by two numbers and one of them is always lower than the _sqrt_ of any given number n.

* The usage of ruby’s inline _if _statements

An important note about slices in Go

I’m new in Go and this seems important so it’s better to digest it and point it out. A slice is not an array. A slice describes a piece of an array. Its internal structure can be _described_ as the following:

  type sliceHeader struct {
    Length        int
    ZerothElement *byte //Assuming that the array that we are pointing to has byte type.
    }

It’s important to note that there is a pointer inside the structure, but what implications can that have?
Let’s check the following example:

    
      func AddOneToEachElement(slice []byte) {
          for i := range slice {
              slice[i]++
          }
       }
      func main() {
            slice := buffer[10:20]
            for i := 0; i < len(slice); i++ {
                slice[i] = byte(i)
            }
            fmt.Println("before", slice)
            AddOneToEachElement(slice)
            fmt.Println("after", slice)
      }
Output:
        before [0 1 2 3 4 5 6 7 8 9]
        after [1 2 3 4 5 6 7 8 9 10]

So, the slice is passed as value, that means that the slice that is inside AddOneToEachElement is a copy from the slice in main, right? so will the output after calling that function will be the same? after all it’s just a copy isn’t it? Yes it’s a copy but a copy containing a pointer, that means that even to copy will have access to the original referenced data, that implies the following affirmation: **”The content of a slice can be modified”** But what happens if I do the following?

 func SubtractOneFromLength(slice []byte) []byte {
            slice = slice[0 : len(slice)-1]
            return slice
        }
    
        func main() {
            fmt.Println("Before: len(slice) =", len(slice))
            newSlice := SubtractOneFromLength(slice)
            fmt.Println("After:  len(slice) =", len(slice))
            fmt.Println("After:  len(newSlice) =", len(newSlice))
        }

The creation of a slice inside the subtraction function implies a new allocation, that means a new place to point, but wait a minute, am I allowed to modify the pointer inside my head structure? well for sure the program will compile and run but the behavior won’t be the one that we expect, the output will be:

 
        Before: len(slice) = 50
        After:  len(slice) = 50
        After:  len(newSlice) = 49

And that means: **”The contents of a slice argument can be modified by a function, but its header cannot.” ** It’s important to keep this in mind to be aware of unexpected behaviors while we are working. If you are an experienced Go programmer you may find this example familiar, it took it from [here](http://blog.golang.org/slices). Hope it helps anyone in the way that writing this helped me to understand it 🙂

A Client / Server prototype in Go

I started my batch at Recurse Center two weeks ago. One of my goals for the batch is to become proficient in go. To get started I went through “A tour of Go”, after that I decided to work on my first Go project.

The project was a Client / Server conversation, a limited conversation. As a client you are able to connect to an IP:PORT server and send three commands to the server: {1: ls, 2: who, 3: pwd}. As a server you are able to bind a port on your localhost and listen, execute and resolve (return) the requests of the client. The server is able to support multiple clients and request at the same time thanks to Goroutines.

So, what challenges I’ve faced during this project? being my first project in go the simple fact to make the program compile was a challenge in the beginning… then I realize I didn’t understood the language quite well… in the end this turned to be a fun first experience with go.

Check it out:

 readed := 0
    response := make([]byte, 8)
    
    for {
        //Read from server
        readed, err = con.Read(response)
        fmt.Print(string(response))
        if readed != len(response) {
        //Read request from keyboard
            fmt.Print("ftp> ")
            _, err = fmt.Scanf("%s", &request)
         if request == "quit" {
             break
         }
         //Send to server
         _, err = con.Write([]byte(request))
         //Valid terminated string
         _, err = con.Write([]byte("\r"))
        }
        if err != nil {
            return fmt.Errorf("Interact error: %s", err)
        }
        response = make([]byte, 8)
    }

Cheers!

Connect to Airport Extreme Shared Disk from Linux

Recently I bought an Apple Airport Extreme to improve WiFi connectivity at home. I’m very happy with the results.

Airport Extreme allows you to share a hard drive over the network, since one of my computers runs Linux I decided to modify my fstab to auto mount the shared drive into the Linux box.

sudo mkdir /media/airport
sudo vim /etc/fstab

Add the following information at the end of that file (_in one line_):

//YOUR.AIPORT.IP.ADDR/YOURAIRPORTWORKDIR 
/media/airport/ cifs auto,
iocharset=utf8,nobrl,username=AirportUsername,
password=AirportPass,
_netdev,uid=LinuxUser,gid=LinuxGroup

Finally, auto mount your new fstab entry using:

marin@Corsair$> sudo mount -a

And that’s it!

Violent Python Chapter #1 Final

And that’s all for the chapter #1! The last exercise was fun as well. It is a Zip file  password cracker.

    #
    # Violent Python Chapter #1
    # The Cuckoo's Egg: a simple password decrypter
    # By: Marin Alcaraz
    #
    
    import crypt
    import hashlib
    
    def testPass(cryptPass):
        salt = cryptPass[0:2]
        dictFile = open('dictionary.txt', 'r')
        for word in dictFile.readlines():
            word = word.strip('\n')
            cryptWord = crypt.crypt(word, salt)
            if (cryptWord == cryptPass or hashlib.sha512(word) == cryptPass):
                print "[+] Found Password: " + word + "\n"
                return
        print "[-] Password not found.\n"
        return
    
    def main():
        passFile = open("passwords.txt", 'r')
        for line in passFile.readlines():
            if ":" in line:
                user = line.split(':')[0]
                cryptPass = line.split(':')[1].strip(' ')
                print "[*] Cracking Password for: user[" + user + "]\n"
                testPass(cryptPass)
        return
    
    if __name__ == "__main__":
        main()

 

Violent Python Chapter #1 Part 2

I’ve finished the second exercise from Violent Python’s Chapter #1 “The cuckoo’s egg”, it is a password decrypter. Here’s the code:

    #
    # Violent Python Chapter #1
    # The Cuckoo's Egg: a simple password decrypter
    # By: Marin Alcaraz
    #
    
    import crypt
    import hashlib
    
    def testPass(cryptPass):
        salt = cryptPass[0:2]
        dictFile = open('dictionary.txt', 'r')
        for word in dictFile.readlines():
            word = word.strip('\n')
            cryptWord = crypt.crypt(word, salt)
            if (cryptWord == cryptPass or hashlib.sha512(word) == cryptPass):
                print "[+] Found Password: " + word + "\n"
                return
        print "[-] Password not found.\n"
        return
    
    def main():
        passFile = open("passwords.txt", 'r')
        for line in passFile.readlines():
            if ":" in line:
                user = line.split(':')[0]
                cryptPass = line.split(':')[1].strip(' ')
                print "[*] Cracking Password for: user[" + user + "]\n"
                testPass(cryptPass)
        return
    
    if __name__ == "__main__":
        main()

Violent Python Chapter #1

I’ll try to post a some excerpts about the book Violent Python here. This posts references the first part of chapter #1. In chapter one you work on three mini projects:

  • Vulnerability Scanner
  • The Cuckoo’s egg
  • Zip file Cracker

The first exercise aims to build a vulnerability scanner. You are supposed to read full of vulnerable program definitions and compare it against services running in a remote server.

    #
    # Violent Python Chapter #1
    # Vuln Scanner
    # By: Marin Alcaraz
    #
    
    import sys
    import os
    import socket
    
    def retBanner(ip, port):
        try:
            socket.setdefaulttimeout(2)
            s = socket.socket()
            s.connect((ip, port))
            banner = s.recv(1024)
            return banner
        except Exception, e:
           return  str(e)
    
    def checkFile(filename):
        try:
            if not os.path.isfile(filename):
                raise Exception("File doesn't exist")
                return -1
            if not os.access(filename, os.R_OK):
                raise Exception("Permission Denied")
            f = open(filename, 'r')
            return f
        except Exception, e:
            print str(e)
            return -1
    
    
    def checkVulns(banner, filename):
        print "[+] Reading Vulnerable Banner list from: " + filename
        f = checkFile(filename)
        for line in f.readlines():
            print "[+] Checking for banner: " + line.strip('\n')
            if line.strip('\n') in banner:
                print "[+] Server is Vulnerable: " + banner.strip('\n')
            else:
                print '[-] FTP Server is not vulnerable'
        return
    
    def main():
        portList = [21, 22, 25, 80, 110, 443]
        if (len(sys.argv) == 2):
            filename = sys.argv[1]
        else:
            filename = "vuln_banners.txt"
        for x in range(1, 255):
            ip = '192.168.95.' + str(x)
            for port in portList:
                banner = retBanner(ip, port)
                if banner:
                    print '[+] ' + ip + ': ' + banner
                    if (checkVulns(banner, filename) == -1):
                        return
    
    
    if __name__ == '__main__':
        main()

Notes:

  • Python reserves memory space for variables when programmer declares them. Python interpreter decides the type of the variable. You can get the type of a variable via type() function.
  • The Python dictionary provides a hash table that can store any number of Python objects. It follows the classic key->value method. You can get the available keys via the .keys() function, you are also able to verify the existence of one key with has_key() or see the whole list with items(). Direct access to the elements is provided via data[‘key’] scheme.
  • The socket module provides a library for making network connections using Python.
  • Python provides exception handling capability with try and except.
  • The keyword def() begins a function, the variables between () are passed by reference meaning that any changes to these variables inside the function will affect their value from the calling function.
  • Python provides an easy way to interact with files through the open() and readlines functions. Full i/o API is of course available at Python’s website.
  • The built in sys modules provides access to objects used or maintained by the Python interpreter. Ex: argv.
  • OS module allows Python to communicate with local OS library.

Django-Vim code autocomplete

Recently I came back to Django development and after a year my set of tools had change a lot. Mainly because vim became my main text editor. The following lines of code will turn vim into a more powerful tool to work with Django and Python, place them inside your .vimrc:

"--ENABLE PYTHON/DJANGO OMNICOMPLETE
    
    filetype plugin on
    set omnifunc=syntaxcomplete#Complete
    autocmd FileType python set omnifunc=pythoncomplete#Complete
    autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
    autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
    autocmd FileType css set omnifunc=csscomplete#CompleteCSS
    
    "--SuperTab Integration
    set completeopt-=previewtj
    let g:SuperTabDefaultCompletionType = ""
    let g:SuperTabDefaultCompletionType = "context"

First lines are activating the Omni Completion feature of Vim for those type of files and the last lines reference Super Tab which installed as a plugin. Now we will define a wrapper, paste this lines inside a file called djvim (DON’T FORGET TO MODIFY YOUR PROJECT PATH):

PROJECT_PATH="/home/marin/Code"
    if [ $# -eq 2 ]
    then
            export PYTHONPATH="$PROJECT_PATH/$1"
            export DJANGO_SETTINGS_MODULE=$1.settings
            vim $2
    else
            echo "Usage: djvim [Project] [File]"
    fi

then make the file executable and move it to your /bin folder, that will do the trick. Test djvim with:

user@machine:$ djvim myproject models.py

and inside Vim type:

:python from django import db

Then test the autocomplete with some functions, launch it with the Tab key.