Ruby ‘dups’

March 7th, 2010 peterk No comments

I was surprised to see Ruby doesn’t have this handy function:

module Enumerable
def dups
inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys
end
end

Categories: Uncategorized Tags:

CentOS and JFS

January 24th, 2010 peterk No comments

I like JFS: better performance than ext3 and more reliable than reiserfs. However installation under CentOS is awkward, at best. Here’s one of the better install guides I found. Quoted from http://www.norlin.se/blog/2006/12/28/centos-and-jfs/

JFS (Journaled File System) is a file system from IBM. I have always really liked this file system since I first came across it, working with AIX, but I have never used it in a Linux environment until now. When you read comparisons of different file systems it seems JFS always comes out in a top position. For Linux it is sometimes beaten by XFS, but I think that is due to the fact that XFS is more widely used on Linux.

For some reason RedHat seems to have taken out support for JFS in RHES, but it is available for CentOS using the kernel in the CentosPlus repository. The process to upgrade an existing Centos installation to support JFS is simply to update the kernel with the kernel in centosplus and install jfsutils:

yum –enablerepo=centosplus install kernel-smp
yum –enablerepo=centosplus install kernel-smp-devel
yum install jfsutils

Then you probably need to change the “default” row in grub.conf and reboot to start using the new kernel with JFS support.

To create a JFS file system on a new partition use fdisk and mkfs -t jfs.

I think you need to stick to ext3 for the root and boot file systems though and there is no path (at least that I know of) for migrating an existing ext3 file system to JFS “in place”.

Categories: Uncategorized Tags:

Presenting Lessons from Jay Fields

January 20th, 2010 peterk No comments

Quoted from Jay Fields blog:

