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
formattocustom - Change the key
custom-formatto astrftimeformat 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...
Beware of rails' reverse_order!
#reverse_order does not work with complex sorting constraints and may even silently create malformed SQL for rails < 5.
Take a look at this query which orders by the maximum of two columns:
Page.order('GREATEST(pages.published_from_de, pages.published_from_en) DESC').to_sql
# => SELECT "pages".* FROM "pages" ORDER BY GREATEST(pages.published_from_de, pages.published_from_en) DESC
Rails 4
Rails 4 will not immediately raise but creates malformed SQL when trying to use reverse_order on this query:
Pageorder('GRE...
Master the chrome history and autocomplete
1. Sometimes you have search entries in the autocomplete of the address bar, which are higher weighted than your bookmarks. Pressing SHIFT + DEL while searching removes them from the history immediately.
2. Sometimes you have search entries in the autocomplete of the address bar, which are all higher weighted than your recently visited sites. Add a search for your history, so you can get recent results first.
...
AngularJS Cheat Sheet (PDF)
This cheat sheet ... aims at providing a quick reference to
the most commonly used features in AngularJS.
Running awstats on a single logfile
AWstats is build to regularly run on webservers. If you want it to build a report once, here is the minimal configuration you need:
Put the following into the awstats config file (look into /etc/awstats/awstats.conf.local or look into /etc/awstats/awstats.conf how to do it on your system):
SiteDomain="yourdomain.de"
DirData="."
DNSLookup=0
Run the following to build a simple HTML page:
awstats -staticlinks -config="yourdomain.de" -LogFile=your-logfile.log -output > report.html
This might take a second (it will take ...
Git error: "badTimezone: invalid author/committer line - bad time zone"
You might get the above error message when cloning certain git repositories (for example the rails repository). It indicates that there is a malformed timestamp in some commit, and your git installation is configured to validate it.
As a workaround, you can disable the validation using
git config --global fetch.fsckobjects false
This settings seems to be the default for most git installations anyways.
Pexels: Free stock photos
You can find great stock photos on pexels.com.
All pictures are free for personal and commercial use without attribution, and may be modified.
Detecting if a Ruby gem is loaded
Detect if a gem has been activated
A gem is activated if it is either in the current bundle (Gemfile.lock), or if you have manually activated it using Kernel#gem (old-school).
To detect if e.g. activerecord has been activated:
if Gem.loaded_specs.has_key?('activerecord')
# ActiveRecord was activated
end
Detect if a particular gem version has been activated
To detect if e.g. activerecord ma...
Ubuntu Mate: Get rid of F12 drop-down terminal
To get your F12 key back for other shortcuts, stop Tilda:
killall tilda
To prevent Tilda from starting on boot you can remove it
sudo apt-get remove tilda
or disable auto start:
- Go to Mate Control Center > Startup Applications
- uncheck "Tilda"
makandra/gemika: Helpers for testing Ruby gems
We have released a new library Gemika to help test a gem against multiple versions of Ruby, gem dependencies and database types.
Here's what Gemika can give your test's development setup (all features are opt-in):
- Test one codebase against multiple sets of gem dependency sets (e.g. Rails 4.2, Rails 5.0).
- Test one codebase against multiple Ruby versions (e.g. Ruby 2.1.8, Ruby 2.3.1).
- Test one codebase against multiple database types (currently MySQL or PostgreSQL).
- Compute a matrix of all possib...
Fix "libmysqlclient.so.20: cannot open shared object file: No such file or directory"
This error can be caused by the mysql2 gem under mysterious circumstances. You need to remove it with gem uninstall mysql2 and then reinstall it (or just run bundle).
gem pristine mysql2 will not be enough.
Sass: How to convert an RGBA color to its RGB look-alike
Say you have an RGBA color that you need as a non-transparent color because of reasons.
Basically, this is possible. Just understand that you will convert your RGBA color for exactly one base background color as you are giving up transparency.
Most likely, your background is white, so you'll use #fff as that for examples below.
Simple approach
When your know the RGBA color's base RGB color (e.g. your brand color that you RGBA'd for some hover effect), you can simply use the mix function instead of rgba.
Before:
backgroun...
VCR fails if the same request is triggered multiple times
Same requests are recorded only once in vcr. Replaying a test fails, if you trigger the same request multiple times. The error message is somehow confusing, as your cassette contains the request:
An HTTP request has been made that VCR does not know how to handle
If you want to allow to match a request multiple times, you need to configure this explicit with allow_playback_repeats: true. Some exa...