Jason’s Ranting & Raving

Those who don’t read have no advantage over those who can’t.

Archive for the ‘Programming’ Category

Mounting a Synology drive on Ubuntu Linux

Posted by jaystile on April 26, 2013

I was having a little trouble mounting my Synology network drive as described on the wiki. This is was on a clean installation of Ubuntu Linux 12.10.

These are the steps I took to figure out what was going on. First I had to find the IP address of the drive on my network. So, I downloaded nmap and then scanned my local network.

sudo apt-get install nmap
nmap -O 192.168.1.0/24

I found I was have troulbe with just using nfs as I had to use a username and password to connect to the shared drive. I found that using cifs worked for me. I installed it and then tried mounting the drive and it worked! Then I unmounted because I didn’t want to have to do this every time I wanted to access the drive.

sudo mkdir -p /mnt/synology
mount -t cifs -o username=MYUSER,password=***** //192.168.1.109/share /mnt/synology
mount -a
ls -la /mnt/synology
umount /mnt/synology

I decided I wanted a little more permanent solution. So I created incorporated the ‘Basic Method’ steps from the synology wiki. I edited the /etc/fstab with the following:

//192.168.1.109/share /mnt/synology cifs user,uid=yourusername,gid=users,rw,suid,credentials=/etc/cifspwd 0 0

Next was to create to the cifspw file.

sudo su -
echo username=yourusername > /etc/cifspwd
echo password=yourpassword >> /etc/cifspwd
chmod 0600 /etc/cifspwd
mount -a
ls -la /mnt/synology

I hope that works for you!

Update!
I built a new PC and had to try something new as my original instructions didn’t work for the fstab and creditials file.
I ran the command

 sudo su -
 dmesg | tail

I noted that there was an error: CIFS VFS: No username specified. After a quick google search some nice person posted a solution. However, it was a touch out of date as the package smbfs was retired and cifs-utils was the recommended package offered by apt-get.

sudo apt-get install cifs-utils

After a restart my mounts came back up correctly,.

Advertisements

Posted in Programming, Solutions | 3 Comments »

Roulette Betting Strategy Analysis

Posted by jaystile on June 13, 2011

My friend was speaking with me about a positive progression betting strategy that he had used successfully. Me being the analytical person that I am began obsessing about it. Why did I obsess about it? It was because I could not see how it would fail. It’s evident now but not before I modeled the strategy. Enjoy my analysis on some common strategies.

The Model
I wrote my own Roulette simulator in java. Each ‘player’ uses a specific strategy. Each player started with $300. The minimum bet on the table is $5. A maximum bet was not enforced. 100 Sessions of 100 spins were completed for the players.

The Positive Progression
There are streaks in gambling. One wishes to bet the minimum when on a losing streak and bet the maximum on a winning streak. The issue with this strategy is that those positive streaks don’t seem to come frequent enough. Each time the player wins they add one betting increment ($5) to their original bet. Once a streak of three or better comes along is when the player starts to profit.

Basic Positive Progression (-20.5%)
The first ‘flavor’ is what I’m calling the ‘Basic Positive Progression’. The player bet on black and each time they won they added one increment. When they lost they started over at the first increment.

Hedged Positive Progression (-40.2%)
If it works for betting black, it’s got to work just as well for betting black and red at the same time! The theory behind this strategy is that if the spins go back and forth between red and black the player can’wait it out’ for a streak. The same theory applies as before but executing the strategy on both red and black.

First Dozen – Positive Progression (-19.5%)
You know what is better than a streak paying you 1:1? A streak paying 2:1. This is the same Positive Progression scenario as before, but using the ‘First Dozen’ bet.

Martingale (-45.1%)
The Martingale strategy is fairly straight forward. This strategy involves the player doubling their bet until they win. Then they go back to the first increment. It is common to lose all your cash or to reach the table limit causing a giant loss.

Fibonacci (-19.7%)
This strategy involves using the Fibonacci sequence to manage the player’s bets. Each time the player wins they go back two steps to the left along the sequence. Every time they lose they move one forward to the right in the sequence. The sequence looks like this 1, 1, 2, 3, 5, 8 …

First Dozen Fibonacci (-26.1%)
Same as above but using the ‘First Dozen’ bet instead of ‘Black’.

