Wednesday, March 27, 2013

Thoughts on Gay Marriage

Or, you know, marriage.

This will be rambletastic, you have been warned.

For a long time, probably over a decade, I have thought that consenting adults should be allowed to enter into legally binding, and respected, agreements.  This has progressively changed from allowing "Civil Unions" with all of the rights of marriage to my current position of just calling it what it is, marriage.  I have asked people who are against it to provide me with one non-religious reason for disallowing it, and the one that I heard most recently was that he did not want to have to explain to his grand daughter why two people were doing something that they thought was immoral and the government was condoning it.

Really? Outlawing the ability of two people who love each other to care for each other because you can't talk to children about how different people have different views of what is immoral? Though I suppose that is how prohibition started too. Of course, this is still a religious argument.

Even before I was married, I held the opinion that two people of the same gender getting married would in no way devalue my marriage.  If two people who love each other, and who happen to be of the same gender, get to marry, and this somehow has a deleterious effect on my marriage, that says a whole lot more about my marriage than it does about the gay couple who love each other.

In terms of the national good, I would think that allowing gays to marry each other would actually stimulate the economy, at least a little, as there are more people employing reception halls, DJs, bakeries, and everything else that goes with a wedding, whether or not the ceremony proper is held in a church.  Though I guess more lawyers will probably be getting paid too as the inevitable divorces come through.

That of course points us to the "sanctity of marriage" argument. I'm not certain of the current statistics, but I was under the impression that it is still something like 50% of marriages end in divorce. In this country marriage hasn't been sacred for quite some time. When a celebrity has been married for over 10 years we applaud them. When non-celebrities are married for more than 30 years, we, as a society, marvel at their matrimonial longevity.

Maybe I should have made this post yesterday, or many days ago. Regardless, the members of the Supreme Court will not see it prior to their decision, nor should online essays sway their decision one way or the other. They should base their decision on their interpretation of the Constitution, including the part which provides equal protection under the law.

This also brings up my final thought, the only place the word "faith" shows up in the original Constitution has the effect of saying that marriages between same-sex partners performed in New York have to be upheld in Utah.  The full faith and credit clause. Though the word faithfully shows up 2 places, one in an oath for the President, and the other stating that the president will ensure that the laws are faithfully executed.

Monday, March 25, 2013

Bring out your dead!

First non code-related post!

My wife and I have been playing a lot of Zombicide recently, and we are backing Zombicide: Season Two as well.  If you don't want to click through the links, it is a cooperative board game for 1-6 people where you are trying to survive the mission at hand.  You can pick up items which make killing zombies easier, but the more experience you rack up (by killing zombies) the more zombies spawn each turn, making it a balance of killing vs. running away.

The game comes with about 10 missions in the rule book, but the website has a bunch of other missions for download.  There is also a game editor so you can easily create your own missions.  They even run a weekly contest where the winning submitted mission gets an exclusive survivor sent to them.

My wife and I are working on a mission which we will probably be play testing in the next week or so. We hope to eventually submit it.  If it wins, I'll be sure to post a link to it here.  If it doesn't, I'll probably  post a link to our write up so that others can play it anyway.

Hmm, I wonder if Zombicide will ever make it onto #TableTop?

Sunday, March 24, 2013

Building gcc 4.8

So apparently on 22 March 2013, GNU put gcc 4.8.0 into production.  So I decided to build it on my home computer (AMD Phenom2, Ubuntu 12.04 64-bit)

Here are the steps that I took for a pretty smooth installation.

Edit: I initially used 4.1, however, I have since built gcc-4.8.0 on other (non-debian) based systems where I have not had root access. Step 4.2 should work in those cases. This has worked on CentOS 5.9 on an IvyBridge Core i7 and CentOS 6.3 on a SandyBridge based Xeon. My prefix directory in those cases were $HOME/app/gcc/4.8.0.
  1. Download the source code
  2. Unzip the file (tar -xjf <file name> for .bz2 file, like what I linked to)
  3. Make a build directory (mkdir gcc-build && cd gcc-build)
  4. Install some supporting parts 
    1. Option 1: sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev libc6-dev libc6-dev-i386
    2. Option 2 (from source code directory): contrib/download_prerequisites (prereqs will then be built as well)
  5. Run configuration (../gcc-4.8.0/configure --prefix=/app/gcc/4.8.0)
  6. make
  7. sudo make install
