Tag Archives: files

New Year, New Cloud Solution

Happy New Year everyone! I’m kicking it off with a change from SparkleShare to Seafile for my private, self-hosted cloud storage. I have a server (Ubuntu 12.04) in my room that’s been running a SparkleShare cloud for about five months. It was my first time setting up anything of the like, so I’ve stuck with it through the annoying bugs. It does have many awesome features and has been super convenient, but I can’t get over the fact that it will never work with Git repositories. Admittedly I didn’t look that hard, but I thought the only other option for private cloud hosting was CloudShare.

Anyway, I was at Barnes & Noble yesterday and saw mention of Seafile in one of the many Ubuntu/Linux magazines on display. I’d never heard the name, so of course I looked it up and started reading. It was immediately apparent that the level of polish on Seafile is outstanding. It has no problem with Git repos and syncs extremely fast. It hosts a web server called Seahub so users can collaborate on and discuss files. To top it all off, the documentation is excellent, which makes installation a breeze. The installation and setup only took a few hours last night, including transferring my files from the old system and creating all of my libraries. It’s even running on an extra domain I have so I don’t need to use my IP or a freeDNS URL.

The docs alone on Seafile were almost enough to convince me it was worth changing over. Still, I’m glad I found Pat’s articles on Patshead.com about his experience with the software. They really helped answer the remaining questions I had. My time with Seafile so far may be slim, but I’m already so glad I went for it. Everything about it has been awesome and I’m very excited to have a new cloud!

Hope you all have a wonderful start to 2014!!

I Forgot My Newline

This is a friendly reminder to always leave a blank line at the end of your text files. You might be thinking that it doesn’t really matter, and in many cases you’d probably be correct. However, there are also plenty of configuration files for apps that require it to be there. Those that do will most likely not tell you so it would be quite hard to find and fix the problem.

Technically, a text file is just a series of lines ending in a newline character “\n”. On very old systems, a file without the ending newline would not even be considered a text file. Operating systems and applications nowadays can handle this and still read the file, but not without problems. The most likely issue is that the last line will be completely ignored. Due to the missing newline, it’s not even considered a line of text. Hope the last line of your file wasn’t important!

A prime example is cron in Unix-like operating systems. Filling up the last line in a crontab and forgetting to add a newline at the end is one of the most common problems people run into when new to cron. That last command at the end of the crontab will simply not run.

I’ve run into this a few times in the past, so I decided to look it up and find out the deeper reasons behind programs expecting “\n”. I thought it would be interesting, and it was. I hope you’ve learned a useful tip, even if you don’t care about the reasons behind it.

If you want to be sure to never have this problem, check out Sublime Text, my favorite text editor for code and everything else. It has an option to force a newline at the end of a file on saving. Sweet! If you are already using Sublime Text, see my previous post on replacing the default icon with something much cooler.

Using Ruby Find To Look For Files

It’s only been a few months since I started learning Ruby, and I’ve found myself using Find more than any other standard library. It’s likely because I’m mostly doing scripting work to organize my files. If you’re also new to Ruby, you might not know about the Find library and its ability to seek out all files and folders recursively.

The core library’s Dir class has ‘Dir.entries’, but you only get an array of the files and folders in that top directory. When trying to interact with a lot of files in multiple directories, Find is your friend.

This little method will return an array of all the directories within the program’s pwd(present working directory) or any directory supplied to the method. Find has a ::prune method that stops looking any further into the given directory. It’s perfect for ignoring the .git folder incase find comes across any repositories.

This ‘find_files’ method is almost identical, but it finds files instead of directories. I know, very self explanatory, but I included this code here to point out something that came up when I first ran it. Most of my photo library comes from my Windows machine. I used Google Picasa for organizing, which makes a little hidden file inside any folder containing an image. Never really matters until you’re making a script to compare and move around some photos! Skipping any file path containing the word “picasa” fixes the problem easily.

I’ve found this useful quite a few times in both repeated use and one-time-use scripts. This technique could also be modified to return a hash instead of an array, containing extra metadata about each file. The returned info can be used in any number of ways, whether the desire is information or alteration.

I’ve had a lot of fun making simple scripts and command line tools. I write this in the hopes that a fellow budding Rubyist can be inspired to write fun scripts for their system. Please feel free to leave a comment, I’d love to hear about any cool things you’ve done with Find!