Fibonacci Positive Progression (-11.2%)
As I was experimenting played with a positive progression strategy using the Fibonacci sequence. That means every time you win you increase the number of bet increments to the appropriate number. When you lose you start over at the first number in the sequence. I was pleasantly surprised to see the result had bested all the other strategies.

First Dozen – Fibonacci Positive Progression (-08.9%)
Then I tried with a result that pays 2:1. The numbers gave me a better result, but I am not sure why. More investigation is required.

Summary
If you are going to play Roulette just keep it in mind that you’re going to lose money. Some strategies have you lose it slower than others. You might want to consider using the First Dozen – Fibonacci Positive Progression’.

Posted in Programming | Leave a Comment »

Programming: Android setup for Ubuntu

Posted by jaystile on September 27, 2010

Android Setup
I’ve been kicking the idea around of developing some Android applications. This blog post is about setting up that initial environment.

After a quick google search, I found the Android developer page. Downloaded the Linux (i386) SDK. I was thinking that I might want to develop on Windows, but I already had a VirtualBox running Ubuntu 10.04 with the Required Eclipse and JDK. I browsed the System Retirements page http://developer.android.com/sdk/requirements.html, and it looks the VM (Virtual Machine) will be just fine.

Preconfiguration
Java development downloads go to into the /opt directory on this linux VM. Softlinks are used to help maintain version of the software.

/opt/ant/latest → /opt/app/apache-ant-1.8.1
/opt/java/latest → /opt/java/jdk1.6.0_21
/opt/eclipse/latest →/opt/eclipse/eclipse-jee-helios

The ~/.bashrc file gets updated to add variables to these locations and then export the $PATH so you can execute them on the command line.

JAVA_HOME=/opt/java/latest
ANT_HOME=/opt/ant/latest
export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH

Download the Android SDK

$ mkdir /opt/android/
$ wget http://dl.google.com/android/android-sdk_r07-linux_x86.tgz
$ tar zxvf android-sdk_r07-linux_x86.tgz
$ mv android-sdk-linux_x86 android-sdk-linux_x86-0.9.8 
$ ln -s android-sdk-linux_x86-0.9.8/ latest

ADT Plugin v 0.9.8
The Eclipse workspace has been setup to use /opt/workspace/android. Eclipse then needed to include the ADT plug-in . Add the site: https://dl-ssl.google.com/android/eclipse/ to Eclipse after selection Help → Install Software.

Install SDK Tools r7 into your SDK
The link describes adding new tools into your sdk http://developer.android.com/sdk/adding-components.html#UpdatingComponents .

Launch the android manager.

$ /opt/android/latest/tools/android

It looks like the Android SDK Tool revision 7 was already there! Moving on.
Odd
I got a pop-up from the Plug-in asking to enable statistics usage. But it was ‘unclickable’. So it’s just hanging out there now, so I’ll have to kill it from the command line. I could tell if it came from the Android manager or the ADT eclipse plugin.

First Project
Used Eclipse to try and create a new Android Project. This failed because an SDK was not defined.
Register SDK with Eclipse
Window → Preferences → Android
SDK Location: /opt/android/latest
Apply
Error
Failed to get the adb version: Cannot run program “/opt/android/latest/tools/adb”: java.io.IOException:error=2, No such file or directory.
That is very odd. The file is navigable from the command line. However, when trying to execute it from the command line like ./adb, the bash: ./adb: No such file or directory error occurs.
Attempting to restart (and kill that pop-up that is still hanging around).

$ /opt/android/latest/tools/android

Install packages
Installed Packages → Android SDK Tools, revision 7. Clicked update all and selected all recommended downloads.
Then removed all obsolete packages.

Try Again – With Galileo
Downloaded Eclipse JEE Galileo, I heard rumor through the grapevine that ADT Plugin did not play nice with Helios.
This still did not resolve the original issue of the adb not working.

