Thursday, February 4, 2016

New Roulette

Here is a new roulette game.
  1. Everyone has an initial stake that can be any amount of money.
  2. For each spin, you can play or you can watch.
  3. If you play, you must wager 1% of your stake. Watching is free.
  4. A number is chosen for each player and watcher; no two players or watchers have the same number.
  5. The roulette wheel has exactly enough numbers for all the players and watchers.
  6. After each spin, all players and watchers win %100 of their stake.
Here is how you increase your stake:
  1. The roulette wheel is spun.
  2. If the ball lands on the number of a watcher, no ones stake increases.
  3. If the ball lands on the number of a player, then the stake for each player and watcher is raised by an amount between 1% and 2.5%.
  4. Any increase is to the stake for all players and watchers for this spin and all future spins. The longer you play or watch, the bigger your stake becomes.
Would you play or watch?

The name of the game is The Power of a Union in a Right-to-work State.

Friday, January 22, 2016

Installing Python3 on Mac OSX

I have python 2.6 installed on my Mac.

I already had homebrew installed for perl.

I used the command

brew install python

and python 2.7 was installed. The bash profile command was altered to include the new python path at the start of the path command.

PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

Install Python 3

Next, I tried to install python 3.

brew search

The name of the package is python3.

brew install python3

This was the first error:


C compiler cannot create executables

I had read a comment earlier about installing Xcode. I already had Xcode. Another comment was to enable command line tools. I did not know if they were already enabled. They weren't.

xcode-select --install

After this command and install, I was able to get further, but the install failed. After error

Need 'brew link xz'

Typed the command

brew link xz

and received an error. So, I ran

brew doctor

I changed the permission on a file. I was able to continue. python 3 is now installed in /usr/local/bin/python3

Install Virtual Environment 

I accessed Python Virtual Environment and learned about virtual environments.
 

Next, I created a virtual environment with the new python.

virtualenv -p python3 python3env

After installing, switch to the folder and activate the environment.

source bin/activate

Now, the path has the local python as the default python.

The virtual environment is alright, but I am limited to a text editor and console window.

Install Eclipse IDE

An IDE with code completion and syntax highlighting is preferable. 

Next, I installed Eclipse and added the PyDev plugin. I installed Eclipse for Java, since no option existed for python.

I followed the instructions at http://www.pydev.org/manual_101_install.html. I was required to accept a certificate that was not mentioned in the instructions.

For Mac, the preferences are not under the window menu, but in the usual preferences under Eclipse in the menu strip.

Next, I followed the instructions for creating a project. The interpreter was the default 2.7, not the new 3.5. I added the new interpreter to the preferences.

The tutorial is for 2. I am using 3, so tutorial code must be modified.

Install NetBeans IDE


Next, I checked to see if NetBeans had a plugin for python. NetBeans 8.1 has a python package that can be installed easily, 8.02 requires some worked. I upgraded to 8.1.

The default python was for jython in NetBeans. I added a reference to my python 3.

The default template for creating a module used python 2 syntax. The template for creating a package used python 3 syntax. 

Update

https://opensource.com/article/19/5/python-3-default-mac

use pip to install modules







 



Monday, June 1, 2015

Finding Largest Files in Bash

I often need to find the largest files in a directory tree.

I have used

du -a | sort -nr | head -n 10

but it includes directories.

To exclude all directories, I tried using find.

find -type f -exec ls -l {} \; | tr -s ' ' | cut -d' ' -f 5,9- | sort -rn | head -n 10

Explanation
  1. -type f means only look at files
  2. -exec ls -l {} \; means to show a long listing for each matched file
  3. tr -s ' ' replaces multiple occurrences of space with one space
  4. cut -d' ' -f 5,9- sets the delimiter to space and displays the columns 5 and everything after 8. Column 5 is the size, everything after 8 is the file name (with possible embedded spaces)

Saturday, March 7, 2015

Moving Dropbox From The Roaming Profile

When roaming profiles get big, they take a long time to load.

Dropbox stores its configuration files in the roaming profile. Some of the files are large.

After installing Dropbox, I noticed that the data files were stored on a network drive and the config files were in my roaming profile. I did not like either of these locations, but Dropbox installation does not allow them to be changed.

After installation, I was able to open the advanced Dropbox preferences and move the data file to a local drive. I tried several tricks to get Dropbox to move the config files to the local drive, but nothing worked.

I thought about symbolic links in Linux. I am using Windows 7, which has a mklink command.

I stopped Dropbox, moved the config folder to the local drive and created a link from the AppData\Roaming\Dropbox to the config file on the local drive.

I created a script that tests if the local folder exists and then creates the link. I created an admin task that starts the script on log on.

