Auto-hide player controls in the default Flash video player component
If you find yourself working in the Adobe Flash IDE you're already doing it wrong, but maybe the hour is late and your standards for success are slipping. Anyway here is how to hide the controls in the default Flash video player component:
- Select the player frame on the stage.
- Open the component inspector by selecting
Window -> Component Inspector
or clicking a funny unlabeled icon in the player properties. - Set the
skinAutoHide
property totrue
.
Test that a select field contains an option with Cucumber
This note describes a Cucumber step definition that lets you say:
Then "Mow lawn" should be an option for "Activity"
But "Reply support mail" should not be an option for "Activity"
Note that this step checks whether an option is available, not that it is selected. There is a separate step to test that an option is selected.
Capybara (0.4.1 or higher)
Then /^"([^"]*)" should( not)? be an option for "([^"]*)"(?: within "([^\...
Fix errors when rendering PDF output
If you run specs or your application and get an error like:
ActionController::MissingFile in 'ProductsController#show, should render PDF'
Cannot read file /some/file.pdf
You may be missing the HTMLDOC binary on your system. Install it like this on Debian/Ubuntu:
sudo apt-get install htmldoc
Show the name and version of your Linux distribution
To list the name and version of your Linux distribution, type the following:
cat /etc/*-release
hyphenator
Javascript that implements client-side hyphenation of HTML-Documents.
remove_index fails silently for non-existing indexes in Rails 2 migrations
When you try to remove a non-existing index using remove_index
, the migration will incorrectly pass without an error. The schema will not be changed, but the migration will be considered migrated.
Since this might be fixed in the future, you cannot mend your database by adding another migration on top of the faulty one. You should manually alter the database schema to the previous migration on all machines that migrated the faulty migration (inform your fellow developers), then delete the faulty migration from the repository.
The Case Against Queues
Some people, when confronted with a problem, think "I know, I'll use a queue." Now they have an unbounded number of problems.
Networked message queues like ActiveMQ, RabbitMQ, ZeroMQ, and a host of other Java inspired software tumors are crutches of systems design. I love asynchronous stuff as much as the next guy, but think of a queue like Java: it encourages large swaths of mediocre programmers to overengineer shit, and it keeps systems administrators in business by giving them something to respond to at 4AM.
Here is some of th...
Using Firebug Lite to inspect HTML in Internet Explorer and other browsers
You know Firebug as a Firefox extension but there is also a "Lite" version which runs purely off JavaScript.
Though all major browsers offer inspection tools you may like the Firebug style. Also, for me this is a lot better than the IE8 developer tools -- and it works in older versions of IE, too.
Get the bookmarklet over at http://getfirebug.com/firebuglite#Stable. It usually loads the JavaScript code from a remote server but you can also download it to have it run locally. If adding the bookmarklet does not work in IE, add a new book...
babushka: test-driven sysadmin
The idea is this: you take a job that you'd rather not do manually, and describe it to babushka using its DSL. The way it works, babushka not only knows how to accomplish each part of the job, it also knows how to check if each part is already done. You're teaching babushka to achieve an end goal with whatever runtime conditions you throw at it, not just to perform the task that would get you there from the very start.
OscarGodson/jKey - GitHub
jQuery plugin to register callback functions to keyboard shortkuts. Keyboard events in vanilla Javascripts are super-painful to work with, so hopefully this library can help.
The Difference Between jQuery’s .bind(), .live(), and .delegate()
The difference between .bind(), .live(), and .delegate() is not always apparent. Having a clear understanding of all the differences, though, will help us write more concise code and prevent bugs from popping up in our interactive applications.
Calling selected methods of a module from another module
Given those modules:
module A
def foo; end
def bar; end
end
module B
end
When you want to call methods from A
inside B
you would normally just include A
into B
:
module B
include A
end
Including exposes all of A
's methods into B
. If you do not want this to happen, use Ruby's module_function
: it makes a module's method accessible from the outside. You could put the module_function
calls into A
but it would remain unclear to peop...
Split an array into groups
Given group size
If you would like to split a Ruby array into pairs of two, you can use the Rails ActiveSupport method in_groups_of:
>> [1, 2, 3, 4].in_groups_of(2)
=> [[1, 2], [3, 4]]
>> [1, 2, 3, 4, 5].in_groups_of(2)
=> [[1, 2], [3, 4], [5, nil]]
>> [1, 2, 3, 4, 5].in_groups_of(2, 'abc')
=> [[1, 2], [3, 4], [5, 'abc']]
>> [1, 2, 3, 4, 5].in_groups_of(2, false)
=> [[1, 2], [3, 4], [5]]
Given group cou...
Freeze (vendor, unpack) a single Ruby gem with and without Bundler
When you need to patch an existing gem, one way is to "vendor" the gem by copying it into the vendor/gems
directory of your Rails project. You can then make any changes you require and Rails will use the vendored version of the gem after a server restart. Unfortunately you need to perform some additional steps to marry Rails and the copied gem. This notes describes what to do.
With Bundler
This is super-painful. If you just copy the gem to vendor/gems
, Rails will complain:
Unpacked gem foolib in vendor/gems has no s...
MySQL: "LOAD DATA INFILE" says "file not found"
This might be due to AppArmor denying the MySQL server access to most of the filesystem. You can instead use
LOAD DATA LOCAL INFILE ...
to pipe data through the MySQL client, which can read everything the executing user can.
Properly sanitizing column names for MySQL
There are times when you need to send SQL to the database, like this:
def self.some_count(field)
field = connection.quote_column_name(field)
scoped(:select => "COUNT(DISTINCT #{field}) AS count")
end
Although the given variable is sanitized here, the MySQLAdapter's (and probably other adapters as well) method for this is insufficient as it only wraps backticks around it, not helping against injection:
Klass.some_count("id`); DELETE FROM users; -- ")
# Will result in this SQL which is valid but definitely undesi...
Test the status code of a response in Cucumber
Webrat
Then /^I should get a response with status (\d+)$/ do |status|
response.status.should include(status)
end
Capybara
Then /^I should get a response with status (\d+)$/ do |status|
page.status_code.should include(status.to_i)
end
Perform HTTP basic authentication in Cucumber (with or without Selenium)
This card describes a Cucumber step that lets you say:
When I perform basic authentication as "username/password" and I visit the admin area
The path component ("... the admin area") is parsed through your path_to
helper in features/support/paths.rb
.
Capybara
The step definition is part of Spreewald. The step has been tested with multiple versions of Capybara, Rack::Test and Selenium.
Webrat (legacy)
This is a simpler version of the step above:
When /...
Access the documentation of all locally installed gems
In case https://www.rubydoc.info/ is to slow or offline, you can also read a gem documentation offline.
Start a server with gem server
and go to http://0.0.0.0:8808/
. Here you will find a list of all installed gems and it is possible to navigate to the documentation if installed e.g. http://0.0.0.0:8808/doc_root/rubocop-0.77.0/
In case you set the configured RubyGems to not install documentation by default, you need to add generate the documentation for the specific gem.
gem install rubocop --document
`...
ETags with memcached
I love ETags, but there’s something that annoys me: most implementations revolve around pulling a record out of a data store and only “rendering” the response if it hasn’t been modified.
The problem with this approach is that request has already gone through most of your application stack–parsing params, authentication, authorization, a few database lookups–so ETags are only saving you render time and some bandwidth.
While working on a Sinatra-based JSON web service that gets very heavy traffic, I wanted to find a way to short-circuit...
Always show the page if there is an error in Cucumber
Are you adding a "Then show me the page
" and re-run Cucumber whenever there is a failing scenario? Don't be that guy!
Save time with the shiny new version of our cucumber_spinner gem. It comes with a Cucumber formatter that not only displays an awesome progress bar, and shows failing scenarios immediately, it will also open the current page in your browser whenever a scenario step fails.
After you installed the gem, use the formatter like this:
cucumber --format CucumberSpinner::Curiou...
In-depth HTTP traffic analysis using tcpdump & Wireshark
From time to time we're convinced that an error must be very close to the network card, OS IP stack or compiler. In reality this is quite rare, so before continuing, triple-check that the issue is not located between chair and keyboard...
If you're still convinced that a in-depth analysis of network traffic might help you, go on:
-
Find out the IP address the client causing trouble will come from.
-
Replace 147.0.0.123 with the client address, log into your web server and run:
`remote$ sudo tcpdump host 147.0.0.123 and port 80 -s 0 -w...
Allow a user to run a single command with root privileges
It's that simple to allow one of your Linux users to run a single command as UID 0:
sudo visudo
- Add the line below to allow user 'deploy' to run
/usr/bin/bundle
with root privileges
deploy ALL=NOPASSWD: /usr/bin/bundle
How to fix "extconf.rb:8:in `require': no such file to load -- mkmf (LoadError)"
If you're on Ubuntu:
sudo apt-get install ruby-dev
On other platforms: Look for a package containing ruby header files. On Red Hat that's "ruby-devel" likely.