Add the site: https://dl-ssl.google.com/android/eclipse/ to Eclipse after selection Help → Install Software. In this instance, I made it to the license agreement. However, when selecting the radio, “I agree” and scrolling down to the bottom of the license window, the ‘Finish’ button was never enabled. Thank you Mylyn for having 9 things to agree to when all I’m trying to is NOT add your plug in. It is my professional opinion that Eclipse with JEE comes with way too many plug-ins that do not have value add. Eclipse is pretty stable, but the plug-in developers really need to get on the ball. I keep running into resource hogs or plug-ins that don’t do their job very well. Have you seen the GIT plug-in? It doesn’t even come close to mapping what you can do on the command line. Going to get Eclipse just for Java to minimize plug-ins to see if I can get this to install.

Try Again – With Galileo sans JEE garbage.
Installed the basic Eclipse IDE for Java Developers. There are noticably less plug-ins install that might collide. But Mylyn is still there. Let’s see how it goes. Oh look at that! It appears that I am in the same situation. Here are the list of things to agree to:

Android DDMS
Android Development Tools
Mylyn Bridge: Eclipse IDE
Mylyn Bridge: Java Development
Mylyn Bridge: Team Support
Mylyn Connector: Bugzilla
Mylyn Task List (Required)
Mylyn Task-Focused Interface (Recommended)
Mylyn WikiText

Let’s see if my outcome is any different this time. I’ll scroll to the bottom of each agree and check I accept. Wow! Different behavior! The ‘Finish’ button was able to be clicked. Joyous happy day.

Back on track – Setup the SDK
Window → Preferences → Android
SDK Location: /opt/android/latest
Apply

Configure the SDK
Eclipse → Window → Android SDK and AVD Manager
Something weird happened again.
After selecting the option above I received and error. [2010-09-17 06:12:09 – adb]Failed to get the adb version: Cannot run program “/opt/android/latest/tools/adb”: java.io.IOException: error=2, No such file or directory
After selecting it a second time, the application launched.
Android SDK and AVD Manager (ASAM) → Installed Packages → Update All…
Now ‘Delete…’ any obsolete packages.

I got another error saying that there are packages dependent on adb, but it isn’t running. I think the 0.9.8 SKD might be fubar. After more research, there is a problem with Ubuntu 64bit (which I’m running). It looks like some 32bit libraries need to be installed. There was nothing explicit on the Android SDK site, but after more searching I found references to the 32 bit libraries under an Ubuntu forum. Then I found a matching troubleshooting article on the SDK site.

$ sudo apt-get install ia32-libs
$ /opt/android/latest/tools/adb 

Yay! ADB now does something! That was the root of my problem. Now everything is right with the world. Two hours later my quest continues.

Ubuntu Linux 13.10 64-bit
The error ‘bash: ./adb: No such file or directory’ came back. But this time ‘install ia32-libs’ did not work. However, this seemed to do the trick:

$ sudo apt-get install libc6:i386 libstdc++6:i386

Hello World
Follow the instructions from the Android Site. http://developer.android.com/resources/tutorials/hello-world.html
After the errors before, getting the Hello, Android app running was a piece of cake. That emulator is pretty cool. Then I said, f@#$ it, and I set it up to run on my windows environment.

Posted in Programming | Tagged: , | 1 Comment »

Programming: Rails with Postgres – Couldn’t create database

Posted by jaystile on August 31, 2010

Hello internet community! I wanted to share something with you that you may encounter. I was setting up a postgres database and trying to use rake db:create to create the sample database from the getting started tutorial.

I kept getting an error like:

Read error message: FATAL: Ident authentication failed for user "blog_development
...
Couldn't create database for {"encoding"=>"unicode", "username"=>"blog_development", "adapter"=>"postgresql", "database"=>"blog_development", "pool"=>5, "password"=>"tmppass"}

The default Ubuntu Postgres installation requires both a system user and a database user with matching user IDs. It turns out I had to change a setting in postgres to allow connections from just database users.

vi /etc/postgresql/8.4/main/pg_hba.conf
Change the line
local all all ident
to
local all all md5

Note: You cannot have two of the same defined combinations. The first once wins, when I had put “local all all ident” followed by “local all all md5” the second didn’t get defined. That caused me a couple of hours of heartache.

Posted in Programming | Tagged: , , | 1 Comment »

Setting up Eclipse with Windows 7 issues

Posted by jaystile on June 22, 2010

