BigVideo.js - The jQuery Plugin for Big Background Video
This plugin makes it easy to add fit-to-fill background video to websites. It can play silent ambient background video (or series of videos). Or use it as a player to show video playlist. BigVideo.js can also show big background images, which is nice to have for showing big background images for devices that don’t have autoplay for ambient video.
Highlight current navigation item with Staticmatic
StaticMatic is a nice tool to build simple static websites.
In case you want to have some nifty styles on the navigation item that is currently active, you can use this:
=link 'Aktuelles', :class => (current_page =~ /aktuelles/) ? 'current' : 'default'
Keep in mind that current_page
gives you the full relative path of your page. raise
current_path in case you're not sure.
I know there is an navigation helper out there. I did not use it and also did not want to migrate.
"command not found" bash function
If you type a command in your bash that doesn't exist you get this:
bash: foo: command not found
or if you have installed the command-not-found
package on ubuntu/debian:
The program 'foo' can be found in the following packages:
* foobar
* barfoo
Try: sudo apt-get install <selected package>
-bash: foo: command not found
But you can customize this with the command_not_found_handle
function which you can add to your .bashrc
.
This is something I've tried:
function command_not_found_handle {
ssh $...
See which MySQL database is currently in use
When you work in the MySQL console and you want to see which database is used, type:
SELECT database();
The result you see is the database you would activate with
USE database_name;
Test meta-refresh redirects with Cucumber
The step definition below allows you to write:
Then I should see an HTML redirect to "http://www.makandracards.com" in the page head
Capybara
Then /^I should see an HTML redirect to "([^\"]*)" in the page head$/ do |redirect_url|
page.should have_xpath("//meta[@http-equiv=\"refresh\" and contains(@content, \"#{redirect_url}\")]")
end
To find meta
tags with Capybara, you can also use page.find('meta', visible: false)
.
Fix error: Invalid gemspec / Illformed requirement
When you get an error like this:
Invalid gemspec in [/opt/www/foo-project.makandra.de/shared/bundle/ruby/1.8/specifications/carrierwave-0.6.2.gemspec]: Illformed requirement ["#<YAML::Syck::DefaultKey:0x7fda6f84d2e8> 1.1.4"]
... the machine's Rubygems needs to be updated.
If that happens on your local machine
- Manually remove the offending's gem files and specifications. The paths will be something like
/usr/lib/ruby/gems/1.8/gems/your-broken-gem
and `/usr/lib/ruby/gems/1.8/specificatio...
Manage ssh keys with Keychain
Keychain helps you to manage ssh and GPG keys in a convenient and secure manner. It acts as a frontend to ssh-agent and ssh add, but allows you to easily have one long running ssh-agent process per system, rather than the norm of one ssh-agent per login session.
This dramatically reduces the number of times you need to enter your passphrase. With keychain, you only need to enter a passphrase once every time your local machine is rebooted. Keychain also makes it easy for remote cron jobs to securely "hook in" to a long running ssh-agent p...
Meny - A three dimensional and space efficient menu concept
Stuff like this is now possible in Webkit browsers, Firefox and IE10.
Updated: Unobtrusive jQuery to toggle visibility with selects and checkboxes
Now works with radio buttons.
Paperclip: Move attachements from local storage to AWS S3
We frequently use the handy Paperclip Gem to manage file attachments.
If you need to move the files from local storage (i.e., your servers' harddisk) to Amazon S3, you can simply change settings for Paperclip to use the S3 storage adapter and use this script to migrate to S3. Put the snippet into a chore if you don't want to run that in the console.
YOUR_LOCAL_STORAGE_MODEL_DIRECTORY should be something like 'storage/your_model'.
Dir.glob(YOUR_LOCAL_STORAGE_MODEL_DIRECTORY**/*).each do |path|...
"rake gettext:findpo" running forever
Under certain circumstances gettext_i18n_rails
will hit a near-infinite loop. This occured in Rails 2.3.5 with Haml 3.0.18 and fast_gettext 0.5.10.
gettext_i18n_rails
's Haml-Parser compiles the Haml code and delegates the parsing to ruby_parser
. Unfortunately, ruby_parser
appears to be confused when a string contains both escaped chars (that is, any unicode characters as ndash, umlauts etc.) and #{}
blocks, which makes it extremely slow.
The easiest "solution" we came up with was to replace all occurrences of UTF-8 chars wi...
Evening on Backbone.js/Views w/ Q&A with David Heinemeier Hansson - YouTube
Interesting interview with DHH, where he talks about how they made the new Basecamp feel very fast without using a lot of Javascript (most of Basecamp still lives on the server). The two tricks they used are PJAX and Russian Doll Caching.
defunkt/jquery-pjax
pjax loads HTML from your server into the current page without a full reload. It's ajax with real permalinks, page titles, and a working back button that fully degrades.
pjax enhances the browsing experience - nothing more.
Beware of magic adblocker rules
If a customer calls and tells you that she cannot see some content of her website beware of the following before starting tcpdump
or other forensic debugging tools.
Some ad blockers like Adblock are shipped with filters that remove (amongst others)
-
divs
named'sponsor'
- images with a class
"banner"
or the filename"banner.png"
- images from directories named
'sponsor*'
- Image names or class names that begin with
adv_...
.
Renaming the div
to something more specific to your site and renaming...
How to fix gsub on SafeBuffer objects
If you have an html_safe
string, you won't be able to call gsub
with a block and match reference variables like $1
. They will be nil
inside the block where you define replacements (as you already know).
This issue applies to both Rails 2 (with rails_xss
) as well as Rails 3 applications.
Here is a fix to SafeBuffer#gsub
. Note that it will only fix the $1
behavior, not give you a safe string in the end (see below).
Example
def test(input)...
Hack of the day: Find all classes that define a method with a given name
If (for some reason that you don't want to ask yourself) you need to know all classes that define a method with a given name, you can do it like this:
def classes_defining_method(method_name)
method_name = method_name.to_sym
ObjectSpace.each_object(Module).select do |mod|
instance_methods = mod.instance_methods.map(&:to_sym) # strings in old Rubies, symbols in new Rubies
(instance_methods & [method_name]).any? && mod.instance_method(method_name).owner == mod
end
end
So, when we want to know all...
Boolean fields in migrations
If you want to update some records with boolean fields in a migration, always remember to set your values with field=#{quoted_true}
and field=#{quoted_false}
. The Rails methods quoted_false
and quoted_true
return the correct boolean representations for your database.
How to deal with strange errors from WEBrick
If you get errors from your development WEBrick that contain unicode salad, you are probably requesting the page via SSL. \
Since WEBrick does not speak SSL, so change the URL in your browser to use http
instead of https
.
The error looked like this for me:
[2012-09-06 11:19:07] ERROR bad URI `\000\026\000\020\000'.
[2012-09-06 11:19:07] ERROR bad URI `\000\026\000\020\000'.
[2012-09-06 11:19:07] ERROR bad Request-Line `\026\003\001\000�\001\000\000\177\003\001PHj�\031\006�L��'.
[2012-09-06 11:19:07] ERROR bad URI `\000\026\000\...
How to test print stylesheets with Cucumber and Capybara
A print stylesheet is easy to create. Choose a font suited for paper, hide some elements, done. Unfortunately print stylesheets often break as the application is developed further, because they are quickly forgotten and nobody bothers to check if their change breaks the print stylesheet.
This card describes how to write a simple Cucumber feature that tests some aspects of a print stylesheets. This way, the requirement of having a print stylesheet is manifested in your tests and cannot be inadvertedly removed from the code. Note that you can...
Reset mysql root password
This article describes how to reset MySQL's or MariaDB's root password on your workstation. It's meant for local development purposes only, don't do this in production. This article will also help you if you have a fairly recent MariaDB version that uses authentication based on linux users instead of passwords for the root user and you prefer using a password for root.
Solution
Step 1 is getting a root mysql shell that allows us to change user credentials. We need to stop the mysql
daemon first and re-start it without authorization c...
Be careful when using Unicode symbols for graphical elements
There are many fun Unicode characters like ▲ or ☯. You might be tempted to use them for graphical elements in lieu for an image. After all they are so much easier to style and scale than a raster image!
Unfortunately you will discover that these symbols render very differently on Linux, Windows and MacOS. The reason for this is that the font you are using will probably not contain any characters outside the standard Latin-1 set. When browsers encounter a character not included in the current font, they use a fallback font for this one cha...
Flat Icons & Icon Fonts | CSS-Tricks
Nice list of icon sets that come in the form of fonts.
I recommend Font Awesome.
How to install GNOME classic desktop in ubuntu 12.04
Run
sudo apt-get install gnome-session-fallback
or (alias)
sudo apt-get install gnome-panel
from a terminal.
Then logout to reach the logon screen and click on the options button next to you name.
Select Gnome Classic
, log in et voilà.
RSpec and Cucumber: Shorthand syntax to run multiple line numbers in the same file
This works in modern RSpecs (RSpec >= 2.x) and Cucumbers:
rspec spec/models/node_spec.rb:294:322
cucumber features/nodes.feature:543:563:579
Also your features should be shorter than that :)