Thursday, October 4, 2018

Installing Cisco Packet Tracer 7.2 in Ubuntu 18.04

There are a few problems that occur when installing Cisco's Packet Tracer in Ubuntu 18.04, mainly permission issues and a missing dependency. Here are the steps I took to get it up and running.
  1. Log in to netacad.com (or register first, it's free)
  2. Go to Resources->Download Packet Tracer
  3. Click the link for "64 Bit Download" under Linux Desktop Version 7.2 English
  4. Move the downloaded file to the folder of your choice and extract it. Note that sudo is required to avoid permission problems (I know, this shouldn't be needed if the file was created properly).
    sudo tar xvzf Packet\ Tracer\ 7.2\ for\ Linux\ 64\ bit.tar.gz
  5. Run the install script
    sudo ./install
  6. Read the EULA and, if you agree to it, accept it by pressing "Y"
  7. Press "Enter" for the default installation directory
  8. Press "Y" to create a symbolic link to run Packet Tracer
  9. As requested, restart the computer (NOTE: logging out and back in may work instead of a reboot)
  10. At this point, Packet Trace is installed, but it is missing a dependency. If you try to run it, it will print "Starting Packet Tracer 7.2" and just drop you back to a prompt and nothing will happen. The "packettracer" command is a script that actually runs /opt/pt/bin/PacketTracer7. When running this directly, it complains about not finding libpng12.
  11. Get the libpng12 package
    wget http://ftp.debian.org/debian/pool/main/libp/libpng/libpng12-0_1.2.50-2+deb8u3_amd64.deb
  12. Install the libpng12 package
    sudo dpkg -i libpng12-0_1.2.50-2+deb8u3_amd64.deb
  13. Type "packettracer" and Packet Tracer should start up normally

Monday, December 29, 2014

Extract Locally Stored MP3s From Google Music On Android

I needed a way to copy the music that is stored locally on my Android device. I couldn't just copy the files over since they have nondescript names like 153.mp3, 214.mp3, etc. Well, I could have just copied them, but I didn't want to have to listen to all of them and then rename them appropriately. I could have downloaded them with Google Music Manager but there is a limit to the number of times you can download them (two, I think). But more importantly to me, I have a data cap and I have already downloaded them by selecting "Keep on device" and didn't want to download them again. What I did was use the music database to gather information and use that to copy and rename the files.

What is needed:
-a rooted device in order to access the music files
-adb installed on the PC (see here for info on adb)
-Python installed on the PC (although I imagine this could be done in a Bash script too)
-the Android device connected to the PC so adb can access it

A few notes:
-The music is copied to the current folder as Artist/Album/Tracks.
-Copying the MP3 files from the device can take a while. Patience is a virtue.
-The paths created are *nix style, i.e. uses forward slashes. Windows users might need to change to back slashes
-There isn't any error checking, so if adb fails or sqlite3 isn't installed, who knows what will happen?

Finally, here is the python script.

#!/usr/bin/python
# Extract locally stored music from Google Music and rename the files properly
# 12-08-2014  Created by Bill Blankenship

import subprocess
import sqlite3
import os

# Get a copy of the music database
subprocess.check_call(["adb", "pull", "/data/data/com.google.android.music/databases/music.db"])
subprocess.check_call(["adb", "pull", "/data/data/com.google.android.music/databases/music.db-journal"])

# Get the mp3 files
raw_input("Getting ready to copy mp3 files from the device. This can take a while.\nPress Ctl-C to abort or Enter to continue...")
subprocess.check_call(["adb", "pull", "/data/data/com.google.android.music/files/music/"])

# Get needed info from the database
db = sqlite3.connect("music.db")
cursor = db.cursor()
cursor.execute('''select Id, LocalCopyPath, Title, Album, Artist, TrackNumber from MUSIC where LocalCopyPath is not NULL''')
all_rows = cursor.fetchall()

# Iterate through each song 
for row in all_rows:
  # Replace "/" with "-" in track names 'cause they're trouble
  # Apparently tuples are immutable, so create more variables 
  LocalPath = row[1].replace("/","-")
  Title = row[2].replace("/","-")
  Album = row[3].replace("/","-")
  Artist = row[4].replace("/","-")
  TrackNumber = row[5]

  # Make TrackNumber two digits (and a string)
  if TrackNumber < 10:
    TrackNumber = "0"+str(TrackNumber)
  else:
    TrackNumber = str(TrackNumber)

  # Create Artist folder if needed
  if not os.path.isdir(Artist):
    os.makedirs(Artist)
  # Create Album folder if needed
  if not os.path.isdir(Artist+"/"+Album):
    os.makedirs(Artist+"/"+Album)
  # Move and rename tracks
  print("Copying "+LocalPath+" to "+Artist+"/"+Album+"/"+TrackNumber+"-"+Title+".mp3")
  os.rename(LocalPath, Artist+"/"+Album+"/"+TrackNumber+"-"+Title+".mp3")
db.close()

# Remove the music database files
os.remove("music.db")
os.remove("music.db-journal")

Tuesday, September 16, 2014

Video Capture from a Hauppauge USBLive 2 Using ffmpeg

I haven't had much luck using my Hauppauge USBLive 2 capture device in Linux. The device works OK, but the quality is terrible whenever I use mencoder or VLC to capture. As a result, I have to boot Windows and use Hauppauge's software whenever I want to capture video. I find this annoying, so I thought I would see if ffmpeg would do the job in Linux.

My goal was to produce an output file that had the same properties as the file created in Windows. This means some of the options I used might not be the best ones. I used mediainfo to compare the properties of the files produced with ffmpeg and the Windows software.

So, here is the command line I came up with (this is a single line):
ffmpeg -f alsa -i hw:1 -f v4l2 -channel 1 -i /dev/video1 -c:a mp2 -b:v 8500k -minrate:v 8500k -maxrate:v 8500k -bufsize:v 2M -pix_fmt yuv420p -flags +ilme -bf 2 -vf mp=eq2=1:1:-0.05 -aspect 3:2 outputfile.ts

Looks complicated and scary, but it really isn't. Here are the options:
-f alsa (set alsa format for the audio input)

-i hw:1 (use audio input #1, #0 is the microphone on my laptop)

-f v4l2 (set v4l2 format for the video input)

-channel 1 (set capture input: 0=composite, 1=S-video)

-i /dev/video1 (use video1 for video input, video0 is the camera on my laptop)

-c:a mp2 (set the audio codec to mp2)

-b:v 8200k  (set the video bitrate to 8200k)

-minrate:v 8200k  (set min video bitrate to 8200k)

-maxrate:v 8200k  (set max video bitrate to 8200k)

-bufsize:v 2M  (set video bufsize to 2M)

-pix_fmt yuv420p  (set chroma format)

-flags +ilme (set interlace mode)

-bf 2  (set B frame rate)

-vf mp=eq2=1:1:-0.05 (video filter to adjust gamma:contrast:brightness: default= 1:1:0)

-aspect 3:2 (set aspect since -vf mp=eq2... causes aspect error on playback)

I spent way too much time searching for the "channel" option. ffmpeg kept insisting on using input 0 (composite). Even when I used v4l2-ctl to set the input to S-video, ffmpeg would change it back. I knew there had to be a way to set this, but I couldn't find it any of the documentation I read. I finally found it in some archived post about ffmpeg.

The output files created with the Windows software had a constant bitrate of 9000 kbits. The bitrate settings above try to simulate a constant bitrate. For whatever reason, using 9000k resulted in the bitrate being too high. Trial and error allowed me to settle on 8200k to give approximately 9000k in the output file.

I kept interlaced mode because that's what the Windows software creates. Anyway, I use Handbrake to crop, deinterlace (or more precisely decomb), and convert to MP4.

The ffmpeg results seemed washed out compared to the Windows results. Reducing the brightness a bit seems to help (the -vf option above).

There is one problem with the above command. There isn't any way to view the video as it is being captured. There are two possible solutions. If you know how long you want to capture and don't need to view the video stream, then just add the -t option, as -t #secs or -t hh:mm:ss. If you do need view the video, then another output must be added to the ffmpeg command (ffmpeg can handle multiple outputs, and inputs). I do this by adding the following right before the output file name:
-f mpegts -b:v 1M udp://ipaddress:9999
You can then view the video using:
ffplay udp://ipaddress:9999

So far the results have been pretty good. I might eventually try to convert directly to mp4, but I'll have to find some way to autocrop.

So what ffmpeg options would you use instead of the above?

What do you use to capture video in Linux?

Friday, June 20, 2014

FIX: Android device doesn't show up in Google Play Store device list

Somewhere along the way while flashing updates to the AOKP ROM to my Nexus 7 (2012), the Nexus stopped showing up in the device list on the web version of the Google Play store. But the Play store functioned properly on the Nexus: I could install new apps, got updates for existing apps, etc.

Since I saw the problem on the Play website and Play worked great on the Nexus itself, I thought the problem was "Google-wide". I cleared cache and data for Google Play services on the Nexus. No luck. I went to the Google dashboard and deleted the duplicate entries for my N7 (duplicates are a result of flashing ROMs to my device). Didn't work.

It turns out my assumption that the problem was Google-wide was wrong. The fix turned out to be easy.

This fixed the problem for me:

  • Clear Play Store data. Go to Settings->Apps and scroll down until you see Google Play Store and tap it. Tap Clear Cache and then Clear Data. 
  • Reboot device
  • Wait a few minutes
  • Check the Play store website
  • Do a happy dance
After doing this, my Nexus 7 shows up again.




Thursday, January 23, 2014

Python Script to Remove Unbreakable Blocks in Robominer


Robominer is an Android game where you use a robot to drill around searching for a diamond. There are blocks that can't be drilled, so you have to either go around them or use dynamite to blow them up. After a while, I got really annoyed dealing with these blocks. So I poked around and found a way to replace them with other blocks.

Basically, when you save a game, it saves the entire map too. This includes the types and locations of all of the blocks. The save file can be modified to remove the unbreakable blocks.

I have SL4A and Python installed on my Android device, so I wrote a Python script I can run on my device to make the changes for me. If needed, you can also copy the file to a PC, run the script, and then copy it back. Note, however, that the script has to be run on every new level. Being able to run the script on the device is a lot more convenient.

Here is the script. It assumes your saved game file is on the SD card. I don't think you can modify the save file in the "Phone" slot unless your device is rooted.



#!/usr/bin/python
# Replace gray blocks with regular blocks on Android app Robominer
#
# 01-15-2013: Created by BitJunkie
# 01-16-2013: For gray blocks, generate random mineral type
# 01-22-2013: Block info starts 3 bytes before 0x3f80, adjust file pointer info
import random 

count=0
random.seed()
# Open the file in binary mode for reading and writing
fh=open("/sdcard/Android/data/com.rnet.robominer/files/last_1.sav","rb+")

# Go to the beginning of the block info +3 bytes, from the beginning of the file
fh.seek(0x30, 0)
header = fh.read(2)

while header == b"\x3f\x80": 
  fh.seek(-4,1)  # Move file pointer to start of block info
  blk = fh.read(1)
  if blk == b"\x01": # if block is gray
    fh.seek(-1,1)
    fh.write(b"\x02")  # Make it regular 
    r = random.sample(["\x01","\x02","\x03","\x04","\x05","\x06","\x07","\x08","\x09","\x0a","\x0b","\x0c","\x0d","\x0e","\x0f","\x10","\x11","\x12"],1)
    fh.write(r[0])  # Add random mineral/element
    fh.seek(13,1)  # Go to next block
    count+=1  # Count how many blocks are changed
  else:
  # Go to next block header
    fh.seek(14,1)
  header = fh.read(2)

print "Blocks changed: %d" % count

I have only used this for games on the "Easy" level. I'm sure the script would have to be modified for the higher difficulties.

Have fun!

Thursday, January 9, 2014

Gift Codes for Despicable Me: Minion Rush

Updated 5/14/2015. See below.
Updated 3/28/2015. See below.
Updated 2/11/2015. See below.
Updated 12/10/2014. See below.
Etc., etc.

NOTE: Comments are moderated, so it might take a while for posted comments to show up.

Despicable Me: Minion Rush is a running game for Android (maybe other OSes too). If you select Options from the main screen and press the gift icon, you can enter codes here to get some goodies. Here are the codes I've found so far.

Use the up and down arrows to select different minion types. The different types are: classic, baby, maid, golfer, dancer, firefighter, and dad.

classic, firefighter, baby: Unlock Baby minion
baby, dancer, golfer: Unlock x5 score perks
baby, firefighter, maid: Unlock x5 banana points
maid, classic, golfer: Unlock loser taunt
dancer, firefighter, dad: Unlock x3 minion launcher
----------------------------------------------------------------------------
May 14, 2015 Update: Version 2.8.0k; Content Version 421 (also Version 2.8.1d) 
Looks like gift codes have been removed in this update.
----------------------------------------------------------------------------
March 28, 2015 Update: Version 2.7.1c; Content Version 412
This update adds an April Fools Day special mission. But I didn't find any new gift codes in this update. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
February 11, 2015 Update: Version 2.6.2c; Content Version 398
This update adds a Valentine's Day special mission. But I didn't find any new gift codes in this update. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
December 10, 2014 Update: Version 2.5.0p; Content Version 383
This update adds special missions, in particular the Arctic Base mission. But I didn't find any new gift codes in this update. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
November 10, 2014 Update: Version 2.3.1a; Content Version 370
I didn't find any new codes in this update. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
November 8, 2014 Update: Version 2.3.0f; Content Version 370
No surprise, I didn't find any new codes in this update. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
October 21, 2014 Update: Version 2.2.1f; Content Version 367
I didn't find any new codes in this update. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
September 18, 2014 Update: Version 2.1.0m; Content Version 343
I didn't find any new codes in this update. I'm starting to think this feature isn't used anymore. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
August 20, 2014 Update: Version 2.0.3b; Content Version 326
I didn't find any new codes in this update. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
July 30, 2014 Update: Version 2.0.2e; Content Version 325
Big update. The game mechanics have changed, but gameplay is about the same. But I didn't find any new codes in this update. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
May 26, 2014 Update: Version 1.8.1g; Content Version 294
I didn't find any new codes in this update. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
May 14, 2014 Update: Version 1.8.0u; Content Version 289
I didn't find any new codes in this update. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
March 22, 2014 Update: Version 1.7.2; Content Version 227
I didn't find any new codes in this update. If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
February 10, 2014 Update: Version 1.6.1b; Content Version 202
I didn't find any new codes in this update. :( If you find any, please leave a comment to let me know.
----------------------------------------------------------------------------
January 2014 Update: Version 1.6.0u; Content Version 200
Golfer, golfer, baby: x3 Score Perks

Golfer, dancer, dad: 20 Tokens

Dancer, maid, baby: x3 Banana Perks

Dad, baby, dancer: 1500 Bananas


Enjoy!

Thursday, November 7, 2013

Colors and Split Screens in Vim

Here is some info on vim that I put here mainly for my reference. Maybe someone else will find them useful.

Color schemes
Set the color scheme in .vimrc, e.g. add a line like "colorscheme ron"
In vim, you can list the color schemes with ":colo <TAB>" (space after "colo")
If no colors after setting the color scheme, make sure syntax is enabled. In .vimrc add the line "syntax on".

Editing Multiple Files
:ls - List open files
:n or :bn - Go to next file
:p or :bp - Go to previous file
:b10 - Go to 10th file
:b foo - Go to file named "foo"
:b <TAB-KEY> - Cycle through open files (space after ":b")
CTRL-w v - Split screen vertically
CTRL-w s - Split screen horizontally
CTRL-w h and CTRL-w l - Switch through vertical windows
CTRL-w k and CTRL-w j - Switch through horizontal windows