Up until a few years ago I’d never done any type of public speaking. I’m outspoken among friends, but generally shy around strangers. However, some opportunities presented themselves and I decided to take the leap into the world of presenting. I thought it might be helpful to document some lessons I’ve learned. If you decide to take the leap into presenting, I hope these ideas make your journey a bit easier than mine.

  • Get Help – I took a class at Speakeasy (NYC). The class that I took forced me to stand in front of a small group of strangers, present on any topic I liked, and have the entire thing recorded. I learned about things that I was doing wrong, but I also got to see what mistakes the other people in the class were making. It was the single largest thing that improved my public speaking.
  • Practice – the last public talk I gave was at QCon SF 2008. In the weeks leading up to that talk I rehearsed the presentation at least 25 times. There’s so many reasons why a presentation can go wrong, so you’ll want to make sure you have the content down cold. You’ll lose the audience’s trust if at any time you look as though you don’t have the content down 100%.
  • Don’t Script Jokes – at QCon London 2008, I was feeling nervous and chatting with Jim Webber. Jokingly, I said “maybe I’ll open with: My name is Jay Fields, and yes, I’m American, but I guess you already knew that from my weight problem”. Jim thought it was “brilliant”. So I opened with the joke. But, it didn’t come out smooth or well-timed, it came out dry and forced. No one laughed, and I got to start out my presentation with awkward silence. If you’re naturally funny, it’s fine to improv a joke in the middle of the presentation; otherwise, I suggest sticking to the content.
  • Know Your Audience – Audience’s will react to your content in different ways based on several factors, it’s important to consider these factors when putting together your content. For example, a local Rails User Group may laugh at your joke about DBAs. However, at QCon there are likely to be DBAs, CTOs, and other audience members who may not find your DBA humor amusing. It’s also valuable to consider language barriers. In Europe, where my audiences often very mixed, jokes never seemed to amuse the audience in my talks or any that I attended. Maybe, the humor didn’t translate well, or maybe I was moving too quickly. Either way, I made a mental note to stick to the content when my audience was likely to speak English as a second language.
  • Look Natural – At Speakeasy I learned that “arms at your sides” is how to look natural to the audience. It’s extremely uncomfortable and feels unnatural to me, but I have the recorded video to show that I’m wrong. The problem is, if you are always waiving your arms around, or hiding them behind your back, you distract the audience. That’s not to say you should never move your arms, but do it less often. I tend to point or gesture way too often, so whenever I notice that I am, I just naturally put my arms down and focus on doing that for a bit.
  • Face Forward – When you turn your back on the audience, you lose them. Especially if you are talking with your back to them. Instead, take small, backward steps and always face the entire audience.
  • Pictures – pictures are really the way to go. If you put text on the screen, people will read the text and tune you out. Some presenters are amazing enough that they get away with no slides at all. I don’t suggest starting there. Technical conference-goers are used to slides. However, you can stick to pictures for your slides. If you have pictures that support your ideas, you can have slides while still forcing the audience to pay attention to you for content delivery.
  • Short Text – If you must use text, don’t use sentences, paragraphs, definitions, or anything else lengthy. A few words, as little as possible is the only way to go. If the audience is reading, they aren’t listening to you.
  • No Bullets – If you must you text, avoid bullets. Instead, show one line at a time and hide or shade the other lines.
  • Code Is Acceptable – Some ideas are more easily expressed with a snippet of code. Don’t avoid code when code is the best choice. Instead, when you bring the code up, give the audience 30 seconds (or whatever is appropriate) to digest the code, and then begin to discuss it. Just remember, as long as the code is on the screen, there will be people reading, and not paying attention to you.
  • No Distractions – Distractions can ruin a presentation. Excessive transitions, morphing text, blinking text, etc all take away from the message that you are trying to express. I remember seeing a Flex presentation at RailsConf where the presenters showed their Flex Twitter Client. It was really pretty, and kept popping up tweets from conference attendees. Putting it up was awesome, leaving it up was the worst possible choice. I can’t remember anything they said after they put up the application. I tuned them out for the remainder of the talk, and read all the tweets that kept popping up. I didn’t mean to, but I was drawn to the shiny objects. After the talk I asked a few friends if the presentation was any good. They had no idea, we were all entranced by the twitter client.
  • Start Small, Build Up – My wife is the first to hear (suffer) though any presentation that I put together. I practice it a few times, then present it to her, then practice a few more times, then move on to a slightly larger venue. A User Group or some peers at work are good audiences for a new talk. After you present to 10-20 people, you should feel pretty confident about giving the same presentation to 100-200 people.
  • Be Original – If you use a template provided with Powerpoint or Keynote, it’s likely that someone else at the conference will be using the same template.
  • Be Yourself – In my presentations I almost always swear and make some kind of sarcastic remark. That’s how I act among friends and when I act like myself in presentations people tend to accept that what I’m saying is what I believe, not what I’m trying to pitch.
  • Record Coding – Don’t live code unless you’ve practiced it 100 times, know how to deal with all possible problems, and are Justin Gehtland. Okay, I’m (sort-of) kidding about having to be Justin. However, the reality is that live coding is really, really hard. Often, you can express the same thing with a recorded coding session and there’s little to no chance that things will go wrong. Justin has acting, teaching, and presentation training. He’s also ridiculously smart. Those things combined mean he can carry a live coding session even when things go very wrong. If you have the same background, go for it. Otherwise, stick with the, much more likely to succeed, recorded coding session.
  • Questions – Pause for questions a few times during your presentation. It allows you to give color on ideas that you may not have clearly expressed. It also gives the audience the chance to see that you really know what you are talking about. For me, it also helps me relax and provide conversation, instead of simply lecturing.
  • Breathe – You know your content, the audience doesn’t. Chances are you are going too fast. The simple rule of thumb is, the audience is always at least 5 seconds behind whatever you are saying. If you take the time to breathe or take a sip of water, you give them the opportunity to catch up.
  • Relax – The best presentation ratings I’ve ever gotten were when I gave a presentation entirely hungover. I thought I was going to be terrible. But, I was too hungover to be nervous, and I gave a straightforward, natural presentation on the ideas. I’m not advocating that you get drunk the night before your presentation, but do take steps to relax, if you know how. For me, I like to have friends in the audience, a drink about an hour before the presentation and a drink right after. It’s my ritual and it helps ensure that I’m as relaxed as possible.

Almost everything I learned I got from Neal FordJim Webber, and Dan North. Thanks for the ideas, gentlemen. If I left anything out, it would be cool to see additional lessons that you’ve learned throughout the years.

