Linux: How to add a task bar to VNC displays
If you are using VNC to run Selenium tests, it may be hard to see what's going on since by default there is no list of open windows and Alt
+Tab
won't work.
Solving that is easy:
-
Install a panel of your choice (like lxpanel) which offers task switching:
sudo apt-get install lxpanel
(You can't use
gnome-panel
because it won't start twice -- but lxpanel does a good job) -
To have that panel appear on VNC screens by default, edit
~/.vnc/xstartup
...
IE-friendly mobile-first CSS with Sass 3.2
Building CSS mobile-first is the way forward, because blah blah blah progressive enhancement blah. Problem is, Internet Explorer prior to 9 ignores anything within media query blocks, leaving those browsers with mobile styles.
Not all of us can get away with that, but thankfully, as Chris Eppstein points out, Sass 3.2 (not yet released) can generate a separate stylesheet with everything it needs to create a "desktop" look.
This page was built mobile-first where smaller width devices get a single column layout, but IE8 and below still get a...
Visualized introduction how git works
Quick introduction to git internals for people who are not scared by words like Directed Acyclic Graph.
The linked page offers a simple yet concise explanation of how git is organized internally ('a directed acyclic graph with post-it notes'). Each feature is illustrated by a simple diagram, so you get a sound understanding of how each command affects git's structure.
Match a string with wildcards
The following snippet will convert a string with wildcards to a appropriate regexp, i.e.
parse_wildcards("foobar") # => /\Afoo.bar\z/
parse_wildcards("") # => /\A.\z/
parse_wildcards("[") # => /\A[\z/
^
def parse_wildcards(string)
matching_parts = string.split('', -1).collect { |part| Regexp.escape(part) }
/\A#{matching_parts.join(".")}\z/
end
How could it be that my database.yml disappears?
Probably was in the repository once and got deleted in a commit that you pulled.
When the iPad won't play an MP4 video
I had trouble serving an MP4 video to my iPad. Although the video complied with all the specs (H.264 codec, up to 1080p, 30 FPS) I always got this error:
This video could not be loaded, either because the server or network failed or because the format is not supported: http://10.40.0.177:3000/video.mp4
After spending a lot of time fighting this issue, I tried to upload the same unchanged video file to a production server (Apache / Passenger). It worked immediately. I guess iOS is picky about some HTTP header that my local HTTP server (Th...
Random numbers in Ruby
A collection of snippets to generate random number under certain conditions, as:
- gaussian
- with a specified distribution
- triangular distribution
- ... and some more
Plotting graphs in Ruby with Gruff
Geoffrey Grosenbach has created Gruff for easily plotting graphs. It is written in pure Ruby and integrates with Rails applications.
It provides features as automatic sizing of dots and lines (the more values, the thinner the graph's elements), custom or predefined themes, different styles (bar, line, dot and many more) and multiple graphs in one chart.
Installation
In your Gemfile:
gem 'rmagick', :require => false
gem 'gruff'
Then run bundle install
(and don't forget to restart your development server.)
Usage
This i...
Mysterious "margin" below an image
Consider the following HTML & CSS:
<div><img src='http://makandra.com/images/makandra-ruby-on-rails.png' /></div>
^
img {
background-color: red;
}
div {
border: 1px solid black;
}
This will leave a margin of about 5px between the lower edge of the image and the containing div, although there are no paddings or margins set, and there's no whitespace. The reason is, the image will vertically align baseline
, and the space below the image is just kept for descenders (the part of letters below the basel...
Gimp: Why removing pixels sometimes leaves transparency, sometimes the background color
- You might have notices this behavior when you cut a selection or use the rubber tool.
- The behavior depends on whether your images has an alpha channel.
- You can add an alpha channel by choosing Layer → Transparency → Add alpha channel
Use different CSS depending on whether elements render on the same line or multiple lines
You will find this useful when creating responsive designs that work well on small screens.
The attached Javascript gives a container different CSS classes (single_line
or multiple_lines
) depending on whether its children render on one line or multiple lines.
Initialize it with the selectors for container and children:
$(function() {
$('.navigation').countLines('a');
});
You can now use different CSS styles like this:
.navigation
&.single_line a
// styles when all anchors are rendered on the same line...
RubyMine: Set specific Ruby version per project
If your project uses another version than your default Ruby, RubyMine will give you incorrect inspections, for example.\
Here is how to switch which Ruby you use in RubyMine.
- File → Settings (Or press
Ctrl+Alt+S
) - Select "Ruby SDK and Gems" from the left pane
- Switch your "Ruby interpreter".
Though it may seem you are changing a global setting here, this is in fact a per-project setting, as are all things you change in the "Project Settings [your_project_name]" area of the global settings dialog.
When you switch to another proje...
Compress bitmap images within PDF files
Embedding bitmap images within PDF sometimes results in large files because the bitmaps are not compressed. If you don't need high quality images within the resulting PDF file, you can use ghostscript to compress embedded images:
ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new-smaller-file.pdf large-original-file.pdf
Note that your PDF printer (or similiar generation tools) also often come with a compression setting for embedded raster images.
You can put this ...
Sync confidential files between unixes using cloud storage and encfs
Note: You might also want to check out BoxCryptor which does pretty much the same, and is supported across many more platforms. I just didn't want to use Dropbox...
I use Ubuntu One to automatically sync confidential files between my machines. The encryption is done via encfs, which is a file-based encryption that simply puts encrypted versions of files from one folder into another. This is well-suited for cloud storage, since it allows syncing single files, not whole crypt containers.
Recipe
I'll ass...
Fix capistrano errors: "no such file to load -- net/ssh/authentication/agent/socket" or "uninitialized constant Net::SSH::KnownHosts::SUPPORTED_TYPE"
There is a conflict between current capistrano versions and the 2.5.1 net-ssh gem. Make sure you upgrade to 2.5.2, then it should work again.
MySQL 5.1: Switch to InnoDB Plugin for better performance
MySQL version 5.1 comes with an alternative, faster InnoDB implementation (called "InnoDB Plugin").
Switching is easy:
- Stop your mysqld with
sudo stop mysql
- Add the following lines to your
/etc/mysql/my.cnf
under the[mysqld]
section
ignore-builtin-innodb
plugin-load=innodb=ha_innodb_plugin.so - Start your mysqld with
sudo start mysql
The file format has not changed, your tables should survive this.
Note: This is not necessary in MySQL 5.5, where the new implementation is the default.
Removing white space after links in HAML
TL;DR
%p
#{link_to "label", "url"}!
Haml is a great engine for writing shorter, readable HTML. However, there is one thing that troubles me regularly. Consider this Haml code:
%p
Visit our homepage at
= link_to "www.makandra.com", "http://www.makandra.com"
!
Haml will insert a space around the generated link, the result is this (see the space before the exclamation mark!):
<p>
Visit our website at <a href="http://www.makandra.com">www.makandra.com</a> !
</p>
They suggest to us...
Howto properly use vertical-align to align elements vertically
Say you want to vertically align a div
box inside a div
container. This is how you do it:
HTML
<div id="container">
<div class="box">
<span> Some text...<br />in two lines. </span>
</div>
</div>
CSS
Set the line-height to the container's (implicit) height. The container MUST have a height >= its line-height, because the line-height actually spans the area inside which .box will align vertically.
#container {
line-height: 50px;
}
Because the container's line-height is inherited by .box,...
When using time zones, beginning_of_day / end_of_day is broken in Rails 2 for any Date or DateTime
Using beginning_of_day
or end_of_day
on Date
or DateTime
objects in Rails 2.x applications will never respect time zones, which is horrible.\
This is fixed in Rails 3, though.
Even when using Date.current
or DateTime.current
you will get regular Time
or DateTime
objects:
>> Date.current.beginning_of_day.class
=> Time # not a ActiveSupport::TimeWithZone as expected
>> DateTime.current.beginning_of_day.class
=> DateTime ...
Rails 3 routing: Be careful with matching routes *including their format*
Today, this line made me trouble. Can you spot the mistake?
match 'sitemap.xml' => 'feeds#sitemap', :constraints => { :format => 'xml' }, :as => 'sitemap'
The mistake is to match sitemap.xml
. Rails will by default strip any dot-anything, remember it as desired format and forward the rest of the request to the routing engine. Since we're making .xml
part of the match, it is not available for format determination and Rails will set the format to html
.
Unfortunately, the constraint won't complain in this case and Rails even ren...
Get Rid of That Code Smell – Duplication
Removing duplication from the code is a seemingly easy task. In many cases it is pretty straight-forward – you look at similar bits of code and you move them to a common method or class that is reusable in other places. Right? No, not really. It is true that code that looks similar might be an indicator that there’s a duplication but it’s not the definitive way of determining the smell.
If we look for duplication in our code we should look for duplicated concepts instead of similarly looking lines of code.
Aspect Oriented Programming in Ruby
Slides presenting ways to integrate the ideas of Aspect-Oriented Programming in Ruby.
Outline
- Why Aspect-Oriented Programming?
- AOP in Java and AspectJ (a Review).
- AOP in Ruby.
- What you can do today.
- Example AOP-isms in Ruby on Rails.
- Aspect-Oriented Design.
- The AOP Promise for Tomorrow.