20091006

MonoDevelop Custom Color Schemes

I have been playing with MonoDevelop 2.0 on Ubuntu on and off for a while now, but one of the things I find most annoying (other than not having ReSharper) is there is no easy way to modify the colors used for syntax highlighting. Sure, it has several pre-defined schemes you can choose from (Using Edit | Prefrences > Text Editor > Syntax Highlighting), but changing individual syntax element colors using the GUI is not possible.


The reason I find this issue annoying is that I like to have comments and strings really stand out – in our shop we avoid comments as much as possible, and string constants are kept to a minimum, so I like to be able to see them easily in the code. A few years ago, I started using “highlighter” background colors for comments and strings, and have become quite attached to them ever since.


After many attempts to find a solution on the web, I finally found all the pieces I needed to make it happen. The basic problem is that although MonoDevelop allows you to add new color schemes, the format of the scheme file is not well documented, and there are a few tricks you need to know to make it work correctly. The existing schemes are embedded resources and not stand alone files, so they can't be easily viewed for reference. Finally, I discovered this Ubuntu Forum thread that helped me find the solution. The first piece of the puzzle was discovering the color scheme XML source files in MonoDevelop's SVN tree. Now I had some samples to go by. Another useful tidbit from that thread was that the file name must end in "Style.xml" in order to work correctly. I did not actually verify that this was required, but I did it just to be safe. The rest came from a MonoDevelop Developer's Article page I stumbled across shortly thereafter. One of the important things mentioned on that page is that you need to put the color scheme XML file in the ~/.config/syntaxmodes directory (although in my Ubuntu installation it is actually ~/.config/MonoDevelop/syntaxmodes). Now I had everything I needed to start tweaking colors!

The first thing I did was download the VisualStudioStyle.xml file and renamed it to TeknynjaStyle.xml. Next I edited the file to change the name and _description attributes of the EditorStyle tag so they would not clash with the existing styles in the GUI. Finally, using the information from the MonoDevelop article and the existing examples, I modified the colors for comments and strings to get the highlighting I was looking for:

   <Style name="comment" color="black" bgColor="#ffff80"/>
<Style name="comment.doc" color="black" bgColor="#ff8040"/>
<Style name="comment.tag.doc" color="black" bgColor="#ff8040"/>

<Style name="text.preprocessor" color="purple"/>
<Style name="text.markup" color="skyblue"/>

<Style name="constant" color="black"/>
<Style name="constant.language" color="keyword-blue"/>

<Style name="string" color="black" bgColor="#80ff80"/>
<Style name="string.single" color="black" bgColor="#80ff80"/>
<Style name="string.double" color="black" bgColor="#80ff80"/>
<Style name="string.other" color="black" bgColor="#80ff80"/>

<Style name="keyword" color="keyword-blue">
<Style name="type" color="#004080"/>
</Style>

I found the "bgColor" attribute by looking in one of the other color scheme files. Then I copied my customized color scheme file to ~/.config/MonoDevelop/syntaxmodes, restarted MonoDevelop, and selected my color scheme. I was able to tweak the colors by editing the XML file and restarting MonoDevelop until I achieved the scheme I was looking for. Finally I had the highlighting I was used to in Visual Studio, and along with modifying some of my commonly used key bindings, I was able to make MonoDevelop feel a little more like "home".

Read More......

20090603

To Protect and Surf (dnsmasq and Whitelists)

Contrary to popular rumor, I am still alive and very busy – from about October of last year until last month I have been buried at work (a good thing in this economy!). Maybe now that I can see a little daylight, I can try to keep this blog updated a little more frequently. Enough with the excuses and on with the post.

The only person in this house that likes to spend more time on the computer than me is my 4 year old son. Most of the time he is content to play an old copy of Monster Truck Madness 2 that I picked up years ago, but he also likes to spend time at Dan-Dare.org, Playhouse Disney, PBS Kids, and several other sites. The problem (other than trying to limit his time on the computer) is that he also likes to explore. When he gets bored just playing the games, he's off checking out what each menu item and dialog box does. He has explored all the configuration options in the monster truck game, and he is always playing with the volume control applet – I've spent plenty of time trying to undo his changes on the kid's computer. Lately, he has also taken to checking out the various links on the websites he visits. A couple of times he has run in to inform us that we can get a free monster truck game, and when we go check on him he has wandered off to some obscure website. Well, it happened again today, and although I've always known I would have to take action, today was the day to do something about it.

