Chrome: how to fix window issues (maximize, minimize,...)
I experienced a lot of issues with google chrome that made it almost impossible to work with it. Here are some of them:
- minimized windows stay hidden
- maximized windows overlap system bars (like the status bar of Ubuntu Mate on the top edge of the screen)
- windows cannot be resized
I finally discovered a setting that fixed these issues for me:
- go to
chrome://settings/appearance
- activate
Use system title bar and borders
I'm not sure if this setting was changed by me or if it was the browser default.
Vortrag: Content Security Policy: Eine Einführung
Grundidee
CSP hat zum Ziel einen Browser-seitigen Mechanismus zu schaffen um einige Angriffe auf Webseiten zu verhindern, hauptsächlich XSS-Angriffe.
Einschub: Was ist XSS?
XSS = Cross Site Scripting. Passiert wenn ein User ungefiltertes HTML in die Webseite einfügen kann.
<div class="comment">
Danke für den interessanten Beitrag! <script>alert('you have been hacked')</script>
</div>
Rails löst das Problem weitgehend, aber
- Programmierfehler weiter möglich
- manchmal Sicherheitslücken in Gems oder Rails
Lösungsid...
How to check if a file is a human readable text file
Ruby's File class has a handy method binary?
which checks whether a file is a binary file. This method might be telling the truth most of the time. But sometimes it doesn't, and that's what causes pain. The method is defined as follows:
# Returns whether or not +file+ is a binary file. Note that this is
# not guaranteed to be 100% accurate. It performs a "best guess" based
# on a simple test of the first +File.blksize+ characters.
#
# Example:
#
# File.binary?('somefile.exe') # => true
# File.binary?('somefile.txt') # => fal...
How to cycle through grep results with vim
grep
is the go-to CLI tool to accomplish tasks like filtering large files for arbitrary keywords. When additional context is needed for search results, you might find yourself adding flags like -B5 -A10
to your query. Now, every search result covers 16 lines of your bash.
There is another way: You can easily pipe your search results to the VIM editor and cycle through them.
Example: Searching for local occurrences of "User"
vim -q <(grep -Hn -r "User" .)
# vim -q starts vim in the "quickfix" mode. See ":help quickfix"
# grep...
How to migrate CoffeeScript files from Sprockets to Webpack(er)
If you migrate a Rails application from Sprockets to Webpack(er), you can either transpile your CoffeeScript files to JavaScript or integrate a CoffeeScript compiler to your new process. This checklist can be used to achieve the latter.
- If you need to continue exposing your CoffeeScript classes to the global namespace, define them on
window
directly:
-class @User
+class window.User
- Replace Sprocket's
require
statement with Webpacker's...
The State of Ruby 3 Typing | Square Corner Blog
We're pleased to announce Ruby 3’s new language for type signatures, RBS. One of the long-stated goals for Ruby 3 has been to add type checking tooling. After much discussion with Matz and the Ruby committer team, we decided to take the incremental step of adding a foundational type signature language called “RBS,” which will ship with Ruby 3 along with signatures for the stdlib. RBS command line tooling will also ship with Ruby 3, so you can generate signatures for your own Ruby code.
Ruby 3 is coming, and it will have optional type sign...
Geordi 4 released
4.0.0 2020-07-30
Compatible changes
- Improved documentation; README now includes command options.
- Improvement #90: geordi console, geordi deploy, geordi rake and geordi shell now work correctly if the project hasn't been bundled before
- Use binstubs if present – breaks Geordi execution when a binstub is not working
Breaking changes
- Removed deprecated executables
Introducing GoodJob 1.0, a new Postgres-based, multithreaded, ActiveJob backend for Ruby on Rails
GoodJob is a new background worker gem. It's compatible with ActiveJob.
We're huge fans of Sidekiq for its stability and features. One advantage of GoodJob over Sidekiq is that GoodJob doesn't require Redis. So in cases where you don't have Redis or don't want to pay for a Redis HA quorum node, this might be an alternative worth checking out.
Fixing wall of warnings: already initialized constant Etc::PC_SYMLINK_MAX
These warnings are printed when the etc
Gem is installed, while etc
is also included in Ruby. Fix with:
gem uninstall etc
Git: Merge a single commit from another branch
This is called "cherry-picking".
git cherry-pick commit-sha1
Note that since branches are nothing but commit pointers, cherry-picking the latest commit of a branch is as simple as
git cherry-pick my-feature-branch
Be aware that cherry-picking will make a copy of the picked commit, with its own hash. If you merge the branch later, the commit will appear in a history a second time (probably without a diff since there was nothing left to do).
Also see our advice for [cherry picking to production branches](https://makandraca...
How to prevent Nokogiri from fixing invalid HTML
Nokogiri is great. It will even fix invalid HTML for you, like a browser would (e.g. move block elements out of parents which are specified to not allow them).
>> Nokogiri::HTML.fragment("<h1><p>foo</p><span>bar</span></h1>").to_s
=> "<h1></h1><p>foo</p><span>bar</span>"
While this is mostly useful, browsers are actually fine with a bit of badly formatted HTML. And you don't want to be the one to blame when the SEO folks complain about an empty <h1>
.
To avoid said behavior, use Nokogiri::XML
instead of Nokogiri::HTML
whe...
FactoryBot: Traits for enums
FactoryBot allows to create traits from Enums since version 6.0.0
The automatic definition of traits for Active Record enum attributes is enabled by default, for non-Active Record enums you can use the traits_for_enum
method.
Example
factory :user do
traits_for_enum :role, %w[admin contact] # you can use User::ROLES here, of course
end
is equivalent to
factory :user do
trait :admin do
role { 'admin' }
end
trait :contact do
role { 'c...
The HTML5 video element
# Basic HTML example
<video poster="preview_image.png" controls>
<source src="or_here.webm" type="video/webm" />
<source src="alternative_if_browser_cant_pay_first_source.mp4" type="video/mp4" />
<track src="optional_subtitles.vtt" kind="subtitles" srclang="de" label="Deutsch" default>
</video>
# Javascript API (notable methods and properties)
video = document.querySelector('video')
video.play()
video.pause()
video.load() // Reset to the beginning and select the best available source
video.currentSrc // The selected source
video.c...
The JavaScript Object Model: Prototypes and properties
Speaker today is Henning Koch, Head of Development at makandra.
This talk will be in German with English slides.
Introduction
As web developers we work with JavaScript every day, even when our backend code uses another language. While we've become quite adept with JavaScript at a basic level, I think many of us lack a deep understanding of the JavaScript object model and its capabilities.
Some of the questions we will answer in this talk:
- How does the
new
keyword construct an object? - What is the differen...
Merging two JavaScript objects
Let's say you want to merge the properties of two JavaScript objects:
let a = { foo: 1, bar: 2 }
let b = { bar: 3, baz: 4 }
let merged = merge(a, b) // => { foo: 1, bar: 3, baz: 4 }
Depending on your build, there are several ways to implement merge()
.
When you have ES6
When you have an ES6 transpiler or don't support IE11, you may use the spread operator (...
) to expand both objects into a new object literal:
let merg...
Select2 alternatives without jQuery
Select2 is a fantastic library for advanced dropdown boxes, but it depends on jQuery.
Alternatives
Tom Select
There is a selectize.js
fork called Tom Select. It is well tested, comes with Bootstrap 3, Bootstrap 4 and Bootstrap 5 styles and is easy to use. You might miss some advanced features.
Known issues:
- Dynamic opt-groups in AJAX requests are not supported, you need to define them in advance on the select field (see <https://github.com/selectize/selectize.js/pull/1226/...
How to use Active Job to decouple your background processing from a gem
In a web application you sometimes have tasks that can not be processed during a request but need to go to the background.
There are several gems that help to you do that, like Sidekiq or Resque.
With newer Rails you can also use ActiveJob as interface for a background processing library. See here for a list of supported queueing adapters.
For ...
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...
Testing for XSS in Markdown Fields
If you render markdown from user input, an attacker might be able to use this to inject javascript code into the source code of your page.
The linked github page is a collection of common markdown XSS payloads which is handy for writing tests.
Producing arbitrary links:
[Basic](javascript:alert('Basic'))
[Local Storage](javascript:alert(JSON.stringify(localStorage)))
[CaseInsensitive](JaVaScRiPt:alert('CaseInsensitive'))
[URL](javascript://www.google.com%0Aalert('URL'))
[In Quotes]('javascript:alert("InQuotes")')
Using onload...
Error handling in DOM event listeners
When an event listener on a DOM element throws an error, that error will be silenced and not interrupt your program.
In particular, other event listeners will still be called even after a previous listener threw an error. Also the function that emitted the event (like element.dispatchEvent()
or up.emit()
) will not throw
either.
In the following example two handlers are listening to the foo
event. The first handler crashes, th...
Don't ever use the float type for database columns
Like in any language, a FLOAT
will eventually corrupt data due to rounding errors.
Please use DECIMAL
, which has well-defined behavior for rounding and range overflows.
Ruby: Using the pry debugger in projects with older Ruby versions
In case you want to use pry with an older version of Ruby, you can try the following configurations.
Ruby 1.8.7
Your pry
version must not be greater than 0.9.10
.
gem 'pry', '=0.9.10'
gem 'ruby-debug', '=0.10.4'
gem "ruby-debug-pry", :require => "ruby-debug/pry"
gem 'pry-nav'
gem 'ruby18_source_location'
Ruby 1.9.3
Your pry
version must not be greater than 0.9.9
.
gem 'debugger', '=1.1.4'
gem 'pry-debugger', '=0.2.0'
gem 'pry', '=0.9.9'
Known errors
No source for ruby-1...
The ultimate guide to Ruby timeouts
An unresponsive service can be worse than a down one. It can tie up your entire system if not handled properly. All network requests should have a timeout.
Here’s how to add timeouts for popular Ruby gems. All have been tested. You should avoid Ruby’s Timeout module. The default is no timeout, unless otherwise specified. Enjoy!

Migrate data between Redis servers
There is a reasonable simple way to move data between Redis servers: Simply temporarily configure the new server as a replica of the old server.
To do this:
- Make sure the new Redis server can access the old server. If they are on different networks, a simple SSH tunnel will do.
- Connect to the new server using
redis-cli
. - Tail the log of the redis server (found in
/var/logs/redis
) in another terminal. - Make sure the server is currently master and not already a replica (check
INFO replication
) - Enable replication with `REPL...