TIL is my collection of short, technical daily learnings. 233 and counting.
Reverse a String
Reverse a string with the rev command. $ echo 'test' | rev tset It also works with files. $ rev Procfile br.amup/gifnoc C- amup cexe eldnub :bew
TIL is my collection of short, technical daily learnings. 233 and counting.
Reverse a string with the rev command. $ echo 'test' | rev tset It also works with files. $ rev Procfile br.amup/gifnoc C- amup cexe eldnub :bew
Previously run commands can be viewed with the history command. $ history 10048 git checkout master 10049 gpr 10050 rake With this list, you can rerun any command using !n: $ !10048 Already on 'master' The command !! prints the last command you ran, then runs it. Here is an example: $ ls LICENSE.md README.md bash cucumber rails $ !! ls LICENSE.md README.md bash cucumber rails Replace the second ! with the first few letters of a command you have previously run, and bash will search for, print, and run the most recent instance. ...
I like a quiet computer. But I also like tab-completing commands in the terminal, which produces a necessary alert from time to time. A solution I found today is to use OSX Accessibility features to add a screen flash on alerts, then disable the sounds. System Preferences > Accessibility > Hearing menu, choose ‘Audio’ > Check ‘Flash the screen when an alert occurs’
Processes on any POSIX-compliant computer can be sent to the background with CTRL-Z (<prefix> + Z for the tmux-ers) and returned to the foreground with fg. Here is an example: user@computer:~% ping www.google.com PING www.google.com (74.125.228.212): 56 data bytes 64 bytes from 74.125.228.212: icmp_seq=0 ttl=52 time=41.574 ms 64 bytes from 74.125.228.212: icmp_seq=1 ttl=52 time=42.836 ms 64 bytes from 74.125.228.212: icmp_seq=2 ttl=52 time=53.527 ms ^Z zsh: suspended ping www.google.com user@computer:~% fg [1] + continued ping www.google.com 64 bytes from 74.125.228.212: icmp_seq=3 ttl=52 time=42.433 ms 64 bytes from 74.125.228.212: icmp_seq=4 ttl=52 time=42.401 ms 64 bytes from 74.125.228.212: icmp_seq=5 ttl=52 time=42.837 ms 64 bytes from 74.125.228.212: icmp_seq=6 ttl=52 time=44.203 ms ^C --- www.google.com ping statistics --- 7 packets transmitted, 7 packets received, 0.0% packet loss
Today I was trying to restore a production Postgres dump on a remote machine, to test some migrations. I haven’t granted myself Heroku production database access, hence the SSH into a machine with a Heroku user that has access. I quickly hit a problem— this remote machine runs Postgres using Postgres.app. Without that program, I’m out of luck. No local Postgres server, no production database restore, no testing. It turns out you can start Postgres.app from the command line. Find the executable and call it. ...
Have you ever been working in the terminal and found yourself repeating the same command many times? Delegate that work to the computer. watch comes with Linux and can be installed on OSX via homebrew. It executes a program periodically, defaulting to every two seconds. We used it today while writing a database backup script. Instead of checking our dump directory every time a cron job executed, we ran watch ls, and watched the script succeed or fail with live updates. ...
Today I got to see the :ExtractRspecLet command from the vim-weefactor plugin. It does what the names suggests, converting this: # spec/model/foobar_spec.rb foo = FactoryGirl.create :foobar To this: # spec/model/foobar_spec.rb let(:foo) { FactoryGirl.create :foobar } It also moved the new let from inside my it block to right underneath my context block. Awesome! h/t Josh Davey and Dillon Hafer
To update rubygems: gem install rubygems-update update_rubygems gem update --system
If you’ve been mucking around in your Ruby dependencies, bundle pristine is your friend; it resets all of the gems in your Gemfile to their pristine condition. This can be a slow on a big project. Target the specific gems you worked on today with: $ bundle pristine <gemname>
“Select isn’t broken.” If you’re working on a CSS file, and none of your changes are being applied, check for typos, crashed servers, misplaced files, etc. Once you’ve ruled out simple mistakes, you might have a syntax error like this: .klass { opacity: 0.5; }; The trailing semicolon is incorrect, and none of the CSS below it can be understood by the browser. Change this to: .klass { opacity: 0.5; } There may be some environments where a broken CSS file fails loudly; Code Sandbox or Codepens are not among them. If you’re changing CSS and nothing is happening, start looking for syntax errors. ...