How to change the hostname in Cucumber features
Capybara uses www.example.com as the default hostname when making requests.
If your application does something specific on certain hostnames and you want to test this in a feature, you need to tell Capybara to assume a different host.
Given /^our host is "([^\"]+)"$/ do |host|
page.config.stub app_host: "http://#{host}"
# In older Capybaras (< 2.15) you needed to do this instead:
Capybara.stub app_host: "http://#{host}"
end
You can now say:
When I go to the start page
Then I should not see "Home ...
FreeBSD pkg can't find any packages
If you're trying to searching or installing packages via pkg the your repository data might be broken. If pkg update shows that your repositories are up to date try:
pkg update -f
Afterwards you should be able to search and install packages again.
Introducing Helix: Rust + Ruby, Without The Glue
Helix allows you to implement performance-critical code of your Ruby app in Rust, without requiring glue code to bridge between both languages.
See attached article for a longer write-up about the why and how.
How to preview an image before uploading it
When building a form with a file select field, you may want to offer your users a live preview before they upload the file to the server.
HTML5 via jQuery
Luckily, HTML5 has simple support for this. Just create an object URL and set it on an <img> tag's src attribute:
$('img').attr('src', URL.createObjectURL(this.files[0]))
Unpoly Compiler
As an Unpoly compiler, it looks like this:
up.compiler '[image_p...
rroblak/seed_dump
This gem gives you a rake task db:seed:dump do create a db/seeds.rb from your current database state.
The generated db/seeds.rb will look this:
Product.create!([
{ category_id: 1, description: "Long Sleeve Shirt", name: "Long Sleeve Shirt" },
{ category_id: 3, description: "Plain White Tee Shirt", name: "Plain T-Shirt" }
])
User.create!([
{ password: "123456", username: "test_1" },
{ password: "234567", username: "test_2" }
])
twitter responds with HTTP 401 for missing profiles
When your application crawls twitter profiles for tweets, it might throw HTTP 401 (Unauthorized) errors.
Those can happen for a number of reasons, one of them obviously being incorrect credentials.
However, 401 is also returned when crawling profiles that no longer exist.
True story.
How to use triple quotes inside a Cucumber docstring
Cucumber's docstrings let you add long strings to a step like this:
# foo.feature
Given this text:
"""
First line
Second line
Second Paragraph
"""
# foo_steps.rb
Given /^this text:$/ |docstring|
puts docstring.split
end
You see these neat triple double quotes ("""). Now what to do when you need your docstring to contain triple double quotes, too?
# Does not work:
Given this text:
"""
Docstrings work like this:
"""
Docstring example
"""
You see?
"""
Update: Official solution
You can escape the inner quotes ...
Install MySQL 5.6 in Ubuntu 16.04
Instead of using this hack you might want to use MariaDB 10.x which can work with both old and new apps.
An alternative could be to use the MySQL Docker image which is still updated for 5.6.
Ubuntu 16.04 only provides packages for MySQL 5.7 which has a range of backwards compatibility issues with code written against older MySQL versions.
Oracle maintains a list of official APT repositories for MySQL 5.6, but those repositories do...
Using Bumbler to Reduce Runtime Dependencies - The Lean Software Boutique
Tool to show you which gems are slow to load:
➜ git:(master) ✗ bundle exec bumbler
[################################################# ]
(49/65) travis-lint...
Slow requires:
110.21 render_anywhere
147.33 nokogiri
173.83 haml
179.62 sass-rails
205.04 delayed_job_active_record
286.76 rails
289.36 mail
291.98 capistrano
326.05 delayed_job
414.27 pry
852.13 salesforce_bulk_api
Caching best practices & max-age gotchas - JakeArchibald.com
Showing various caching patterns. Includes WhatsApp screenshots.
VCR: An OAuth-compatible request matcher
OAuth requires a set of params to be carried along requests, among which a nonce. Some libraries pass these along as headers, some as query parameters. All fine.
When you're using VCR, the latter case is an issue. By default, requests are matched on method and URI. However, no request URI will equal another when they include a nonce. You won't be able to match these requests with VCR.
Solution
Obviously you need to...
Running the Awesome window manager within MATE
Awesome is a very good tiling window manager that provides neat features like automatic layouting of windows, good multi-display support with per display workspaces and more. Since it is only a window manager, you will probably miss some of MATE's conveniences like the network manager, application menus, automatic updates etc.
Fortunately, you can run Awesome within MATE, by following these steps (tested on Ubuntu MATE 16.04):
Awesome + MATE
- Create the followi...
Top-level constants in BasicObject
If you want to access top-level constants inside a BasicObject class, you need to prefix them with ::.
This will not work
class Foo < BasicObject
def bar
Hash.new
end
end
Foo.new.bar # => NameError: uninitialized constant Foo::Hash
You need to explicitly write ::Hash.
The reason is that top-level constants are internally attached to Object, so Hash is not in the lookup chain inside a BasicObject.
Postgres Index Types
When creating an index using
CREATE INDEX, Postgres will create a B-Tree type index by default. The B-Tree type is great for general purpose indexes but there are special cases when other types provide better results.
Test e-mail dispatch in Cucumber
Spreewald has steps that let you test that e-mails have been sent, using arbitrary conditions in any combination.
The attached file is for legacy purposes only.
Reading and writing cookies in JavaScript
You can use JavaScript to get or set cookie values on the client.
Using the vanilla JavaScript API
In JavaScript, document.cookie is an accessor to all cookies on the current site. It looks like a String, but its setter is actually more powerful.
When setting cookies this way, remember to set the path=/ option.
Reading cookies
A result may look like this:
hello=universe; foo=bar
This means that there are 2 cookies: "hello" with value "universe", and "foo" with value "bar...
An interactive Git shell
Git commands tend to come in groups. Avoid typing git over and over and over by running them in a dedicated git shell.
You might want to run git config --global help.autocorrect true before using gitsh. This will silently swallow a muscle-memory "git" prefix to your commands inside the git shell.
How to fix: HTML5 video not working in IE9
While IE9 does support HTML5 <video> tags, it fails to work until you force HTML5 mode.
Here are two ways to do that.
Option 1: Doctype
Make sure your HTML document uses HTML5. It should start like this:
<!DOCTYPE html>
Option 2: Magic meta tag
If you can not set a doctype, you use the X-UA-Compatible meta tag in your HTML <head>.
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
Infinitely nested hashes in Javascript (Coffeescript)
The NestedHash class allows you to read and write hashes of any depth. Examples:
hash = {}
NestedHash.write hash, 'a', 'b', 'c', 'value' # => { a: { b: { c: 'value' } } }
NestedHash.read hash, 'a', 'b', 'c' # => 'value'
NestedHash.read hash, 'a' # => { b: { c: 'value' } }
NestedHash.read hash, 'foo', 'bar' # => undefined
Inspired by victusfate.
Code
class @NestedHash
@read: (objekt, keys...) ->
if objekt and keys.length
@read objekt[keys[0]], keys[1...]...
...
MySQL / MariaDB: Show disk usage of tables and columns
You can find out about disk space usage of all tables within your database by running this:
SELECT table_name AS `Table`, round(((data_length + index_length) / 1024 / 1024), 2) `Size (MB)` FROM information_schema.TABLES WHERE table_schema = "$your_database";
Replace $your_database here.
To find out the disk usage of a single column:
SELECT sum(char_length($your_column))/1024/1024 FROM $your_table
Result is in megabytes again.
Ever wanted man pages that actually help? Here you go
Enter any command into explainshell and it will explain it to you: split into separate commands (if present), with each option explained.
About
Hello,
This site contains 29761 parsed manpages from sections 1 and 8 found in Ubuntu's manpage repository. A lot of heuristics were used to extract the arguments of each program, and there are errors here and there, especially in manpages that have a non-standard layout.
It is written in Python and uses bashlex, a bit of NLTK (to find the interesting parts of the manpage), a little d3....
Git: Delete a branch (local or remote)
To delete a local branch
git branch -d the_local_branch
To remove a remote branch (if you know what you are doing!)
git push origin :the_remote_branch
or simply use the new syntax (v1.7.0)
git push origin --delete the_remote_branch
Note
If you get the error
error: unable to push to unqualified destination: the_remote_branch
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.
error: failed to push some ref...
Analyse short links
Sometimes you might want to check a short link for it's destination before clicking on it. Additional you get information about the redirects.
Use the magic + at the end of the short url!
Google:
https://goo.gl/TXe0Kx => https://goo.gl/TXe0Kx+
Since the original publication of this post, Google's URL shortening service goo.gl has been discontinued.
Bitly:
http://bit.ly/1VRwNVt => [http://bit.ly/1VRwNVt+](http:/...