I use environment modules, so I've put together a module file in modulefiles/compiler/gcc/4.8.0 which currently looks like this:

 
#%Modules1.0
##
##

conflict compiler

prepend-path PATH /app/gcc/4.8.0/bin
prepend-path LD_LIBRARY_PATH /app/gcc/4.8.0/lib64
prepend-path MANPATH /app/gcc/4.8.0/share/man
prepend-path C_INCLUDE_PATH /app/gcc/4.8.0/include
prepend-path CPLUS_INCLUDE_PATH /app/gcc/4.8.0/include

setenv CC /app/gcc/4.8.0/bin/gcc
setenv CXX /app/gcc/4.8.0/bin/g++
setenv FC /app/gcc/4.8.0/bin/gfortran

After that, a 'module load compiler/gcc/4.8.0' and the 4.8 version of gcc, g++, and gfortran are my default C, C++ and FORTRAN compilers. Pretty simple over all.

Text Editors

I write code on occasion.  I've found that most people who write code have a favorite text editor for doing that.  I haven't found anybody for whom that text editor is Notepad, but I'm getting ahead of myself.  This happens to be a subject where I have some opinions.  However, I have to be honest and say that I haven't really investigated the  multitude of text editors out there.  Another thing to note is that I spent my formative computer years using Windows products, so I like having certain keyboard shortcuts, most notably CNTL-C for copy, CNTL-X for cut, CNTL-V for paste, CNTL-S for save, CNTL-Z for undo, and CNTL-Y for redo.  I know there are plenty of text editor editorials and guides out there, but this is mine.

Geany
Right now my text editor of choice is Geany.  Geany seems to fit my style pretty well.  It has automatic text highlighting for the languages I use most, it has tabs, and it also is available easily on Windows as well as Linux.  I know that it is in the repositories for Ubuntu and an RPM can be found for Red Hat/Fedora/CentOS.  I have also been able to easily build it from source on CentOS when I did not have root access, though it does have a few library dependencies (GTK++ is one of them I think).  I haven't decided if Geany is a heavyweight text editor or a lightweight IDE.  However, it loads up pretty fast, and if I have other files open, can autocomplete variables, class names, and functions out of those open files.  If I'm writing in XML, it will also automatically created close tags, which is can be pretty nice.

Notepad
I hate Notepad.  Notepad wasn't quite the first text editor I ever used (I think that was edit, back on DOS) but it was close.  There are many reasons I dislike Notepad.  Here are the main ones:

  • No tabs: If I am working with text files, there is a reasonable chance I am working with many text files simultaneously.  Having each file in a separate Window is infuriating
  • No text highlighting: text highlighting is very helpful when working with code, 'nuff said
  • No line numbers: again, something very helpful when working with code
  • And the kicker: no support for new lines without a carriage return
Seriously, I can't read any text file generated on a *nix system because Notepad doesn't realize that \n means newline, it requires \r\n.  I can't imagine this is that hard to fix, and sure anybody who is actually going to write code at all is going to get a better alternative (the previously mentioned Geany, Notepad++ is pretty good too).  However, to not include something at least marginally better than Notepad seems like a big FU to developers.

Notepad++
Notepad++ is an excellent choice for replacing Notepad on Windows.  It fixes all 4 gripes I posted (but not all that I have, believe me) about Notepad.  The main reason that it is not my primary text editor on Windows is that I can't get it for Linux.  I work in Linux often enough, that having my text editor similar in both Windows and Linux is enough of a boon to push Geany above Notepad++.  Because of this, I haven't actually used Notepad++ in probably over a year.  However, it is still a quality text editor.

vi / vim
If I only have access to a command line editor, or if all I want to do is make a very small modification to a text file, I use vim (or plain vi is vim is not available).  vi is incredibly powerful if you know how to use it.  I know how to use very small parts of it, enough to move around somewhat quickly, do search/replace, a little bit of cut and paste, and mass deletions.  However, these don't follow my normal keyboard shortcuts, so sometimes I mess up pretty badly (which is why repositories are my friend).