if not exist c:\local_data goto nolocal
mklink /j c:\Users\xxxxxx\AppData\Roaming\Dropbox c:\local_data\DropboxFromRoaming
:nolocal

Dropbox is now stored on my local drive, not in my roaming profile.

Update: When I logged off, the Dropbox folder was stored to my roaming profile. On the next login, the link could not be created, since the folder existed. It is necessary to ignore Dropbox in the roaming profile:   https://support.microsoft.com/en-us/kb/188692

I had tried the Group Policy, but it was ignored. I modified the registry and was able to leave Dropbox out of my profile.

Conclusion: It is not necessary to mess with links, just use the registry to keep Dropbox out of the roaming profile.



Monday, December 29, 2014

Working with web application with version control

I have a web application to put into version control.

I decided not to add my NetBeans project to version control.

I created a folder that contained all the files for the web application.

I created a new NetBeans project from existing sources. I pointed all source files to the version controlled sources. The sources are not in the NetBeans project folder.

From Window->Favorites I selected the version controlled folder. From Team->Subversion, I imported the version controlled folder.

It seems that NetBeans is smart about what should go into version control. I probable could have avoided this altogether!

Monday, December 22, 2014

Sharing a repository with SVN and GIT

It is always difficult to get something to work when you don't understand the software. I had this problem with Git. I was using it, but did not understand it. Then I read the first four chapters of the Git book.

I wanted to import a repository that was built in Git into Svn. The project was originally a Svn project, but new developers ported it to Git. I wanted to be able to modify it from either Git or Svn. I knew that I would not be able to create a seamless integration with the first Svn version, but I would be happy with a new one that could work with both from now on.

I found an excellent reference on Stack Overflow. Of course, it did not work with my repository. After many hours, I got it to work.

From Stack Overflow:

1. cd /path/to/git/localrepo
2. svn mkdir --parents protocol:///path/to/repo/PROJECT/trunk -m "Importing git repo"
3. git svn init protocol:///path/to/repo/PROJECT -s
4. git svn fetch
5. git rebase trunk
5.1.  git status
5.2.  git add (conflicted-files)
5.3.  git rebase --continue
5.4.  (repeat 5.1.)
6. git svn dcommit

When I reached the git rebase trunk line, I was faced with so many conflicts, it was impossible to continue. I still do not understand why the replay of the previous commits was causing so many (add/add) conflicts.

I then tried another sequence from later in the post:

git svn fetch
git rev-list --parents master | grep '^.\{40\}$'
git rev-parse svn/trunk
echo   >> .git/info/grafts
git filter-branch -- ^svn/trunk --all
rm .git/info/grafts

More voodoo. In this sequence, I was introduced to rev-list, rev-parse and filter-branch. I am still a little vague on how these work. I was able to get this to work, and was introduced to a nice GUI for a git repository, gitk.

The next statement was git svn rebase. Again, too many (add/add) conflicts.

I then learned that git rebase has the -s for defining a strategy. With the recursive strategy, it is possible to set an option for always accepting the new revision into the current one.

git rebase -s recursive -Xtheirs svn/trunk

This worked, but then I received an error about a commit that did not have a message. Apparently, some commits were added without messages and this was preventing the rebase.

I found another stack overflow post that explained how to add messages for commits that are missing messages. The technique I picked only works for single line messages:

git filter-branch -f --msg-filter '
read msg
if [ -n "$msg" ] ; then
    echo "$msg"
else
    echo "The commit message was empty"
fi' 

I then aborted the rebase and reran it. I received a bad format error. Filter-branch rehashes all the data, so I had to restart the sequence again, starting with git svn fetch.

Once that was done, I was able to complete the sequence:

git rebase -s recursive -Xtheirs svn/trunk
git svn dcommit

It worked. I can now do as the post suggested:

You can now sync from svn to git, using the following commands:

git svn fetch
git rebase trunk
 
And to sync from git to svn, use:

git svn dcommit

Saturday, May 17, 2014

Output of cal on Linux contains underscore and backspace

I just ran across some strange behavior in the output of the cal command on Linux.

I am running a perl script on Linux. The script retrieves the output of the Linux cal command with

`cal $month $year`

where $month and $year are set in the script.

I have been running this script for years and have not had a problem before.

The output of the calendar for

cal 5 2014

contains some control characters. For day 18, the output of the day is _1_8, where is the backspace key (hex 08). As you can guess, this runs havoc with my script that is formatting the calendar.

I had to filter the output of the command, replacing occurrences of _

s/_\x08//g

After filtering the output, the script ran as expected.

I ran a test script on all calendars from 1800 to 3000. Only May 2014 has the error.

More Blogs

Followers