I’ve bought myself a new PC which came with Windows 7. I’ve been running versions of Ubuntu on old hardware since version 6.04 and I thought I’d give the new Windows a test drive. At work we run on linux distros so this is almost a new experience for me. My friend really likes Windows 7 and to be honest I was getting a little sick and tired of external hardware not working. Specifically my webcam (which Logitech doesn’t for Windows 7 for some damn reason, I’m done doing buying anything from them) and the scanner my other friend let me borrow.

I’m working on a few side development tasks on my own. I program a lot of java so I went through and installed the latest JDK and tried to find where in the heck you set the environment variables. But I got that resolved. Next, I go and download Eclipse. I extracted the zip file with the default Windows 7 ‘Extract’ option. When I tried to run eclipse I get a weird error about a shared library not being found.

Anyway, I went searching for the answer and it looks like the Windows 7 zip handler doesn’t handle the eclipse-jee-galileo-SR2-win32.zip very well. So, I downloaded cygwin, extracted the zip, moved the eclipse folder to /cygdrive/c/eclipse. Tried to fire up eclipse again and it failed with a permissions exception. chmod -R 755 /cygdrive/c/eclipse and I was up and running. You can color me unimpressed that Windows 7 failed to correctly extract an archive.

Posted in Programming | Tagged: | Leave a Comment »

INSERT CLOB with JDBC and Oracle Prepared Statement

Posted by jaystile on May 24, 2010

The oracle API made me crazy for about six hours. That is how long it took me before I could figure out how to do an insert that includes a clob. The key to do an insert with a clob is to use the oracle.sql.CLOB.createTemporary method. The javadoc associated with the CLOB class is very sparse and does not include any instructions.

In my scenario I was trying to do an insert with a prepared statement. The Prepared Statement has a setClob method, but it really doesn’t do you any good because you don’t have a clob object available. Most of the examples I found showed a technique of creating an empty clob object and then getting a reference to the clob and then streaming data to it. This was not going to work for me because I’m running batches of statements with thousands of inserts.

This is what worked for me. It might need a little tweaking since I’m blogging from home without my development environment, so take it with a grain of salt.

// Pseudo-code
import oracle.sql.CLOB
import java.sql.Connection
import java.sql.PreparedStatement
...
public void setClobInStatement(Connection conn, PreparedStatement ps, String longText) {

// I don't know what 'false' means versus 'true' in the following statement
CLOB c = CLOB.createTemporary(conn, false, CLOB.DURATION_SESSION);

// The 1 is the position to start inserting the string into the clob.
c.setString(1, longText);

// Set the temporary clob in the statement, it becomes permanent when the statement executes.
// If the clob is the first object to be set in the statement, use 1
ps.setClob(1, c);
}

Gotcha’s

  • The PreparedStatement.setString() will work with text up to 4000 characters. With strings longer than that it will fail with a cryptic exception, ORA-00600, I believe.
  • If you’re supporting multiple databases, you’ll have to create an Oracle specific class and implement an interface so you can swap out the implementation. This requires direct use of the Oracle API.

References
La Javadoc En Francais (It’s in english and the most complete)
oracle.sql.CLOB
oracle.jdbc.driver.OraclePreparedStatement

Posted in Programming | Tagged: | Leave a Comment »

Perl: Finding a Class in a Jar file.

Posted by jaystile on June 19, 2009

I was having some trouble finding which jar contained a class I needed. I wrote a perl script to find it.


#!/usr/bin/perl

use strict;

# flush print to the output after every write.
$| = 1;

##############################################################################
# Parse the parameters.
##############################################################################
if( (scalar @ARGV) ne 2) {

   print "Expected arguments: findClass.pl <ROOT_DIRECTORY> <CLASS_NAME>\n";
   exit;
}
print "findClass.pl\n";
my $dir = shift @ARGV;
my $targetClassName = shift @ARGV;
print "Using root directory: $dir\n";
print "Looking for class: $targetClassName\n";

##############################################################################
# Backup your current directory, go to working directory
##############################################################################
my $currDir = `pwd`;
chomp $currDir;
chdir $dir;

# work
searchDir();

##############################################################################
# Return to previous directory and exit.
##############################################################################
chdir $currDir;
exit;