If I have to do lots of coding on a system with no GUI (and therefore no Geany) what I'll actually do is develop on a system with Geany, and then just rsync files up to the GUI-lacking system.

Emacs
I don't hate emacs, but I don't typically use it.  If a system has emacs, it probably has vi as well, and I have already become proficient enough with vi.  Also, the control characters really throw me off.  I know that I could create my own initialization file which sets those to my preferences, but then I would have to port that file around everywhere.  I haven't even gotten to the point of porting a .bashrc around everywhere (Note to self: I should probably push a .bashrc onto my Google Drive at some point).

UltraEdit
UltraEdit was the first text editor I ever used that I actively liked.  I actually paid for the license back in high school when I was using it (and the license cost $30) for version 9.  I haven't used it in years due to the cost associated with it, and by then I had found other text editors that I liked, but I do remember the column edit mode was pretty sweet, where I could grab a rectangle of text in the middle of other text.  Maybe I'll grab the free trial and play around with it some more, see if it is worth the money and capable of ousting Geany from my top spot.  Another bonus (at least on the version that I had used to have): built in Hex editor.

I think that is all for now.  I may talk about IDEs I have used (Eclipse, JavaBeans, Visual Studio Express, MonoDevelop, more Geany) at some later point.  Or this blog could go the way of many other journals I have started, and I just forget about it (I'm looking at you livejournal).

Saturday, March 23, 2013

Cypher which has probably been done before

I had an idea for a somewhat simple cypher a few weeks ago, and I finally got around to coding it up in Python. Basically, it takes a letter, finds the index of that letter within the cypher key, and then adds the index to a running offset value. The offset value is then modulous by the length of the cypher key, and the location within the cypher key associated with the new index is output. Optionally, a static value can be added to every offset.
If anybody actually sees this, let me know what you think.

 
'''
A module for creating and decoding a simple cypher-text
'''

from collections import OrderedDict

cyStr = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ,.;:"\'!@#$%^&*()[]{}-?/'

def rollingEncode(string, offset=0, cyString=cyStr):
 cyString = "".join(OrderedDict.fromkeys(cyString).keys())
 ncyStr = len(cyString)

 if ncyStr == 0:
  return string

 anslist = []
 cyPos = 0
 
 for a in string:
  index = cyString.find(a)
  if index != -1:
   cyPos += index + offset
   while cyPos < 0:
    cyPos += ncyStr
   cyPos = cyPos % ncyStr
   anslist.append(cyString[cyPos])
  else:
   anslist.append(a)
   
 return ''.join(anslist)
 
def rollingDecode(string, offset = 0, cyString=cyStr):
 cyString = "".join(OrderedDict.fromkeys(cyString).keys())
 ncyStr = len(cyString)

 if ncyStr == 0:
  return string

 anslist = []
 cyPos = offset
 
 for a in string:
  index = cyString.find(a)
  if index != -1:
   index -= cyPos
   while index < 0:
    index += ncyStr
    
   index = index % ncyStr
   
   anslist.append(cyString[index])
   cyPos += index + offset
   
   while cyPos < 0:
    cyPos += ncyStr
   
   cyPos = cyPos % ncyStr
  else:
   anslist.append(a)
   
 return ''.join(anslist)
   
if __name__ == '__main__':
 import sys
 if len(sys.argv) > 1:
  if len(sys.argv) > 2:
   cypher = sys.argv[2]
  else:
   cypher = cyStr
   
  print rollingEncode(sys.argv[1], cyString=cypher)
  sys.exit(0)
 
 cypher = 'The quick brown fox jumped over the lazy dog.!?'
 a = "This is a test. WHOOOO!"
 offsets = [-500, -50 -5, 0, 5, 50, 500]
 for o in offsets:
  b = rollingEncode(a, o, cypher)
  c = rollingDecode(b, o, cypher)
  print "offset =", o, "cypher = '" + cypher + "'"
  print "a =", a
  print "b =", b
  print "c =", c
  print ""
  
  b = rollingEncode(a, o)
  c = rollingDecode(b, o)
  print "offset =", o, "cypher = '" + cyStr + "'"
  print "a =", a
  print "b =", b
  print "c =", c
  print ""