Ruby Lambdas

I’ve used ruby lambdas a few times, but I have to admit that I never really understood them. However, I’ve now come across a case where I have to figure them out. Here’s what I’ve found:

  • just a function without a name
  • in ruby, they’re objects
  • last expression of a lambda is its return value
  • they take parameters by surrounding them with pipes
  • use curly brackets {} for single line lambdas and do…end for multiline lambdas

Why did I want to use them? I use the paperclip gem to upload images to a webpage. I want to change this webpage so that in addition to image files, it will also accept pdfs. On the webpage, I show a thumbnail of each image. For pdf files, I want to have the thumbnail be a png file. The paperclip gem will allow a lambda with the has_attached_file definition. So this is what I have in my model:

has_attached_file :drawing, 
                    path: "#{Rails.root}/public/system/:attachment/:id/:style/:filename",
                    url: "/system/:attachment/:id/:style/:filename",
                    styles: (lambda do |attachment| 
                      if File.extname(attachment.original_filename) == '.pdf'
                        { thumbnail: ["240x240>","png"], medium: ["680x680>", "png"] }
                        { thumbnail: ["240x240>"], medium: ["680x680>"] }

With this, I can use my regular means of displaying the thumbnails as images. I only have to check if the file is a pdf in the one view I have that displays the original file. On that page, I use this:

<% if (File.extname("#{@image.drawing_file_name}") == '.pdf') %>

width=<%= @image.width %> height=<%= @image.height %>>

<% else %>

<%= link_to((image_tag @image.drawing.url(:original)), action: 'show', id: @image )%>

<% end %>

Authlogic Error

I put up a new website that wouldn’t allow me to login and kept giving me an error that said something like undefined method `save_without_session_maintenance’. I double-checked all my controllers and models against another site that was working fine and they all matched up. I didn’t find any bug reports for the version of Authlogic that I was using. The solution was to just deploy the app again. After that, I was able to login successfully. Weird.

Remote Desktop Services with a Samba PDC

We’ve been using a linux computer running samba and openldap as our primary domain controller for a windows domain for years. I absolutely love the fact that I don’t have to deal with windows and their crazy licensing. More importantly, this setup makes it easy for me to create accounts to give people access to everything in our shop. This includes windows accounts, linux accounts and website accounts.

Recently, I bought a very big, fast, loaded with ram server for some of our group to use for their very big designs. These are designs that would run overnight to compile or simulate. On this new server, I also put an ssd drive to help performance even more.

Currently, all of our windows computers are running Windows 7, which everyone likes. I thought that this server should probably run a Windows Server OS, so I installed Windows Server 2012 on it. I made my standard changes to the registry to allow it to join our linux PDC.

Add two DWORDS with the following values:

DomainCompatibilityMode = 1
DNSNameResolutionRequired = 0

Next, open gpedit.msc and change:

Computer Configuration ->
  Administrative Templates ->
    System ->
      User Profiles
Set maximum wait time for the network if a user has a roaming profile or remote home directory = 0

Then, you can join our regular domain as usual.

The next part is where I had to play around with a bunch of stuff, but I hope I describe the important parts.

We now need to allow remote connections. Go to Control Panel – System and then Remote Settings. I selected “Allow remote connections to this computer”. And then under “Select Users”, I added DOMAIN\Domain Admins and DOMAIN\Domain Users. At this point, I could use Remote Desktop from another computer and log into this server. Yay! But then Boo! I soon discovered that we were limited to just two users at a time. (And this is when I wanted to punch Bill Gates in the face.) To allow more than two users, you had to buy Remote Desktop CALs for each of the other users and serve them from a license server.

In our case, we had to run the license server on this computer. Normally, people would probably run it on their PDC. But since ours was running linux, that wouldn’t work.

Start Server Manager and click on ‘Add roles and features’. At the installation type, select ‘Role-based or feature-based installation’. (EVERY website says to click on the Remote Desktop Services Installation. However, this requires running something on the domain controller, so it just won’t work.) Select the name of your server, which for us was the only one listed. Go to Remote Desktop Services and select the following:

Remote Desktop Connection Broker
Remote Desktop Licensing
Remote Desktop Session Host
Remote Desktop Virtualization Host

Some other stuff might get selected with this, so accept those as well. I think I had to reboot after this was done, but I don’t exactly remember.

After rebooting, in Control Panel – Administrative Tools – Remote Desktop Services, you should have two links:

RD Licensing Diagnoser
Remote Desktop Licensing Manager

If you start the Licensing Manager, you should be able to right-click on your server name and “Install Licenses”. This is where you’ll enter the code for your CALs.

Thanks to this website, I found that the next step needs to be open gpedit.msc and go to:

Computer Configuration \
 Administrative Templates \
  Windows Components \
   Remote Desktop Services \
    Remote Desktop Session Host \

Enable “Use the specified Remote Desktop license servers” and set the license server name to the NetBIOS name of your server So if your server is usually PHYSICS\ADMIN, you’d put ADMIN in the box. If you put the ip address or fqdn in the box, things won’t work right. Secondly, enable “Set the Remote Desktop licensing mode” to Per User. (You might use Per Device, it’s up to you.) Again, I can’t remember if I had to reboot after these changes or not. Knowing me, I probably did.

Now if you go back to the RD Licensing Diagnoser, you should see the number of CALs that you got as available for clients. I also get a warning about “The RD Licensing Diagnoser tool is running with local account credentials…” Since things work, I’m happy to ignore this.

There were some other changes I made in the Local Group Policy Editor (gpedit.msc) that were just for us.

Computer Configuration \
 Administrative Templates \
  Windows Components \
   Remote Desktop Services \
    Remote Desktop Session Host \

Enabled “Allow users to connect remotely by using Remote Desktop Services”
Enabled “Limit number of connections” to 999999 (unlimited)
Enabled “Restrict Remote Desktop Services users to a single Remote Desktop Services session”

That pretty much does it. Took me the better part of an entire day to get this configured, so I hope it works well for us. It’s good to periodically go through this insanity with Microsoft products. It makes me very happy that I only have to deal with them every few years. I’m definitely much happier in the linux realm.

Serving SVG Files

I updated a website and changed to using svg files for our header. On our test setup, we were running RHEL7, which had a newer version of httpd than what’ on our production server, which is running RHEL5. I had to add the following to our httpd.conf file to tell it to specifically serve svg files.

# Need to serve svg files at image/svg+xml
# Using svg files in header for new pages, updated April 2015
AddType image/svg+xml svg svgz
AddEncoding gzip svgz

Sendmail on Centos 7.1

I’m running a server that I recently upgraded to Centos 7. For a few months, it wouldn’t send mail and today I finally decided to do something about it. I was getting an error AUTH warning: no mechanisms. After messing around for a while, I saw this in /etc/mail/access:

# If you want to use AuthInfo with "M:PLAIN LOGIN", make sure to have the 
# cyrus-sasl-plain package installed.

Once I installed the cyrus-sasl-plain package and restarted saslauthd and sendmail, I could send mail (over a TLS link only) again.

Make a Bootable USB Drive with Yosemite Installer

I wanted to completely reformat and reinstall Yosemite on an old iMac. To do this, I needed to make something I could boot from. I got an 8gb usb flash drive and used Disk Utility to reformat it to a Mac filesystem that I called Yosemite. This disk was then mounted at /Volumes/Yosemite. I then went to the App Store and downloaded Yosemite, but cancelled the installation. This left the installer in /Applications/Install OS X Then, to make the bootable drive, I ran the following command:

yo:~ $ sudo /Applications/Install\ OS\ X\ --volume /Volumes/Yosemite --applicationpath /Applications/Install\ OS\ X\ --nointeraction
Erasing Disk: 0%... 10%... 20%... 30%...100%...
Copying installer files to disk...
Copy complete.
Making disk bootable...
Copying boot files...
Copy complete.
yo:~ $ 

I don’t remember how long it took, but I definitely had to wait a while. I’d say maybe 30 minutes or so. But it worked perfectly.