Update:
Steve Vinoski said…
I’d add the following:

  • Always repeat any questions asked of you before answering them. This is important not only for the audience in front of you, but also especially for any audience viewing a recorded session at a later time.
  • Don’t be afraid to answer “I don’t know” if someone asks you a question you don’t know. The audience would rather hear honesty than some made-up BS. Presumably you possess specialized knowledge or wisdom, otherwise you wouldn’t be up there speaking, but that doesn’t mean you know everything, and frankly the audience doesn’t expect you to.
  • Ask the audience questions. This helps keep them engaged. Remember, your talk is really more about them than it is about you, so gauging the audience and adjusting accordingly can help maximize the value of your message to them.
  • Should you encounter an audience member who wants to challenge you and argue with you, just politely decline to engage by saying you’ll be happy to discuss the issue with them after the talk. Back-and-forth arguments with an audience member lose and annoy most of the rest of the audience almost immediately, and since you’re probably not repeating every statement the arguer makes, anyone watching a recording of the argument hears only half of it and you lose them immediately.
  • Above all, respect your audience and they’ll respect you. Except in extremely unusual circumstances, they want you to succeed because that way they’ll get the most out of your talk. If you’re a new or nervous speaker, keeping that in mind can help put you at ease.
Categories: Uncategorized Tags:

Vim Syntax File for go

November 22nd, 2009 peterk 1 comment

While installing go, configuring vim syntax took longer than it should – would have been easier if I had known the following:

mkdir ~/.vim/ftdetect and ~/.vim/syntax if they don’t exist
vi ~/.vim/ftdetect/go.vim
containing:
au BufRead,BufNewFile *.go set filetype=go

copy go.vim to $GOROOT/misc/vim/go.vim to ~/.vim/syntax/

And of course, make sure you are running vim-enhanced and not vim-tiny, as tiny doesn’t support syntax highlighting.

Categories: Uncategorized Tags:

Determine Ubuntu Filesystem Type

November 7th, 2009 peterk No comments

Ever connected a hard disk to your computer without knowing how the partitions are formatted, or even what type of formatting? This surprisingly hard-to-find utility reveals all:

/usr/lib/klibc/bin/fstype /dev/sdb1

just replace sdb1 with your drive.

fstype prints something like this:

FSTYPE=jfs
FSSIZE=156225608

I have no idea why the hide this under /usr/lib/klibc/bin. Other applications in the klibc-utils package get mapped to more reasonable locations.

Categories: Uncategorized Tags:

Multiple Ruby with update-alternatives

October 3rd, 2009 peterk 2 comments

Here’s a useful piece from David Lee on the Rails Oceania Google Group:

If any of you are using Ubuntu this is a pretty nice way to manage multiple ruby interpreters.

It has the advantage of managing the manpages, ri, and irb as “slaves”, so they change when a new interpreter is selected.

here’s the code:

# become root
su

# make sure the packages are installed for 1.8 & 1.9 aptitude install -s  ~n^ruby1.[89]$ ~n^irb1.[89]$ ~n^ri1.[89]

# install ruby1.8 & friends with priority 500
# so this will be the default “auto” choice
update-alternatives –install /usr/bin/ruby ruby /usr/bin/ruby1.8 500 \
–slave   /usr/share/man/man1/ruby.1.gz ruby.1.gz \
/usr/share/man/man1/ruby.1.8.gz \
–slave   /usr/bin/ri ri /usr/bin/ri1.8 \
–slave   /usr/bin/irb irb /usr/bin/irb1.8

# install ruby1.9 & friends with priority 400
update-alternatives –install /usr/bin/ruby ruby /usr/bin/ruby1.9 400 \
–slave   /usr/share/man/man1/ruby.1.gz ruby.1.gz \
/usr/share/man/man1/ruby.1.9.gz \
–slave   /usr/bin/ri ri /usr/bin/ri1.9 \
–slave   /usr/bin/irb irb /usr/bin/irb1.9

# choose your interpreter
# changes symlinks for /usr/bin/ruby ,
# /usr/bin/irb, /usr/bin/ri and man (1) ruby
update-alternatives –config ruby