Being the cheap bastard that I am, I needed a free solution that would keep him (or my 7 year old daughter) from visiting places on the web that I would rather not have them be for now. I decided that what I need for now is a DNS forwarder with a whitelist, so that only the sites on the list can be accessed. Although the following solution is fine for small kids, anyone with an 8088 for a brain can figure out how to get around this. Even so, it should work for us for the next few years.

A little surfing pointed me to dnsmasq, a very popular dns forwarding server. A little more research indicated that using it to whitelist domains was not easy – there is no built-in way to do it. I found someone who listed a source patch to make it happen, but I didn't want to go to that extreme if I could avoid it. Despite this, I went ahead and installed it on my file server (running Ubuntu, of course) using sudo apt-get install dnsmasq. Looking at all the options in the man page and in the /etc/dnsmasq.conf file was overwhelming at first, but it didn't take too long to figure things out. One of the things I discovered was that you can assign specific outside DNS servers for specific domains. I realized that if I blocked off any other way for it to resolve domain names except for this feature, I could use it like a whitelist! A little experimenting proved that it did indeed work. Here is the dnsmask.conf that I am using right now:

domain-needed
bogus-priv
log-queries
log-facility=/var/log/dnsmasq.log
no-resolv
interface=eth0

# Add other name servers here, with domain specs if they are for
# non-public domains.
#server=/localnet/192.168.0.1
server=/google.com/192.168.0.1
server=/dan-dare.org/192.168.0.1
server=/dan-dare.net/192.168.0.1
server=/pbskids.org/192.168.0.1
server=/playhousedisney.com/192.168.0.1
server=/disney.go.com/192.168.0.1
server=/starfall.com/192.168.0.1


The first few lines do the actual configuration of dnsmasq, domain-needed & bogus-priv block Windows machines from passing noise traffic, log-queries & log-facility tell dnsmasq to log all DNS requests to the /var/log/dnsmasq.log file (useful for determining the domains required by websites, but this can be turned off to save space), no-resolv tells it to ignore the resolv.conf file which usually lists the outside DNS servers to use, and finally interface tells the service which network interface to bind to.

The rest of the “server” lines implement the whitelist, telling dnsmasq to look for the specified domain's IP address using the specified DNS server. In this case, I simply pointed to the DNS server in my local network's router (192.168.0.1). Any other domains are simply returned as being invalid. To populate this list, I simply attempted to browse to the sites my children visit, and then looked in the /var/log/dnsmasq.log file to see what domains were being requested, then entered them into the dnsmasq.conf file. After each update to the configuration file, I needed to sudo /etc/init.d/dnsmasq restart to get the service to re-read the file.

The final step was to change the DNS server address on the kid's computer to point to the file server's IP address, and that was it – now anytime they “accidentally” try to access a domain not in the list, they get a message saying the domain was not found. Of course any computer-savvy person could simply set the DNS server to something else (like OpenDNS!), but it will probably be a few years before my kids figure that out. If they want to visit someplace new, I have to intervene (which is what I want). In a few more years, I will have to be more creative to keep ahead of the kids and to keep my workload down updating the list – but for now this works for me.

So hopefully, if there are other people like me searching for a way to add whitelisting to their dnsmasq forwarders, maybe this post will be a starting point. If you have any questions, go ahead and leave me a comment or send me an email, I'll do my best to help. And maybe if things slow down a little there will be more frequent posting around here as well.

Read More......

20080928

Ubuntu Photo Frame


About two years ago I converted an old laptop into a photo frame for the living room. There are plenty of examples of how to do this floating around on the web these days, so I am not going to cover that here. What I am going to talk about are the software aspects of this project, and my recent upgrade of my photo frame.

The frame had been working fine for almost two years, but a few months ago I upgraded my WiFi network at the house to WPA (finally), but that meant that I could no longer transfer files to the frame because the WiFi card I was using in it only supported WEP. Shortly after that, the frame started acting strangely, turning itself off about once a day, then finally not booting at all with the infamous “missing file” messages you get when Windows can't read the hard drive correctly.

The original software setup for this project was Windows 2000 with a small .NET application I wrote to scan a directory and display pictures from it. When it was time to display the next photo, the program would scan the directory and pick a new picture at random to display. The laptop hardware did not have enough “horsepower” to handle any kind of transitions or fades between photos, so the program just displayed the next photo on the screen without any transitions.

