Tuesday, August 9, 2011

How to fix "FontConfig <cachedir>" errors...

If you are getting "FontConfig <cachedir>" errors every time you run a program or in your Xorg.0.log file similar to the following:

Fontconfig warning: no  elements found. Check configuration.
Fontconfig warning: adding /var/cache/fontconfig
Fontconfig warning: adding ~/.fontconfig

This is a simple fix...in fact it's telling you what to do in the warning text. The last two lines mention that you need to add those xml elements into your .fonts.conf file. It's erroring out because it doesn't really add them by itself but you can simply add them manually or run:

sed '
/<\/dir>$/{
N
s%\(</dir>\)\n*\(\s*<match\)%\1\n <cachedir>/var/cache/fontconfig</cachedir>\n <cachedir>~/\.fontconfig</cachedir>\n\2%
}' .fonts.conf

Tuesday, April 12, 2011

Using "find" to execute a command on files or folders...

The other day I was trying to make all the folders under a directory available for traversing for the owner group (chmod g+rx) but I couldn't get "find" with the "-exec" switch to work. I had installed Eclipse manually and since my umask is 077 it was not letting me access it since root was the owner. I changed the owner group to users and added +r for the group on all files but of course that is not enough for folders. I figured I would use find to get me all the folders and use -exec switch to change the permissions. So I had:

sudo find -type d -exec chmod go+rx '{}'\;

which kept giving me an error message:

find: missing argument to `-exec'

What?! I have all the right arguments, I read the man pages, looked online, tried info looking for samples. It was all there...well not quite, it seems you need to make sure there is a space between the last tick mark (') and the backslash (\).i.e.:

sudo find -type d -exec chmod go+rx '{}' \;

Wednesday, March 16, 2011

How to add Ruby syntax highlighting in emacs

I recently had to look at some exceptions from a headless server and it was outputting errors from some ruby code. I just wanted to take a quick look at the code without downloading the file to my machine or use vnc and a graphical editor but I still wanted syntax highlighting.

I decided to install emacs and add Ruby mode to the install. Luckily I found out how from reading these two posts:
Ubuntu and Windows

It comes down to this:
  • emacs 23+ already loads it by default.
  • For emacs 22+ you need to download and move to the right directory an ".el" file then change/create your ~/.emacs file to load Ruby-mode when opening Ruby files.

mkdir downloads
cd downloads/
wget http://svn.ruby-lang.org/repos/ruby/tags/v1_9_2_0/misc/ruby-mode.el
wget http://svn.ruby-lang.org/repos/ruby/tags/v1_9_2_0/misc/ruby-electric.el
wget http://perso.tls.cena.fr/~boubaker/distrib/mode-compile.el
mv *.* /usr/local/share/emacs/site-lisp/
cat >> ~/.emacs <<"END_OF_FILE"
; loads ruby mode when a .rb file is opened.
(autoload 'ruby-mode "ruby-mode" "Major mode for editing ruby scripts." t)
(setq auto-mode-alist  (cons '(".rb$" . ruby-mode) auto-mode-alist))

; adds tabify and indentation
(add-hook 'ruby-mode-hook
      (lambda()
        (add-hook 'local-write-file-hooks
                  '(lambda()
                     (save-excursion
                       (untabify (point-min) (point-max))
                       (delete-trailing-whitespace)
                       )))
        (set (make-local-variable 'indent-tabs-mode) 'nil)
        (set (make-local-variable 'tab-width) 2)
        (imenu-add-to-menubar "IMENU")
        (define-key ruby-mode-map "\C-m" 'newline-and-indent) ;Not sure if this line is 100% right!
        (require 'ruby-electric)
        (ruby-electric-mode t)
        ))

; Install mode-compile to give friendlier compiling support!
(autoload 'mode-compile "mode-compile" "Command to compile current buffer file based on the major mode" t)
 (global-set-key "\C-cc" 'mode-compile)
(autoload 'mode-compile-kill "mode-compile" "Command to kill a compilation launched by `mode-compile'" t)
 (global-set-key "\C-ck" 'mode-compile-kill)
END_OF_FILE


Note: You dont have to move the files to the emacs directory, simply move them to your ~/.emacs.d/ folder and add the following to your ~/.emacs file at the top:
(add-to-list 'load-path "~/.emacs.d/")
I also added the code to tabify/indent and one more snippet for quick compiling. If you don't want to add those features then only download the first ".el" file and remove or don't add the last two pieces to your ~/.emacs file.

Enjoy,

Marlon