Monday, November 12, 2018

iTerm2 sends commands to all panes

I use iTerm2 in Mac OSX as a replacement for built-in terminal, and it is pretty handy. I like that I can split a single window into multiple panes and run different cmds and observe outputs simultaneously, for example, starting different services and watching the logs. It saves me some time to otherwise align or locate multiple terminal windows constantly. There are of course many other benefits of iTerm2.

Today, I was switching between Chrome and iTerm2 feverishly to test something out, and all the sudden iTerm2 entered into a mode where my typings got sent to all panes instead of just the one I was interacting. This might be a useful feature, but not now. So what's going on and how can I get back?

It turns out this mode is activated via a "⌘Command + ⇧Shift + i" or "Shell -> Broadcast Input -> ... ". You know very well that the same keyboard shortcut in browser is used to bring out the "Developer Tools". So I probably hit this shortcut in the iTerm2 instead of browser by accident. To get back, just hit the same shortcut again, or use the menu.

Ok, back to work ...

Jun

Wednesday, November 7, 2018

Remove unwanted Confluence macro auto conversion

Confluence is widely used as a wiki platform for companies to document their internal knowledge. It also has a large collection of macros to help make the content more interactive, for example, embedding other documents, spreadsheets, videos, lists, tables, status, etc. Sometimes it can even detect your typing and automatically convert things into macros, although it may not be what you always want.

For example, I want to make a link to a Google Presentation in my page, so I pasted in the URL to that presentation, but then Confluence recognizes the URL and automatically convert it into a Google Slide macro and it is now a GIANT block showing the content of the slides, breaking the page layout, and there seems to be no way to stop that auto conversion. Frustrating ...

To workaround, instead of pasting the link directly into the editor, create a link macro by highlighting some text and clicking the "Insert Link" icon in the editor's toolbar, and then you can paste in the URL into the dialog that pops up, this way it will remain a link and not the block showing actual slides.

Enjoy!

Jun

Friday, November 2, 2018

Elixir strings in single quote vs double quote

Today I stumbled on the subtle difference in Elixir between strings in single quote and double quote. Although the documentation explains it clearly, but who reads the documentation these days anyway.

Here is the deal:

  • Single quoted string, is actually a charlist, aka a list of chars. If you want to concatenate them, you need to use list concatenation operator '++'. 
  • 'hello' ++ ' ' ++ 'world' 
  • Double quoted string, is a UTF-8 encoded 'binary', aka a series of bytes. Their concatenation is done via '<>'. 
  • "hello" <> " " <> "world"
  • You can't mix the two
  • "hello" ++ " " ++ "world" # this is wrong
    'hello' ++ " " ++ 'world' # also wrong
    "hello" <> " " ++ 'world' # you just don't get it
  • There are functions to convert
  • to_charlist("hello")
    to_string('hello')

    to_string('hello') <> " world"
    to_charlist("hello") ++ ' world'
  • You may tend to care less about the difference, and just stick to just one type, say always use the double quoted strings. However be aware that some erlang library you end up using unknowingly may use different type and give you cryptic error. For example
    iex> "<h1><a>title</a></h1>" |> SweetXml.xpath(~x"//h1/a/text()")

    'title' 

    Note the return is a charlist even the original input is a string/binary!