I brought the frame back to my cave, where I confirmed that the hard drive had indeed given out. I ordered a SYBA SY-IDE2CF-NB25 Ultra IDE to Compact Flash Adapter from StarSurplus, and with a 4GB Compact Flash card I had laying around, I now had a solid state hard drive for the frame. I also ordered a EDIMAX EW-7108PCg 802.11g/b Wireless LAN PC Card from NewEgg to allow WiFi access to the frame again. I selected this card because it is well supported under Linux and it is very inexpensive. Now that I had all the hardware ready, time to re-install the software.

I wanted to use Ubuntu for this project, because I am familiar with it, and this would give me an opportunity to learn about doing a very minimal installation. My goal was to use as little space on the flash drive as possible for the OS and supporting programs to leave room for photos. After a few practice runs setting up the system and trying different programs, I came up with the following recipe.

First, I installed Ubuntu Server, with the OpenSSH and Samba options. The server edition of Ubuntu doesn't install any kind of GUI (just a command prompt) and none of the heavy applications like OpenOffice, Evolution, etc. Then I got the Wifi card working (it wasn't detected during setup) and performed an upgrade to make sure I had the latest security patches. I setup Samba to allow access to the folder containing the pictures to be displayed. Next I apt-get installed xorg, dnotify, and feh. feh is a small, lightweight image display program for X. While playing around with different configurations, I discovered that even under Ubuntu, this laptop just didn't have what it takes to display transitions between photos, and so feh fit the bill almost perfectly.

I tweaked the xorg.conf file to prevent it from blanking the screen (I think it defaults to blank after 10 minutes), copied some photos to the frame, and fired off feh using xinit. And my photo slide show started up! The only problem with feh is that it only reads the files in the directory when it starts up, so if I add pictures to the directory later, I would have to restart the program in order for them to be shown. So I created the following script using dnotify to restart the program whenever any files in the folder have changed.


#!/bin/bash
export HOME=/home/teknynja
while true; do
killall -q feh
sleep 1
xinit /usr/bin/feh -rzFZD180 --hide-pointer /home/teknynja/Pictures &
dnotify -MCDRro /home/teknynja/Pictures
done

I made the script executable, and added a line to invoke the script from inside /etc/rc.local so that it would run when the system started up. After a couple of days of testing in the cave, I put everything back together and it is now back in the living room, displaying our family photos once again. It also has the added bonus of being completely silent, due to the solid state hard drive. The total space budget on the flash drive was 645MB for the OS and supporting programs, leaving around 3GB for photos, which is more than enough for now.

Once again I warn the readers that I still have a lot to learn about Linux, so any constructive comments are appreciated. If you have any questions or would like more details about this project, feel free to leave a comment and I will try to help you if I can.

Read More......

20080908

Obscure Ubuntu Tip: CRON User account has expired

No, I haven't forgotten that I have a blog. I've just been keeping busy with a lot going on at work, and a backlog of “projects” at home after finishing up the kitchen project. Some of those projects have involved getting down-and-dirty with Ubuntu, and I thought I would share a quick tip I discovered yesterday.

I was looking through the system log (/var/log/syslog) on one of my servers and I noticed it was full of “CRON[xxxx]: User account has expired” messages. A little searching on the web pointed to the fact that the root account had been locked. While setting up this server, I had followed some instructions I found on the web that required me to unlock the root account, then re-lock it when I was done with the

sudo passwd -l root
command. Locking an account this way also causes the password to be expired, one of the results of which is the above mentioned log entries. Most of the solutions I found on the web involved either unlocking the root again and giving it a long, random password, or manually editing the password files. I think I've found the correct way to fix this though, by using the
sudo chage -E-1 root
command, which sets the root's password to never expire. (Note that the -1 is negative one, not dash L). After using the above command, the system log showed normal CRON log entries, and the root account remained locked.

I hope someone else will find this information to be of use. That's it for my very obscure Ubuntu tip. Join me again soon for another exciting post. I actually have a good sized list of topics to cover on the blog, so hopefully things will settle down and you will hear more from me soon. Thanks for stopping by!

Read More......

20080629

Picture Perfect


