MySql lost connection trouble
Directly from the MySql docs:
There are three likely causes for this error message.
Usually it indicates network connectivity trouble and you should check the condition of your network if this error occurs frequently. If the error message includes during query, this is probably the case you are experiencing.
Sometimes the during query form happens when millions of rows are being sent as part of one or more queries. If you know that this is happening, you should try increasing net_read_timeout from its default of 30 seconds to 60 s...
Memcache: Your cache node may degenerate over time, check your settings
We recently had a problem on a Memcache cluster, where one of the servers showed a significantly worse cache hit rate and a lot more evictions.
It turned out that the only reason was that the server was running for a few months longer than the others. Some investigation showed this to be a known problem with Memcache: Once your cache gets full, it might be "hardwired" for your specific usage patterns. If those change (and you for example start to store larger values), memory is no longer allocated optimally, in extreme cases Memcache might ...
Announcing YARD 0.6.0 (gnuu.org)
YARD 0.6 adds the ability to serve documentation for gems as well as the current project with yard server. Just like gem server in RubyGems, you can serve gem docs. The advantage to YARD’s server is that you don’t need to pre-generate the static docs (with a gem install) before running the server. If you installed your gem with --no-rdoc, YARD will just generate it on the fly!
How to: Apache logs on a daily basis without logrotate
If you want to have a new log file every day automatically, but avoid using logrotate
, the CustomLog
directive is your friend:
CustomLog "|/usr/sbin/rotatelogs /opt/www/awesome-project/log/access.%Y-%m-%d.log 86400" combined
Adding that to your site's vhost will create log files that include the current date in their name, like access.2011-04-20.log
, without any need to restart the web server every night (like logrotate
does).
The last argument above is the rotation time in seconds -- here being 86400 (= 60 * 60 * 24) which ca...
Geordi 6.0.0 released
6.0.0 2021-06-02
Compatible changes
-
geordi commit
will continue even if one of the given projects is inaccessible. It will only fail if no stories could be found at all.
Breaking changes
- Removed VNC test browser support for integration tests – Headless Chrome has
matured and is almost a drop-in replacement. Also, key binding issues have
increased with VNC and recent Linux.- Please use a headless Chrome setup https://makandracards.com/makandra/492109-capybara-running-tests-with-headless-chrome.
- You might also ...
Defining host aliases in your SSH config
You probably already manage servers you often connect to inside the ~/.ssh/config
file. What is nice: you may define alias names for hosts so that you can say something like ssh foobar-staging
.
This is especially helpful for servers whose hostnames are hard to remember or who don't have a DNS record at all (and must be accessed via their IP address).
To achieve the above, you can define something like this in your ~/.ssh/config
:
Host foobar-staging
Hostname staging.example.com
Note that SSH will only match this for `ssh f...
Giving a presentation with a dual screen layout on linux
When giving a presentation with a projector it is sometimes better to use a dual screen layout instead of a cloned display. If you still want a preview of the projector screen on your primary screen, you can do this:
-
Install
x11vnc
and a vnc viewer (e.g.xtightvncviewer
). -
Connect the projector.
-
In your system display settings, move the projector to the left or your primary screen (not strictly necessary, but I had weird clipping issues otherwise).
-
Start a vnc server for your second display with
x11vnc -clip xinera...
Resolving Angular not updating an image src when ng-src is empty
The Angular ngSrc
directive serves to properly set an image src
via Angular. As anything in Angular, it updates the image as soon as the contained Angular expression changes. However, when the ng-src
attribute is empty, Angular will not empty the src
attribute. To overcome this, use the trick below.
<img ng-src="{{ element.image || '//:0' }}" />
Background
The ngSrc
directive explicitly returns when the attribute value is falsy. As a workaround, set a "blank" image src when the image is empty. As [somebody ...
How to use cookies with curl
When making requests using curl, no cookies are sent or stored by default.
However, you can tell curl to re-use cookies received earlier (or forge your own cookies).
There are 2 command line switches you need to use:
-
-c
will write cookies to a given file -
-b
will read cookies from a given file
Example
The remote server sets a "foo" cookie to value "bar". We tell curl to store them to a file at /tmp/cookies
using the -c
switch.
$ curl -c /tmp/cookies http://httpbin.org/cookies/set?foo=bar
You may look at the file, ...
Use the "retry" keyword to process a piece of Ruby code again.
Imagine you have a piece of code that tries to send a request to a remote server. Now the server is temporarily not available and raises an exception. In order to re-send the request you could use the following snippet:
def remote_request
begin
response = RestClient.get my_request_url
rescue RestClient::ResourceNotFound => error
@retries ||= 0
if @retries < @max_retries
@retries += 1
retry
else
raise error
end
end
response
end
This sni...
Using StaticMatic for static pages
Update: Staticmatic will not be further developed. They suggest to switch to middleman.
If you need to make a static web page and find yourself missing all your Rails comforts, take a look at StaticMatic.
This works like an extremely stripped down version of Rails, giving you
- HAML
- SASS
- helpers
- partials
When done, everything is simply compiled to s...
Disable automatic e-mail checking in Thunderbird 3
Have you guys ever done the math on that? You asked or allowed for 24000 interruptions from literally every human being in the world who could fall onto a keyboard and make an e-mail go to you. (Merlin Mann)
So you decided to put a price on your attention and not check your e-mail 24000 times a year. A first step is to disable automatic e-mail checks in Thunderbird.
- Open Edit -> Account settings and select your incoming mail account.
...
Script to open an SSH shell to a Capistrano deployment target
We regularly need to connect to the server in order to e.g. access the production console. Guessing the Capistrano deploy user and then again guessing the right directory on the server is awkward, so we wrote a script that parses config/deploy and gives you the handy command shell-for
.
Run it from any project directory like this, passing a Capistrano multistage deployment target:
shell-for staging
Now it also supports commands to be remotely executed before loading the bash. Use --no-bash
to only execute the command and load no ba...
Why you see a GET "/__identify__" request in Capybara tests
You might wonder about this request in your test.log
:
Started GET "/__identify__" for 127.0.0.1 at 2015-04-29 18:00:02 +0100
This is what happens: For drivers like Selenium, Capybara will boot up a Thin or Webrick server in a separate thread. It then makes a GET request to /__identify__
to see if the server is ready to accept requests.
Since you don't have a route that responds to /__identify
, Capybara will wrap your Rails app in...
Bundler: Install gems behind a proxy
To install gems Bundler needs to be able to talk to https://api.rubygems.org
.
If you are behind a proxy you can use the https_proxy
environment variable:
https_proxy=http://myproxy:123 bundle install
Note that if there is no https_proxy
env variable, Bundler will also look for a http_proxy
env variable.
With Capistrano
Ideally the server you're deploying on exports an https_proxy
variable for all shells.
If you don't have control over the server setup, you can also add this to your Capistrano config:
...
RestClient sends XML Accept header by default
REST Client is a nice, simple HTTP client library for Ruby.
When you do a simple GET request like that:
RestClient.get 'http://example.com/'
it will result in this request beeing sent to www.example.com:
GET / HTTP/1.1
Accept: */*; q=0.5, application/xml
Accept-Encoding: gzip, deflate
Host: www.example.com
The application/xml
accept header might lead to unexpected results on your server. You can force REST Client to ask the server for default text/html
that way:
RestC...
Using the Facebook Graph API
App tokens
For server-to-server requests to the Facebook Graph API you can skip requesting an Oauth token, an instead use the combination of app_id|app_secret
as your access token. This token will never expire, and should suffice for retrieving basic information from the Graph API.
http://graph.facebook.com/endpoint?key=value&access_token=app_id|app_secret
Since you don't make requests for a certain user, the Graph API might respond with an error in case you're requesting a resource that requires authenticating as a human...
mysql2 and older ruby versions
The mysql2 gem in version 0.3.13 might break while compiling on older patch releases of Ruby 1.9.3 within rvm:
*** [err :: server] ruby: symbol lookup error: /path/to/deployment/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.13/lib/mysql2/mysql2.so: undefined symbol: rb_wait_for_single_fd
*** [err :: server] ruby: symbol lookup error: /path/to/deployment/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.13/lib/mysql2/mysql2.so: undefined symbol: rb_wait_for_single_fd
Fixating mysql2 to version 0.3.11 helped.
net-ssh and openssl-3.0.0
You'll need openssl-3 or newer for servers running 22.04
Ruby version 3.1
uses by default the gem openssl-3.0.0
. This can cause issues with the gem net-ssh (6.1.0
). This is a known bug.
Typically this can cause an error while deploying an application with capistrano:
could not verify server signature (SSHKit::Runner::ExecuteError)
or
Ed25519::VerifyError: signature verification failed!
As temporary workaround add the following line to your Gemfile
:
gem 'openssl', ...
Copy a file over SSH
Ubuntu lets you mount an SSH shell into Nautilus from Places -> Connect to server (select "SSH" as server type).
In order to copy a file over SSH from a shell:
scp filename username@remotehost:
The trailing ":" directs the file to username's home directory on the remote host.
You can also copy a file from the remote host to your local machine:
scp remotehost:remotepath localpath
Err http://de.archive.ubuntu.com [...] 404 Not Found [IP: 141.30.13.20 80]
I've got often this error on just one server:
Err http://de.archive.ubuntu.com precise/universe amd64 Packages
404 Not Found [IP: 141.30.13.20 80]
But there was no problem with the network connection or the de.archive.ubuntu.com server.
After I deleted the local lists cache with rm -r /var/lib/apt/lists
it works again.
Howto: Select2 with AJAX
Select2 comes with AJAX support built in, using jQuery's AJAX methods.
...
For remote data sources only, Select2 does not create a new element until the item has been selected for the first time. This is done for performance reasons. Once an has been created, it will remain in the DOM even if the selection is later changed.
If you have a huge collection of records for your select2 input, you can populate it via AJAX in order to not pollute your HTML with lots of <option>
elements.
All you have to do is to provide...
rails/turbolinks
Turbolinks makes following links in your web application faster. Instead of letting the browser recompile the JavaScript and CSS between each page change, it keeps the current page instance alive and replaces only the body and the title in the head.
This is similar to pjax, but instead of worrying about what element on the page to replace, and tailoring the server-side response to fit, we replace the entire body. This means that you get the bulk of the speed benefits from pjax (no recompiling of the JavaScript or CSS) without having to tail...
Dump your database with dumple
This tool is used on our application servers (and called when deploying) but it also works locally.
Just call dumple development
from your project directory to dump your database.
This script is part of our geordi gem on github.