tag:blogger.com,1999:blog-58872562024-03-14T03:43:20.527-07:00Tech BitsRandom Unix or software development tips and notesJason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.comBlogger37125tag:blogger.com,1999:blog-5887256.post-81273270849994831272015-11-06T07:50:00.001-08:002015-11-06T07:50:49.688-08:00Kerberos propagation and unusual networkingMy Kerberos servers are scattered around the Internet, behind NAT in some cases, connected with VPNs, etc. As such the hostname or IP that one server might use to connect to another is often different from the actual hostname or default IP of the other server.
For most services this isn't a particular challenge, but Kerberos replication with kprop and kpropd has often been difficult to get Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-11780483176010771402012-11-07T07:59:00.004-08:002012-11-07T07:59:51.973-08:00Raspberry Pi, Raspian Debian Wheezy, Boot Single User ModeIn short, eject the SD card from your Pi, mount it somewhere, and add "single" to the end of cmdline.txt. I was able to stick the card in my Mac and edit the file. Eject the card from that computer, stick it back in the Pi and boot it up. As is typical on Linux boxes it will boot to single user mode and prompt you for the root password.
Once you've booted up and fixed whatever Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com3tag:blogger.com,1999:blog-5887256.post-10444697534391831042012-09-07T03:58:00.001-07:002012-09-07T03:58:05.705-07:00Reporting Input Errors from a Rails Model
There are several places outside of the standard validations where you might process user input in a Rails model and want to inform the user that they supplied bad data. It is not immediately obvious though how you get useful error messages back to the user. Rails gives your model an instance of ActiveRecord::Errors called errors, which is the standard way to return validation errorsJason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-40663516756837459972012-06-14T14:50:00.000-07:002012-06-14T14:50:51.000-07:00Rails, simple_form, Twitter Bootstrap, and appendI wanted to put a little delete button at the end of a form field. We start with the standard simple_form syntax for a form field.
<%= f.input :name %>
The generated HTML has the form elements inside a set of nested divs which have the classes necessary for Bootstrap styling.
The result looks like:
If we want our delete button to appear on the same lineJason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com1tag:blogger.com,1999:blog-5887256.post-78704702660704122002012-04-19T07:29:00.000-07:002012-04-19T07:29:20.506-07:00Rails.root is the new Rails.configuration.root_pathIn older versions of Rails the Rails.configuration.root_path method would give you the base directory of your application in the filesystem. In Rails 3 this is now Rails.root.Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-50869268186775170012012-03-23T15:09:00.000-07:002012-03-23T15:09:41.097-07:00Rails, as_json, undefined method `serializable_hash'
as_json was failing in one of my Rails models with:
NoMethodError: undefined method `serializable_hash' for ["id", 3]:Array
Eventually figured out that the problem was that I had specified a non-existent association to :include in as_json:
def as_json(options={})
super(:include => [:non_existent_association])
&Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-82822682911976371252012-02-02T07:03:00.000-08:002013-12-10T08:35:03.415-08:00Versioning RESTful APIs
There seems to be general (but definitely not complete) consensus among REST experts that the proper way to version a REST API is via custom MIME/media types. You can Google this for yourself to find the discussions on the rest-discuss mailing list, Stack Overflow, various blogs, etc.
There was one subtlety to the discussion that I found interesting and I spent Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-33032079505397112712011-11-04T08:22:00.000-07:002011-12-14T06:50:08.384-08:00Ruby, OptionParser, and Switches with Optional Arguments
Ruby's OptionParser supports switches with optional arguments. Both the official documentation and the pickaxe book give examples of various syntax choices like these:
"--switch [OPTIONAL]"
"--switch [=OPTIONAL]"
"--switch" "=[OPTIONAL]"
Somewhere along the way the first time I needed a switch with an optional argument I Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-82868961692265272342011-10-10T13:42:00.000-07:002011-10-10T13:42:30.533-07:00FIOS Router CLI and DHCP
I recently got Verizon FIOS service. The router Verizon provides is an Actiontec MI424WR. Verizon goes to some trouble to hide the Actiontec branding; but, for example, the Model Name field in the System Monitoring tab on mine says "MI424WR-GEN2".
Anyway, I wanted to get the DHCP lease database out of the router in order to populate that information into myJason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com3tag:blogger.com,1999:blog-5887256.post-24867554489045604192011-10-07T11:20:00.000-07:002012-06-14T14:57:21.517-07:00Python PackagesI'm new to the Python and Django world, having primarily worked with Ruby and Ruby on Rails for the last few years. In reading about how to manage dependencies several folks referred to pip and distribute as the new hotness (literally). Ok, fine, they're probably something like ruby gems, but what's the difference?
Looking over their respective pages (http://pypi.python.org/pypi/pip Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-76714988670939338142011-08-23T06:50:00.000-07:002011-08-23T06:50:42.438-07:00Upgraded to Mac OS 10.7 (Lion)? Tried to update Macports with sudo port selfupdate and get:
Error: /opt/local/bin/port: port selfupdate failed: Error installing new MacPorts base: shell command failed (see log for details)
You probably still have the Snow Leopard version of Xcode installed. Try to run Xcode, it will probably tell you that you need to upgrade. Go Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-34590599325631968652011-04-12T22:56:00.000-07:002011-04-12T22:56:39.435-07:00I'm working on a MacRuby project in Xcode. I upgraded Xcode from 4.0 to 4.0.1 and Interface Builder stopped working right for my project. New outlets weren't showing up so I couldn't connect them to UI elements. I eventually realized that in the Xcode upgrade the MacRuby templates got wiped out. A reinstall of MacRuby got things working again.Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-83790023154325392062011-04-06T10:19:00.000-07:002011-04-06T10:24:33.890-07:00Filesystem Hierarchy Standard for Mac OS X
I frequently refer to the Filesystem Hierarchy Standard when trying to figure out where to put files on Linux systems.
I recently started doing some Mac development and was looking for an equivalent document. Apple's File System Overview seems to cover similar ground.Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com2tag:blogger.com,1999:blog-5887256.post-10701842135650974122010-05-14T15:41:00.000-07:002012-01-26T07:26:42.530-08:00User-Friendly RESTful Routes in Rails
RESTful routes created via map.resources use the :id field for URLs for individual resources. I.e. if user 'joebob' has an id of 42 then the URL for his resource is http://example.com/users/42
I find those URLs rather user-unfriendly. Wouldn't http://example.com/users/joebob be nicer?
If you plan for this from the start you can fake out rails Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-65396603716879907892010-04-05T15:37:00.000-07:002010-04-05T15:37:25.983-07:00I needed to set the UID for an account on my Mac OS X 10.6 (Snow Leopard) box. Various posts online said that you can right click on an account in System Preferences -> Accounts to access the Advanced Options. But right clicking wasn't doing anything for me. Finally I tried a Ctrl-click, the standard way to "right click" when you only have a one button mouse, and that worked. My right button Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-14982005900668514642009-09-02T14:53:00.000-07:002009-09-02T15:00:44.979-07:00If your Ruby app using https or some other form of SSL is complaining about:net/http.rb:567: warning: can't set verify locationsThen you probably passed in a bogus path to your CA file or path. In my case I had:http.ca_file = '/etc/pki/tls/certs/ca-bundle.crt'http.verify_mode = OpenSSL::SSL::VERIFY_PEERThat path is right on Red Hat, but I was running the script on my Mac laptop. Whoops. Fixed Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-42086122553043487792009-08-31T11:58:00.000-07:002009-08-31T15:38:47.337-07:00I've been using the workaround shown at http://blog.zenspider.com/2008/05/httpsssl-warning-cleanup.html for a while now to eliminate the "using default DH parameters" warning you get when using https in Ruby. However, I recently tried to reference two of my libraries which contained the same workaround in a script and ran into a "stack level too deep" error as the two sets of code both tried to Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com2tag:blogger.com,1999:blog-5887256.post-20165135027609987752009-08-25T10:24:00.000-07:002009-08-25T10:33:19.396-07:00Excel on the Mac defaults to portrait mode. Nearly all spreadsheets I create I want in landscape and finally tracked down how to set this as the default.Open up a new documentSet it to landscape via File -> Page SetupGo to File -> Save AsSwitch to the /Applications/Microsoft Office 2008/Office/Startup/Excel folderSet the filename to WorkbookUncheck the Append file extension checkboxSaveQuit and Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com1tag:blogger.com,1999:blog-5887256.post-62800929693674516752009-07-24T10:04:00.000-07:002009-07-24T10:24:30.565-07:00How to insert a new line above the current line in TextMate? A la capital O in vi? I couldn't find it in the TextMate book, nor searching around online. A few seconds of fiddling on the keyboard turned it up though: command-option-returnThis makes sense, as command-return inserts a new line below the current line. Having now looked around some more this command-option-return key sequence is Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-19180445389428873812009-06-18T14:03:00.000-07:002009-11-25T09:07:37.342-08:00Update: SourceForge no longer offers the Wikispaces wiki, this post is left up for historical curiosity.The default wiki for SourceForge projects is used to be called Wikispaces. The CSS stylesheet configuration on the SourceForge Wikispaces is such that list items (HTML "li") are smaller than normal, and shrink as they are nested. Top level list items are smaller than I would care for, and byJason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-11452977250179629752009-05-04T13:54:00.000-07:002009-05-04T14:08:56.930-07:00With the Oracle client 10.2.0.1.0 installer if you are automating the install with a response file, set UNIX_GROUP_NAME to something like say 'dba', then run the install but you are not in the dba group the install will fail with:SEVERE:S_OWNER_SYSTEM_EPERMI found nothing useful via a search for that error so I thought I'd post something. It would seem that you need to set UNIX_GROUP_NAME to a Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com2tag:blogger.com,1999:blog-5887256.post-71329170326169154262009-04-24T17:47:00.000-07:002009-04-24T17:55:52.080-07:00I was working on building the mysql ruby gem. My mysql install is in a non-standard location. I could get the gem to build with syntax like:gem install mysql -- --with-mysql-config=/path/to/bin/mysql_configHowever, I noticed that the resulting library did not embed the path to the mysql library, ldd on the mysql.so indicated:libmysqlclient.so.16 => not foundI did not want to have to fiddle withJason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-28880286533964495372009-03-12T11:40:00.000-07:002009-03-12T14:44:38.846-07:00Speaking of Perl, Ruby and sorting, sort in both Perl and Ruby allow you to specify a code block to implement your own arbitrary sorting routine. Perl's documentation shows you how you can define this as a subroutine and just reference the subroutine when you call sort. This is handy both for re-use and when your sort routine is complex and doesn't easily fit on one line. Ruby's sort Jason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-60212404296070375792009-03-11T17:22:00.000-07:002009-03-12T11:23:39.930-07:00When sorting complex structures in Perl is is common to use syntax like:sort { $lname{$a} <=> $lname{$b} || $fname{$a} <=> $fname{$b} } @namesThe Perl sort documentation lists examples with this syntax. True to form the Ruby sort documentation doesn't show examples of anything that complex. Best I can tell anything like this doesn't work in Ruby:a <=> b || c <=> dAny way I write that I get backJason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0tag:blogger.com,1999:blog-5887256.post-73444078820445724122009-03-04T16:00:00.000-08:002009-03-04T16:06:23.660-08:00A couple of MacPorts errors I just encountered:Error: Unable to execute port: can't read "frameworks_dir": no such variableI had version 1.6 and it seems the recommendation to fix this is to update to 1.7 (via port selfupdate). I started port in interactive mode, ran selfupdate, then tried my install again and got:Error: Unable to open port: can't read "porturl": no such variableI wasn't sure ifJason Heisshttp://www.blogger.com/profile/07377919426705058481noreply@blogger.com0