This past Father's Day I received a shocking but pleasant surprise – a shiny new Canon SD870IS ELPH point and shoot camera! The shocking part was due to the fact that my wife never buys technology for me, because I am so picky about my gadgets. The pleasant part is because I've been looking to replace our old SD200 that we've had for years. We both loved that camera because of it's small size, ease of use, and fast response time (when you have two fast-moving little ones, it helps to have a camera that can capture an photo right when you press the shutter release). We've also shot hours of video with the SD200, because even though we have a nice Sony camcorder, we never feel like lugging it around with us. The video quality is more than acceptable and it allows us to capture moments we would never have been able to with something larger. The SD200's 3.2 mega-pixel sensor worked fine for the kinds of shots we take.

So enter the SD870IS. The coolest feature about this camera is the “IS” at the end – Image Stabilization. For normal shooting it helps eliminate blur and even works on the large, bright 3” screen. (I was always jealous of other camera's big screens when all I had was the SD200's 2.5” screen). But the stabilization really comes in handy for shooting video. With such a small device, shaking is always a problem on video. The old camera's video always had a lot of shake and could be annoying to watch sometimes, but this new camera shoots nice, steady video that is wonderful to watch! And for photos, the 8 mega-pixel sensor allows us do more with printing and cropping than we could ever do before.

Over the years since the SD200 was introduced, Canon has added tons of cool little features to the software, too numerous to mention here, but several new shooting modes, and auto adjusting the image orientation while reviewing images are a couple of them that I really appreciate. The SD870IS still has some of the same issues as it's older cousin, most notably it's mediocre low light performance But overall, I am excited to have this cool new toy to play with, and I'm no longer lusting over the other cameras I see when we take the kids to Disneyland! Thanks Honey!

Read More......

20080617

Video Sedation


During one of Woot's last “Woot-Offs”, I picked up a couple of Sansa E250 media players for the kids to watch videos on when we need them to be calm and quite (like during visits to Ikea). They each already have a Sansa Shaker loaded with their favorite songs (Tucker seems very fond of his blue “radio”), but video is a much more effective way to keep them “sedated”. In the past, I used my T-Mobile MDA with several hours of their favorite movies loaded on it to keep them occupied – but they both had to share the screen and I didn't like the idea of them fondling my phone and possibly dropping or otherwise injuring it.

For $30 bucks each during the woot-off, I figured I couldn't go wrong, so I ordered two of them. I quickly discovered that the built-in firmware for these players could only handle video encoded using Apple Quicktime DLLs that I have so far managed to keep off my system. Plus, the compression of the supported format was so bad that I could have only put a few minutes of video in the limited 2Gb of memory the devices contain.




Here's were Rockbox saves the day. Before I pressed the shiny “I Want One” button on Woot, I did a little research and discovered this project and found it supports the players I was about to purchase. I went ahead an placed my order for two, then within hours of their arrival, I had the Rockbox firmware installed on them. I played with the software, tweaking the many settings and options the firmware provides.

Finally it was time to put some videos on the devices. It took a while to figure out the optimal encoding options for these devices, but after playing around for a few hours I arrived at the following settings:






























Video Encoding Format MPEG2 (RockBox only supports this for now)
Video Resolution 224x176
Video Bitrate 192 kbps
Video Frame Rate 25 fps
Audio Encoding Format MPEG-1 Layer 2
Audio Samping Rate 44100 Hz (other samping rates break mpeg 2 compatibility)
Audio Bitrate 64 kb/s, Monophonic


Although this results in some serious visual artifacts, this is perfectly fine for the kids to watch (they haven't complained yet!). These settings allow me to cram several hours of video onto the players. The only thing I haven't figured out yet is how long the batteries last during video playback – the longest stretch of time the kids have watched the devices is about 90 minutes during a drive back from Grandma's House.

I figured I should share this little tip in case anyone else needs to administer some “video sedation” of their own while out in the world. As always, any tips and suggestions are always appreciated in the comments.

Read More......

Kitchen Mod Update


Sorry I haven't been posting in a while, but once I got started on the kitchen, every free moment after work was devoted to it. I finally finished all the tough stuff last week, all that's left to do is convert a can light in the ceiling to a hanging lamp that Kelly picked out at Ikea (where else?) The granite people came out last week and attached the sub-tops and made templates, but we are still waiting for them to contact us so we can choose the layout. But even with just the sub-tops (read plywood), life with an island in the kitchen is much better. You can see more details on our kitchen project on Kelly's blog at IkeaFans. It isn't up to date with the latest pics yet, but you can get an idea of what I've been up to the last few weeks.

Read More......
 
Template design by Amanda @ Blogger Buster