Howto: Free disk space when /boot is full
Easy mode
This method will remove automatically installed packages that no other packages depend on any more. This, of course, includes obsolete kernel versions, with the explicit exception of the currently running kernel, the kernel version that was installed on the system before that and, of course, the latest updated version of the kernel. However, it will also remove any and all other packages that have been marked as installed automatically but have no other packages depending on them. This could lead to unexpected removal of packag...
Awesome WM: workaround for gnome or mate panel stealing focus
If you use awesome 3.5, and a gnome or mate panel, the panel will often receive focus when you switch desktops. As a workaround:
- Add this rule to your rc.lua:
{ rule = { class = "Mate-panel" }, properties = { ontop = true, focusable = false } }
- Replace
/usr/share/awesome/lib/awful/autofocus.lua
with the attached file
Fix external Displays switching not on when plugging notebook in docking station
If your external displays not switching on or showing a weird behavior (for e.g. all displays getting the same configuration all the time) you can fix it by switching off all external displays and re-enabling only one in the first step. Afterwards you can apply your whole configuration via xrandr
. This behavior could be a bug in the kernel and may be fixed in linux 4.8.
Example display configuration
Screen 0: minimum 8 x 8, current 5760 x 1200, maximum 32767 x 32767
eDP1 connected 1920x1080+0+0 (normal left inverted right x axis...
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...
How to fix: Bundler 1.13 breaks parallel_tests
When running tests via parallel_tests, you may encounter an error:
cannot load such file -- parallel_tests/gherkin/runtime_logger
Error creating formatter: ParallelTests::Gherkin::RuntimeLogger (LoadError)
This will happen when you upgrade Bundler to version 1.13.x and appears to be "by design" since there is a Bundler config option to restore previous behavior.
You can fix it by setting that flag. You should commit the resulting config file into the repository!
bundle config --local disable_exec_load true
There is a Git...
Aruba: Stubbing binaries
When testing your command line application with Aruba, you might need to stub out other binaries you don't want to be invoked by your test.
Aruba Doubles is a library that was built for this purpose. It is not actively maintained, but works with the little fix below.
Installation
Install the gem as instructed by its README, then put this Before
block somewhere into features/support
:
Before do
Arub...
Hide a Rake task from the `rake -T` list
A Rake task appears in rake -T
if it has a description:
desc 'Compile assets'
task :compile do
...
end
To not list it, simply omit the description:
task :compile do
...
end
You can also hide a Rake task that has been defined by someone else (like a gem) by removing the description:
Rake::Task['compile'].clear_comments
Or you can whitelist which tasks should be listed:
visible_tasks = %w(compile build package)
Rake::Task.tasks.each do |task|
visible_tasks.include?(task.name) or task.clear_comments
en...
Ruby: Writing specs for (partially) memoized code
When you're writing specs for ActiveRecord models that use memoization, a simple #reload
will not do:
it 'updates on changes' do
subject.seat_counts = [5]
subject.seat_total.should == 5
# seat_total is either memoized itself, or using some
# private memoized method
subject.seat_counts = [5, 1]
subject.seat_total.reload.should == 6 # => Still 5
end
You might be tempted to manually unmemoize any memoized internal method to get #seat_total
to update, but that has two disadvant...
Subclassing module
Yesterday I stumbled across a talk in which the guy mentioned module sub-classing. I was curious what you can do with it and found his blog post with a cool example. It allows you to inject some state into the module you are including elsewhere. Check it out!
class AttributeAccessor < Module
def initialize(name)
@name = name
end
def included(model)
super
define_accessors
end
private
def define_accessors
ivar = "@#{@name}"
define_writer(ivar)
define_reader(ivar)
end
def define_writer(ivar)
...
Angular with haml: Dynamic html classes
A haml angular 1 template with
.thing(class="is-{{:: item.type }}")
will be compiled (by haml) to
<div class="is-{{:: item.type thing }}"></div>
which is not what you want! It will also crash in angular (unless thing
is a valid variable in your angular directive) with Error: [$parse:syntax] Syntax Error: Token 'thing' is an unexpected token at column 11 of the expression [item.type thing]
Solution 1: Use ng-class
instead of class
.thing(ng-class='"is-{{ item.type }}"')
**Solution 2: Don't let haml b...
How to monitor Sidekiq: A working example
In order to have monitoring for Sidekiq (like queue sizes, last run of Sidekiq) your application should have a monitoring route which returns a json looking like this:
{
"sidekiq": {
"totals": {
"failed": 343938,
"processed": 117649167
},
"recent_history": {
"failed": {
"2016-11-06": 1,
"2016-11-07": 46,
"2016-11-08": 0,
"2016-11-09": 0,
"2016-11-10": 0
},
"processed": {
"2016-11-06": 230653,
"2016-11-07": 230701,
"2016-11-08"...
Understanding AngularJS service types
Angular comes with different types of services. Each one with its own use cases.
All of these services are singletons. You probably want to use Factory all the time.
Provider
- is the parent of all other services (except
constant
) - can be configured using `app.config(function(Provider) { ...})
- a little complex
Factory
- simpler than Provider, but without configuration
- definition: `app.factory('name', someFunction)
-
someFunction
is called when thename
service is instantiated and should return an object
Se...
mceachen/closure_tree: Easily and efficiently make your ActiveRecord models support hierarchies
Closure_tree lets your ActiveRecord models act as nodes in a tree data structure.
This promises a few improvements over the battle-tested ancestry gem, such as:
- Better performance
- Pre-ordered trees (painful to do with ancestry)
- Holds a mutex during tree manipulations (an issue with ancestry, where concurrent updates can cause deadlocks and corrupt data).
It has some more moving parts than ancestry though (see below).
Implementation
--------------...
AngularJS: How to remove a watch
Sometimes you want Angular to watch an object only until a certain state is reached (e.g. an object appears in the scope).
Angular's $watch
returns a method that you can call to remove that watch. For example:
unwatch = $scope.$watch 'user', (user) ->
if user?
... # do something
unwatch()
That's it.
How to inspect really large directories
When a directory has more than a few thousand entries, ls
will start taking really long to list its content. Reason for this is that ls
by default a) sorts the file names and b) prints them in columns. For both, it needs to know (thus load into memory) the whole list of files before it can start printing anything.
By disabling sorting and columns, you get a lean, superfast ls
that prints "live" as it reads:
$> ls -f -1
file1
file2
...
file9999
file10000
file10001
...
Repeatedly execute a bash command and observe its output
You can have a command repeatedly executed and the output displayed. This is useful e.g. for monitoring file system changes with ls
, but has many more applications.
The update frequency is controlled by the -n
argument (default: 2s), which is locale-specific; i.e. you might need to use a comma as delimiter.
> watch -n 1.5 ls
How to "git diff" with a graphical diff tool
If you are fine with the default console diff most of the time but only sometimes want to use an external tool for viewing a diff, you can use git difftool
.
E.g. viewing git diff
with meld:
git difftool --tool=meld
For each file in the diff you will be asked if you want to view it using meld.
tesseract.js: Pure Javascript OCR for 62 Languages
This might be relevant for us since we're often managing customer documents in our apps.
I played around with the library and this is what I found:
- A 200 DPI scan of an English letter (500 KB JPEG) was processed in ~6 seconds on my desktop PC. It does the heavy lifting in a Web worker so you're rendering thread isn't blocked.
- It detected maybe 95% of the text flawlessly. It has difficulties with underlined text or tight table borders.
- When you feed ...
Configure how VCR matches requests to recorded cassettes
VCR lets you configure how it matches requests to recorded cassettes:
In order to properly replay previously recorded requests, VCR must match new
HTTP requests to a previously recorded one. By default, it matches on HTTP
method and URI, since that is usually deterministic and fully identifies the
resource and action for typical RESTful APIs.You can customize how VCR matches requests using the `:match_requests_on casse...
Git: See more context in a diff
Using the -U
parameter you can change how many lines are shown above and below a changed section.
E.g. git diff -U10
will show 10 lines above and below.
Debugging flickering VCR tests
We often use VCR to stub external APIs. Unfortunately VCR can have problems matching requests to recorded cassettes, and these issues are often hard to debug.
VCR's error messages mostly look like this and are not very helpful:
An HTTP request has been made that VCR does not know how to handle:
POST http://another-site.de:9605/json/index
VCR fails if the request does not exactly look like the request it has recorded. If the request is d...
Ubuntu MATE: Custom time format for clock panel widget
- Run
dconf-editor
(as your user) - Go to
org / mate / panel / objects / clock / prefs
- Change the key
format
tocustom
- Change the key
custom-format
to astrftime
format string
A good, space-saving format string for German users is %d.%m. %H:%M
. This shows the current date, month, hour and minute (e.g. 24.12. 23:59).
Styling SVGs with CSS only works in certain conditions
SVG is an acronym for "scalable vector graphics". SVGs should be used whenever an image can be described with vector instructions like "draw a line there" or "fill that space" (they're not suited for photographs and the like). Benefits are the MUCH smaller file size and the crisp and sharp rendering at any scale.
It's a simple, old concept brought to the web – half-heartedly. While actually all browsers pretend to support SVG, some barely complex use cases get you beyond common browser support.
In the bas...
Creating icon fonts with Icomoon
Icomoon.io offers a free app to build custom icon webfonts. It offers downloads as webfont set (.eot, .ttf, .woff, .woff2) or as icon set of SVG and/or PNG and many more file types, or even SVG sprites.
From my experience, the frontend developer should create the font, and not the designer. There are many tweaks required during font development, and routing changes over the designer imposes just too much overhead.
On rare occasions, webfonts may be blocked by an entreprise's security policy. Be sure webfonts can be u...