for those with additional interpreters in say /usr/local/bin, other Debian variants, or managing other tools, vary as required.

% man update-alternatives

hope wrapping didn’t mangle it too much, and that someone finds this useful

Link to original here.

Categories: Uncategorized Tags:

Rails Rake Tutorial

August 4th, 2009 peterk No comments

Great Rails Rake tutorial from railsenvy.

More Rake stuff from railsenvy:

Now that you know enough to start writing useful rake tasks, I figured I should leave you with a few more resources. The best way to improve your programming is to read other people’s code, so a few of these are existing useful rake tasks people have written.

You’re all set! If you find any other good ones, feel free to post them in the comments.

Categories: Uncategorized Tags:

Remote Access to MySQL Server

July 31st, 2009 peterk No comments

Do something like this:

mysql -u root mysql
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root’@'remotehost’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;

For more details see:
http://www.idevelopment.info/data/MySQL/DBA_tips/Security/SEC_1.shtml

Categories: Uncategorized Tags:

Running VMWare Workstation VM’s as a service

July 31st, 2009 peterk 1 comment

If you don’t have VMWare Workstation, you can use the free VMPlayer instead – just replace vmware.exe with vmplayer.exe.

From Jim Kenzig:

The June issue of Windows .Net magazine has a good article about how to
run VMware VM’s as a service which may interest some of you:
See

http://www.winnetmag.com/Windows/Article/ArticleID/42607/42607.html

VMware-At Your Service!
Run VMware Workstation VMs as services
Chris Wolf
Feature
InstantDoc #42607
Windows & .NET Magazine

If you’re a VMware enthusiast, you’ve probably on more than one occasion
wanted to log off from your computer while leaving your virtual machines
(VMs) running. Or, maybe you’ve wanted selected VMs to start as soon as
your system boots so that your host system can log on to a domain
controller (DC) running inside one of the host machine’s VMs. Sound too
good to be true? That’s what I thought. I assumed that logging off of my
computer and having my VMs remain running was an unattainable dream. But
I discovered that getting VMs to run as services is possible and very
easy to configure.

Tools for Service
VMware doesn’t natively support running its software as a service, but
configuring VMware Workstation 4.0 VMs to run as services is almost as
easy as tying your shoes. All you need to get started are two
tried-and-true Windows resource kit tools: instsrv.exe and srvany.exe.
Both tools are available as free downloads. Go to
http://www.microsoft.com/downloads, enter Windows 2003 Resource Kit
Tools in the Keywords field, and click Go. Then, click the Windows
Server 2003 Resource Kit Tools Download button at the Windows Server
2003 Resource Kit Tools Web page to download rktools.exe-which contains
the most recent versions of Instsrv and Srvany-and run the executable to
install the tools on your system.

Note that you can install the Windows 2003 resource kit tools on a
Windows 2003 or Windows XP system. If your host system runs Windows 2000
or Windows NT, you can acquire Instsrv and Srvany from the Win2K or NT
resource kit CD-ROMs or you can install the Windows 2003 resource kit
tools on an XP system and just copy Instsrv and Srvany from the XP
system to the %windir% folder on your Win2K or NT host system. The
Windows 2003 versions of Instsrv and Srvany run on the earlier OSs
without any problems.

Getting Started
Installing the resource kit tools updates the system path to include the
resource kit installation folder. Updating the path requires a reboot,
so be sure to reboot your system after installing the resource kit.
Alternatively, you can copy Instsrv and Srvany to a folder already in
the path, such as the folder C:\windows\system32.

With the resource kit files in place, your next task is to determine the
location of the VMware application’s vmware.exe file. I used the default
settings when installing VMware, so the path I needed was C:\program
files\vmware\vmware workstation\vmware.exe.

The last bit of information that you need before you configure the new
service is the path to the configuration file of the VM that you want to
turn into a service. This file is in the folder in which the VM was
created and has a .vmx extension. All my VMs are stored on my system’s E
drive, so the path to the .vmx file of the VM that I want to run as a
service is E:\vms\w2k1\w2k1.vmx. When you have the vmware.exe path and a
VM’s .vmx path information, you’re ready to create the service.

