Set of “defaults writes” for a new machine

As I seem to repeatedly search for those whenever I set another machine up – I thought of maintaining here a list of those I (personally) find close to indispensable:

Recent application tile:

defaults write com.apple.dock persistent-others -array-add '{"tile-data" = {"list-type" = 1;}; "tile-type" = "recents-tile";}

Highlighting selection on the grid with mouse-over:

defaults write com.apple.dock mouse-over-hilite-stack -bool true

Distinguishing hidden applications:

defaults write com.apple.Dock showhidden -bool YES

Adding “Quit” menu item to finder (sometimes easier to “force quit”)

defaults write com.apple.finder QuitMenuItem -bool true; killall Finder
Advertisements
Posted in OSX | Tagged , , | Leave a comment

Better description of Rails rake “db” tasks

Reposted after https://jacopretorius.net/ (good job!)

  • db:create Creates the database for the current RAILS_ENV environment. If RAILS_ENV is not specified it defaults to the development and test databases.
  • db:create:all Creates the database for all environments.
  • db:drop Drops the database for the current RAILS_ENV environment. If RAILS_ENV is not specified it defaults to the development and test databases.
  • db:drop:all Drops the database for all environments.
  • db:migrate Runs migrations for the current environment that have not run yet. By default it will run migrations only in the development environment.
  • db:migrate:redo Runs db:migrate:down and db:migrate:up or db:migrate:rollback and db:migrate:migrate depending on the specified migration. I usually run this after creating and running a new migration to ensure the migration is reversable.
  • db:migrate:up Runs the up for the given migration VERSION.
  • db:migrate:down Runs the down for the given migration VERSION.
  • db:migrate:status Displays the current migration status.
  • db:migrate:rollback Rolls back the last migration.
  • db:version Prints the current schema version.
  • db:forward Pushes the schema to the next version.
  • db:seed Runs the db/seeds.rb file.
  • db:schema:load Loads the schema into the current environment’s database.
  • db:schema:dump Dumps the current environment’s schema to db/schema.rb.
  • db:setup Runs db:create, db:schema:load and db:seed.
  • db:reset Runs db:drop and db:setup.
  • db:migrate:reset Runs db:drop, db:create and db:migrate.
  • db:test:prepare Check for pending migrations and load the test schema. (If you run rakewithout any arguments it will do this by default.)
  • db:test:clone Recreate the test database from the current environment’s database schema.
  • db:test:clone_structure Similar to db:test:clone, but it will ensure that your test database has the same structure, including charsets and collations, as your current environment’s database.
Posted in Coding, Rails | Tagged , | Leave a comment

Useful online font identification tools

https://www.myfonts.com/WhatTheFont/

https://www.fontsquirrel.com/matcherator

One of them will probably get you to the font you are in need of.

Posted in Uncategorized | Leave a comment

Rubygems: Rebuild native extensions

Reposted after “makandropedia”:

Rarely, you might want to rebuild all gems with native extensions, because they might be compiled against outdated system libraries, resulting in some warnings or even segfaults or other ruby errors.

You can do that using

gem pristine --all

This will reset all gems to a pristine state as if you’d reinstall them, and as a side effect, rebuild all native extensions.

The above command will also help you sorting out errors like this after a distribution upgrade:

libmysqlclient_r.so.16: cannot open shared object file: No such file or directory - /home/henning/.rvm/gems/ruby-1.8.7-p358/gems/mysql2-0.3.11/lib/mysql2/mysql2.so

(Because the library which is used to compile the gem doesn’t exist anymore and you have to recompile it.)

Posted in Coding, Rails | Tagged , | Leave a comment

One – liner to batch rename files with regex-remove part of the filename

Don’t read this post. It’s only for me so that I don’t forget it 😉

After a long fight with bash, find, sed, … Here is the one – liner:

for i in $(find -E . -regex '(.*[a-zA-Z]{3}[0-9]{3}[a-zA-Z]{3}_[0-9]{9})(\.[0-9])(\.[jJ][pP]([eE])*[gG])') ; do mv -v $i $(echo $i | sed -E 's/(.*[a-zA-Z]{3}[0-9]{3}[a-zA-Z]{3}_[0-9]{9})(\.[0-9])(\.[jJ][pP]([eE])*[gG])/\1\3/') ; done

Given a set of JPEG files, which contained duplicates with .1 thrown-in before the final dot and the ending of the filename, replacing the original with the newer ones (those with .1‘s) seemed like a trivial task… until I tried to actually do this. In the end it came to using “modern regex” with matching groups and refer to those groups I wanted to retain. These are \1 and \3 concatenated in the \1\3 part of the sed replace pattern. Group \2 (the .1) didn’t make it there.

 

Posted in bash, Coding | Tagged , , , , | Leave a comment

One-bash-liner to get rid of .WMV container

For reasons known probably to only a very few, selected ones – videos contained in the “.WMV” container seem to have occasional problems with seeking and positioning when played back with XBMC (or “Kodi” if you adapted to the brave new name). To alleviate the problem I eventually wrote a one-liner that copies all video and audio streams from “.WMV” files into Matroska containers:

SAVEIFS=$IFS; IFS=$(echo -en "\n\b"); for i in $( ls *.wmv ) ; do ffmpeg -i "$i" -c copy "${i%.*}".mkv ; done ; IFS=$SAVEIFS

CD into the directory with the video files you want to process and go. Obviously you need to have a working ffmpeg installation first.

Posted in Video | Tagged , , , | Leave a comment

Rails derailed again (and again)

Executive summary (aka TL;DR)

  1. Rails docs suck… erm, no. I mean they are great but most probably written by people who never actually had to use them.
  2. If you want to follow Rails Guides and install a fresh Rails environment on a vanilla Ubuntu 16.04LTS you need at least the following dependencies installed before you start:
    • ruby-dev
    • zlib1g-dev
    • libsqlite3-dev
    • gcc
    • make
    • g++

Continue reading

Posted in Rails, Rants | Tagged , , , , | 4 Comments