##############################################################################
# Subroutines 
##############################################################################
sub searchDir {
   my @jarList = `find . -name "*.jar"`;
   my @classList;
   my @results = [];

   foreach my $jarName (@jarList) {
      print ".";
      @classList = `jar -tf $jarName`;
      foreach my $className (@classList) {
         if($className =~ /$targetClassName/) {
            print "*";
            chomp $jarName;
            chomp $className;
            push @results, "$jarName:$className";
         }
      }
   }

   foreach my $result (@results) {
      print "$result\n";
   }
}

Posted in Programming | Tagged: | 1 Comment »

Postgres 8.3, JDBC, JPA, and Hibernate example setup.

Posted by jaystile on April 1, 2009

I wanted to access my local postgresql database with JDBC and JPA in the J2SE environment. Refer to my previous post about setting up Postgres 8.3 on Ubuntu 8.04.

If you can’t tell, I’m using java. I’m compiling to java 5. I’m building my project with maven. Inside of a larger maven project which creates my ear file, I created a test project ‘runner’. This creates a jar.
runner/pom.xml

<project> <modelVersion>4.0.0</modelVersion> <groupId>org.myproject</groupId> <artifactId>runner</artifactId> <packaging>jar</packaging> <name>JAR Runner</name> <version>1.0</version> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </pluginManagement> </build> <dependencies> <dependency> <groupId>org.myproject</groupId> <artifactId>util</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>8.3-603.jdbc4</version> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>ejb3-persistence</artifactId> <version>1.0.2.GA</version> </dependency> <dependency> <!-- Note this added other dependencies - hibernate-commons-annotations-3.1.0.GA.jar - slf4j-api.1.4.2.jar - exclude this because it is bunk and causes exceptions. - hibernate-annotations-3.4.0.GA.jar - antlr-2.7.6.jar - commons-collections-3.1.jar - dom4j-1.6.1.jar - xml-apis-1.0.b2.jar - jta-1.1.jar - javassit-3.4.GA.jar --> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager </artifactId> <version>3.4.0.GA</version> <exclusions> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </exclusions> </dependency> <!-- The org.slf4j needed to be included because the one included in org.hibernate.ejb3-persistence did not work --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.5.6</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.5.6</version> </dependency> </dependencies> </project>

runner/src/main/resources/META-INF/persistence.xml file
The core of JPA uses the persistence.xml file to set up the database and entity mappings. I tried using Sun’s example but I found it to hard to configure. I know that hibernate provides a JPA implementation so I used that instead of the glassfish example. It was easy to add because it exists in the maven 2 repository. This persistence.xml is configured to talk to the postgresql 8.3 database. It also contains a mapping for my Entity.

<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="pu1" transaction-type="RESOURCE_LOCAL"> <class>org.myproject.runner.MapEntity</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/> <!-- <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/> --> <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/> <property name="hibernate.connection.username" value="myuser"/> <property name="hibernate.connection.password" value="mypassword"/> <property name="hibernate.connection.url" value="jdbc:postgresql://localhost/mydb"/> <property name="hibernate.max_fetch_depth" value="3"/> <!-- cache configuration --> <!-- This was blowing up -v <property name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item" value="read-write"/> <property name="hibernate.ejb.collectioncache.org.hibernate.ejb.test.Item.distributors" value="read-write, RegionName"/> --> <!-- alternatively to <class> and <property> declarations, you can use a regular hibernate.cfg.xml file --> <!-- property name="hibernate.ejb.cfgfile" value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ --> </properties> </persistence-unit> </persistence>

Our database is populated by some sql.

create table map ( pk_id int unique primary key, width int, height int, name varchar(256), last_updated timestamp ); GRANT ALL ON map TO PUBLIC; INSERT INTO map (pk_id, width, height, name, last_updated) VALUES (1, 100, 200, 'test_map', CURRENT_TIMESTAMP);

MapEntity.java
Next, we have an entity to use against our database. It only maps one field, but this was just for testing purposes.

package org.myproject.runner; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="MAP") public class MapEntity { private long id; @Id @Column(name="PK_ID") public long getId() { return id; } public void setId(long id) { this.id = id; } }

DatabaseAccess.java
Finally, we have a java class that can call the database via JDBC or JPA

