Code Blog

Displaying 1-3 of 3 results.
2016/06/01 Programming,Xcode

After starting to use the new layout in Xcode I run into the “Frame for Button will be different at run time” warning. Not very obvious how to solve this, but after searching online I found this very useful tip:

This warning is displayed when the actual position of the element is different in your storyboard than while running the app.

You can select that element and then hit 'Option+Cmd+='.

This will update the position of the element in the storyboard and that warning will go away.

2016/02/15 Programming

I used to be an Emacs user, but switched to use Sublime Text the last few years. In any case I never got too familiar with the vim editor. However, vim editor is still quite useful as a terminal tool for editing as its pretty much always available. This time I needed to do some hex edit of a binary file but needed to look up some commands how to actually use it, see notes below.

Hex edit in Vi / Vim

Change into hex edit mode :%!xxd
Revert from hex mode :%!xxd -r
Global search and replace of string1 to string2 :g/string1/s//string2/g 

I noticed though that after turning into hex edit mode, the regexp will match all characters, so need to pay attention if one wants to match a sequence of 3 hex chars, as "1B04 05" will not match "1B 0405".

Btw, the difference between vi and vim is that vi is the standard pre-installed editor on Unix systems (first release dating back to 1976!), and vim (short for vi improved) is a cloned version with more functions than vi (originally written for the Amiga!).

Insert before the cursor (insert mode) i
Exit insert mode Esc
Delete from cursor to end of the line D
Write and quit :wq
Quit and don't save :q!

For more commands for example go to Vim Cheat Sheet (external link)

Run "vitutor" or "vimtutor" in the terminal will start vi/vim and load a beginners guide tutorial into the editor.

2016/02/15 Programming,Sublime-Editor

It's difficult to remember too many shortcuts, especially as i'm not using Sublime Text everyday, so I try to keep the list short. It's useful to lookup shortcuts via the command palette when I've forgotten something. A note on the documentation: the "super" key is the cmd key on the mac.

A Few Useful Shortcuts

cmd D mark word / multiple cursor
cmd shift P command palette
cmd P goto anything (add @ to search for symbols)
cmd R find symbol
   
cmd alt n advanced new file (need to first install the extension)
shift cmd [ or ] move between open files / tabs

Example of combined search:

cmd P “view blog form @functionname ”

This will search a file with the filepath matching for example, "view/blog/form.php", and it will open the first file that matches the search criteria and then also search for the "functionname" symbol inside the file!

 

Mac finder menu

On the mac its also nice to have a command in the left click menu in finder, to easily let Sublime Text read in a folder or file (the file structure will appear in the side bar of Sublime)

Go to Automator and create new command

Shell command

Create a "bin" directory for local user and create "subl" symbolic link to Sublime Text.

ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl .

in .bash_profile in home directory add the following line:

export PATH="~/bin:$PATH"

Show Hidden files in file dialog

Press ⌘ cmd + ⇧ shift + . to toggle show/hide hidden files.