Creating the Service
First, decide on a name for the service. I prefer to preface the name of
the VM with VM_ to form the service name. For example, I would give my
VM named W2K1 the service name VM_W2K1. After you decide on the service
name, you can use the following syntax to set up the service:

instsrv <VM service name> <Srvany path>
So a sample command might be

instsrv VM_W2K1 c:\windows\srvany.exe
Now you need to modify the service’s parameters by using a registry
editor and the Microsoft Management Console (MMC) Windows Services
snap-in. In the registry editor, navigate to the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<VM service name>
subkey. Right-click the VM service name, select New, then click Key.
Name the new subkey Parameters.

Right-click the Parameters subkey, select New, then click String Value.
Name the new value Application. Double-click the Application value and
enter the path to the vmware.exe file on your host system (put the
pathname in double quotation marks), followed by -x, followed by the
path to the VM’s .vmx file (put the pathname in double quotation marks).
For my configuration, I used the string value “C:\program
files\vmware\vmware workstation\vmware.exe” -x “e:\vms\w2k1\w2k1.vmx”.
Close the registry editor.

Open the Windows Services snap-in. Locate and right-click the newly
created VM service and select Properties. In the service’s Properties
dialog box, click the Log On tab. Ensure that Local System account is
selected, and select the Allow service to interact with desktop check
box, which Figure 1 shows. Click OK to close the service Properties
dialog box. You can now use the Windows Services snap-in to start your
VM service. By default, the service is configured as automatic, so the
VM will start when your system starts. Each VM that you configure to run
as a service will appear in its own window on the desktop. Because the
VM is running as a service, you’ll now be able to log off of your
system, and the VM will continue to run.

Tuning VMware
The configuration steps you’ve performed thus far will let any number of
VMs run as services without problems. However, you might find that some
built-in VMware features will get in the way. For example, when multiple
VMs attempt to start and share the same floppy drive, VMware displays a
message that the floppy drive will start as disconnected on all VMs
except for the one that was powered on first. You must click OK to
acknowledge the message before the VM boot processes will continue. To
prevent the need for manual intervention at boot time, you might want to
configure the settings of each VM on the host so that their floppy
drives don’t connect at power on.

To configure a VM’s floppy drive to start as disconnected, open the VM
in VMware, double-click the floppy drive icon, then clear the Connect at
Power On check box and click OK in the floppy drive’s Settings dialog
box. One other method for preventing the floppy drive from connecting at
power on is to open the VM’s .vmx configuration file in Notepad and set
the floppy0.startConnected parameter to “false”.

VMware hints might also interrupt a VM’s startup process. You can
prevent all hints from appearing for any particular VM by opening and
editing the VM’s .vmx file in Notepad. To disable all hints, add the line

hints.hideAll = “true”
to the file, as Figure 2 shows.

Take It to the Max
Now your VMs can run in ways you’ve never imagined. For example, you can
configure a VM to run as a DC that your host OS can log on to. When
you’ve attained the “unattainable dream” of running VMware as a service,
the possibilities are endless.

Resources
WEB SITES
VMware
http://vmware.com

Windows Server 2003 Resource Kit Tools
http://www.microsoft.com/downloads

Windows & .NET Magazine Network is a Division of Penton Media Inc.
Copyright © 2004 Penton Media, Inc., All rights reserved

Categories: Uncategorized Tags:

Windows XP Resource Issues

July 29th, 2009 peterk No comments

While trying to find out why my XP laptop is so screwed up, I ran across these tips from Artem Russakovskii:

Process explorer (technet.microsoft.com/en-us/sysinternals/…) is the first tool I’d use — what’s consuming resources? And how much memory are we talking about here? Is there at least 1GB in each of these machines, or less? – nedm

I also use Extended Task Manager (extensoft.com/?p=free_task_manager) to keep a little better tabs on what’s going on than the built-in one.

Oh, and lastly, verifier.exe (support.microsoft.com/kb/244617) can help diagnose and troubleshoot driver issues.

Categories: Uncategorized Tags: