Time Wasters

Because you can’t be productive all the time

iDrive and hidden files

I’ve been trying to backup all my files to iDrive since August >.o It’s about 500GB so I suppose I shouldn’t be too surprised it’s taken forever, and apparently iDrive is slow, but just yesterday I was cleaning up some files and noticed there were some problematic files that haven’t been helping in the backup process. (over 210K of them in fact!) So I took some time and did 4 things to help get my backups rolling.

#1 Delete all .AppleDouble files

I was working on a Mac for a few years, and have some back-ups from them, and after going through the logs I notice a ton of “.AppleDouble” files. Apparently Macs make an AppleDouble of every.single.file. So…there were literally twice as many files to back up. I can just tell iDrive to ignore those files, and I did, but I also wanted to get rid of them all, since I’m no longer on a Mac. So I loaded up the shell from my QNAP, and ran this command:

rm -rf `find -type d -name .AppleDouble`

Which deletes all directories and their contents named “.AppleDouble” under the current directory.

Also, iDrive came up with a few of these odd errors:

#2 Delete all Icon\r files

IOERROR [/share/MD0_DATA/…/Icon], : No such file or directory

I also found about 20 of these odd Icon files, apparently their placeholders so Mac’s can change the icon of the folder. But their names are awkward so iDrive can’t handle them and I can’t delete them normally. They’re actually named “Icon\r” so I had to log into the shell again and run this command in order to delete them all:

rm $’Icon\r’

#3 Stop generating thumbnails

And last, but not least is my QNAP’s fault, by default file manager it generates .@__thumb folders with icons for every single image. Of which I have quite a few. Log in as admin, and you can disable the file generation this way:


That will stop new ones from being created, but not delete all the old ones, you can fire up the shell again and run this command to do that:

rm -rf `find -type d -name .@__thumb`

#4 Upgrade to the latest iDrive

I also noticed that the version of the iDrive app in QNAP’s App Center is out of date, so I grabbed a the latest version here: https://www.idrive.com/qnap-backup

The only problem is you have to download the right one for your NAS, but no matter where I looked I couldn’t find what mine is running. I ended up finding out by opening the iDrive in the App Center, I hovered over the download link, and voila!  It has the version right in the file name.  A little backwards to do it, but I couldn’t find the answer anywhere on the QNAP site.

Screenshot (109)



Permalink » No comments

Compress Rails project images

We were having some issues with slow loading times on our site, so I set out to compress all of our uploaded images.  Since we have thousands of images doing it by hand is not really an option, and plenty of the images are transparent PNGs.  So I enlisted the help of TinyPNG.

TinyPNG is an online application that compresses both PNG and JPG images, and preserves the alpha layer for PNG images, and it offers an API along with a ruby gem.  So you can use it to automate compressing images.  First start by installing the gem, and I also use the fastimage gem for this script so if you don’t have it install that too.

gem install tinify
gem install fastimage
rbenv rehash (if you're using rbenv)

Now you just need the script below:

require "tinify"
require 'fastimage'
Tinify.key = "YOUR API KEY"
i = 0
Dir.glob("public/system/rich/rich_files/rich_files/**/*.{jpg,png}") do |item|
  #only do 50 images at a time
  break if i == 10
  #ignorre directories and original files
  next if item == '.' or item == '..' or item.include? "original"
  #ignore iamges less than 50KB
  filesize = (File.size(item) * 0.001).floor
  next if filesize < 50
  #ignore images that are smaller thatn 100KB and over 600px large
  size = (FastImage.size(item).inject(:+))
  next if size >= 600 and filesize < 100
  i = i + 1
  source = Tinify.from_file(item)
  new_filesize = (File.size(item) * 0.001).floor
  puts "Converted: #{item}"
  puts "Original: #{filesize} Optimized #{new_filesize}"
puts "All done!"

Some things you’ll need to address to get this working are first, swap out “YOUR API KEY” with your actual API key, you can get one here. And if you’re not using the rich gem to handle image uploads you’ll need to change “public/system/rich/rich_files/rich_files” to whatever the location of your images is. The “**/*” part of the path will search all sub-directories and files in those sub-directories, and “.{jpg,png}” will only search jpg and png images.

The code will go through all the JPG and PNG files in your images directory, it will ignore all original versions, and then ignore files that are too small to bother with and then print out the files that were compressed along with their original and optimized sizes, then print out “All done!” once it’s finished.

Save it as tinify.rb and you can run it in the console with:

ruby tinify.rb

This will process 50 images at a time, and ignore images that I’ve set as too low to both with, so all images under 50KB are ignored, and images over 600x600px and lower than 100KB are ignored.  But this does pose a problem – images that aren’t reduced enough will still get re-reduced if you run the script multiple times.  For now I’m just monitoring it, and I’ll adjust it if too many images get caught.

Permalink » No comments

AJAX errors explained

I’ve recently finished adding Google Analytics to a mobile App I’ve been working on for some time, and it’s been returning quite a few different error codes from the API.  So, I’m keeping track of them here along with their causes – to make debugging faster and easier in the future.

Status: 406 / Error: Not Acceptable / Error Thrown: Not Acceptable

  1. A server side issue with the response
  2. The session on the server timed out

Status: 0 / Error: error

  1. user was unable to reach the server (most likely connection issue)

Status: 200 / Error: OK / Error Thrown: SyntaxError: Unexpected end of input

  1. Returned JSON was cut off (possibly connection issue)
  2. No JSON whatsoever was returned

Status: 0 / Error: timeout / Error Thrown: timeout

  1. duh, timeout!

Status: 200 / Error: OK / Error Thrown: SyntaxError: Unexpected token

  1. Have HTML returning instead of JSON
  2. Malformed JSON

Status: 401 / Error: Unauthorized / Error Thrown: Unauthorized

  1. User tried to login with wrong username and password

Permalink » No comments

Fats vs Carbs

This is something of a continuation of my “What’s in a calorie?”  article.  Where I dumied down good/bad carbs and fats and looked into why protein is the best thing since sliced bread (which is actually horrible for you).  So I want to continue my oversimplification to carbs vs fats.  There are many many more factors, but I’m trying to pieces things together so with nothing more then a nutrition facts label I can get an educated guess on exactly how good or bad that food is.

After a touch of research, here is my “ranking” of specific macro nutrients:

  1. Protein
  2. Good Fats
  3. Complex Carbs
  4. Saturated Fats
  5. Simple Carbs
  6. Trans Fats

Pretty much every article I looked at described Trans Fat as “the devil” so I think that’s pretty good on the bottom.  Current diet trends are all about Fats > Carbs so I have complex carbs under good fats.  Though, complex carbs/saturated fats seem like a grey area and could easily go the other way.  I’d really like to find something that compares the two in more depth.

This is still a work in progress, but I’m getting the ball rolling.

This time around I got introduced to the glycemic index which is another way to rank carbs. And I already know that not all sugars are created equal, but it seems like the only way to tell the difference is to memorize ingredients.  I don’t have time in my life to give everything such a thorough inspection, but I do have thoughts about putting together a program to assign points to foods based on their nutrition facts to make the process much more approachable.  Pretty much just like fooducate – but with an automatic instantaneous result.


Trans fat is the worst, sat fat not as bad

Sugars/simple carbs are worse then sat fat, but better then trans fat

Good carbs are worse then good fats

Permalink » No comments