package org.myproject.runner; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.Persistence; public class DatabaseAccess { /**
  • @param args
  • /
public static void main(String[] args) { testJdbc(); testJpa(); } public static void testJdbc() { String url = "jdbc:postgresql://localhost/mydb"; Properties props = new Properties(); props.setProperty("user","myuser"); props.setProperty("password","mypassword"); Connection conn = null; try { conn = DriverManager.getConnection(url, props); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from map"); while(rs.next()) { long id = rs.getLong(1); System.out.println("ID:" + id); } } catch (SQLException e) { e.printStackTrace(); } finally { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void testJpa() { // Use persistence.xml configuration EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu1"); EntityManager em = emf.createEntityManager(); // Retrieve an application managed entity manager // Work with the EM MapEntity map = new MapEntity(); map.setId(5); EntityTransaction transaction = em.getTransaction(); transaction.begin(); em.persist(map); transaction.commit(); em.close(); emf.close(); //close at application end // Create EntityManagerFactory for persistent unit named "pu1" // to be used in this test } }

Posted in Programming | Tagged: , | 4 Comments »

Perl: Converting Decimal to Degrees Minutes Seconds (and vice-versa)

Posted by jaystile on February 21, 2009

Here is some code I playing with trying to get conversion from one coordinate system to another. There is some percision loss due to the floating point math in the conversions. So expect to see a loss of a few seconds when converting from decimal.


1 #!/usr/bin/perl
2
3 use strict;
4 use POSIX qw(ceil floor);
5
6 # flush print to the output after every write.
7 $| = 1;
8
9 testConvertDegMinSecToDecimal();
10 testConvertDecimalToDegMinSec();
11
12 ##### TEST ROUTINES
13 sub testConvertDegMinSecToDecimal {
14 my $result = convertDegMinSecToDecimal(121, 8, 6);
15 print "RESULT: $result\n";
16
17 my $result = convertDegMinSecToDecimal(121, 59, 59);
18 print "RESULT: $result\n";
19 }
20
21 sub testConvertDecimalToDegMinSec {
22 my $deg; my $min; my $sec;
23 ($deg, $min, $sec) = convertDecimalToDegMinSec(121.135);
24 print "RESULT - DEG: $deg MIN: $min SEC: $sec\n";
25
26 ($deg, $min, $sec) = convertDecimalToDegMinSec(121.99317);
27 print "RESULT - DEG: $deg MIN: $min SEC: $sec\n";
28 }
29
30 ##### SUB ROUTINES
31 sub convertDegMinSecToDecimal {
32 my $deg = $_[0];
33 my $min = $_[1];
34 my $sec = $_[2];
35
36 my $result = $deg + ($min/60) + (($sec/60) *(1/60));
37 $result = sprintf("%.5f", $result);
38 }
39
40 sub convertDecimalToDegMinSec {
41 my $input = $_[0];
42 my $deg = floor($input);
43
44 $input = $input - $deg;
45 $input = $input * 60;
46
47 my $min = floor($input);
48
49 $input = $input - $min;
50 $input = $input * 60;
51
52 my $sec = floor($input);
53
54 return ($deg, $min, $sec);
55 }

If you’re playing with degrees minutes seconds & decimal degree conversions you’re probably interested in calculating distance on the Earth. There are two common algorithms for calculating distance that are available as CPAN modules:

Posted in Programming | Tagged: , , | Leave a Comment »

Ubuntu: Howto Setup a Local Subversion Repository

Posted by jaystile on February 13, 2009

This Howto is targeted for Ubuntu 8.04, Hardy Heron. Specifically, this will go through a quick start to get subversion running on the file system. Which, by the way, is NOT the recommended way of setting it up. But if you’re doing some local (1-person) development it is the quickest. The documentation for subversion can be found at svnbook.red-bean.com

Get Subversion!
I used the Synaptec Package Manager to download the ‘subversion’ package. You could probably done just as well using ‘apt-get’.

Create Repository!

svnadmin create /var/svnroot/

Import your code into the repository!
Where LocalDir is like /home/username/MyProject
and Where ProjectName is like MyProject

svn import LocalDir file:///var/svnroot/ProjectName

Check out your code from the repository!

svn checkout file:///var/svnroot/PorjectName

Your code is now under version control! (Don’t you feel all grown up now?)

Posted in Programming | Tagged: , | Leave a Comment »