CKeditor – remove top toolbar and bottom toolbar

To use the CKeditor without the top and bottom toolbars, do the following:

config.removePlugins = "toolbar,elementspath"
config.resize_enabled = false

 

This will remove both the capability to resize the dialog and remove the grey toolbar at the bottom, as well as the entire top toolbar, without the need for CSS modifications.

If you’re using the rails plugin – these options can be passed in when creating the cktext_area object, for instance:

f.cktext_area :body, :ckeditor=>{resize_enabled:false, removePlugins: "toolbar,elementspath"}

Rails 4, Carrierwave, Remote file url uploading

If you’re running into the following error when attempting to use Carrierwave to upload a remote file url:

TypeError: no implicit conversion of nil into String

Then you’re probably very frustrated at the moment. I dug into the carrierwave gem to figure the issue out exactly, however I realized there was an easier (and much quicker solution).

If you want to upload a remote file URL using carrierwave, use the following syntax:

@photo = MediaItem.new
@photo.remote_photo_url = "http://www.example.com/url-to-picture-or-other-file"
@photo.save

 

Above, you’ll notice “photo” is emphasized. This value will change according to the name of your uploader. In our case, it is “photo”, however it can be anything.

Grep list only unique filenames

To list unique filenames using grep, do the following:

grep -irl "search-term" .

 

Notice the ‘l’ flag, short for –files-with-matches, defined as “Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.”

The i flag just makes the search case-insensitive, and r is recursive.

Fix footer to bottom if no vertical scrollbar

If you need a footer to stick to the bottom when there is no vertical scrollbar, do the following:


$(document).ready(function() { 
  if($("body").height() <= $(window).height()){ 
    $(".footer-container").css("bottom", 0);
    $(".footer-container").css("position", "absolute");
    $(".footer-container").css("width","100%");
  }
});

 

This will ensure the footer sticks to the bottom of the browser when there is no scrollbar (eliminating the weird empty space that can some times happen under the footer), while keeping the footer at the very bottom of the body whenever scrolling is needed (so that it doesn’t stick out and take up valuable screen space).

Sunspot Solr – Indexing PDF documents

Indexing PDF documents using sunspot / solr seemed like a difficult task initially. There are a number of tutorials dealing with this topic but they seemed overly complicated. In the end, I decided the simplest way to go about providing search functionality for indexed PDF documents was to

1) parse the documents locally
2) input the raw PDF text into an ActiveRecord Object.
3) index the associated raw text field and make it searchable

This allows us to skip the unnecessary step of having Solr index the PDF document, and instead indexes the raw PDF text – which is really the only thing we need.

The configuration is as follows

Gemfile

gem sunspot_rails
gem pdf-reader
group:development do
  gem sunspot_solr
end #we're using websolr on Heroku

 

Model Configuration

searchable do
  text :pdf_contents
end

 

Parsing and automatic indexing.

file = open(url_to_pdf_document) #if you are downloading the file, otherwise skip
reader = PDF::Reader.new(File.open(file,"rb"))
contents = ""
reader.pages.each do |page|
  #remove all newlines and extraneous white spaces from the raw content
  contents += page.text.gsub("\\n","").gsub(/\\s+/," ").strip 
end
object.pdf_contents = contents
object.save

 

The PDF document is now fully indexed and searchable within the rails app.

This post does not cover making the PDFs accessible through your App – this will depend on your specific situation. The steps above are storage agnostic and will work with any configuration (s3, local, other cloud service, etc).

Sublime Text 3 – Ubuntu – Package Control installation

If you’re running into the following error when attempting to install “Package Control’ for Sublime Text:

urllib.error.URLError:

Then you’ll need to install manually. The instructions suggest that you “Browse Packages”, then navigate to the “installed packages” directory. However, if you’re like me, the “Installed Packages” directory is not up the directory tree, it is down.

Simply download the Package Control zip manually and put it in the

~/.config/sublime-text-3/Installed Packages

directory and restart.

From there – you should have access to the necessary package control tools.

Broadcom Wireless and Ubuntu

If you’ve recently built a system with a broadcom wireless configuration with Ubuntu and noticed your wireless networks are nowhere to be found, then you’ll need to update your drivers (specifically adding wl).

This page will probably help:

http://www.broadcom.com/docs/linux_sta/README.txt

It is a pain, but once it is configured it generally works.

Install FFMPEG on Ubuntu

If you run into the following error when installing FFmpeg on Ubuntu

Package ffmpeg is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package ‘ffmpeg’ has no installation candidate

You can do the following to install FFmpeg instead:

sudo add-apt-repository ppa:jon-severinsson/ffmpeg
sudo apt-get update
sudo apt-get install ffmpeg

The PPA above is maintained here:

https://launchpad.net/~jon-severinsson/+archive/ffmpeg

And is referenced by the main FFMPEG page here
http://ffmpeg.org/download.html#LinuxBuilds