Jekyll2023-09-13T11:45:32+00:00https://xsnpdngv.github.io/feed.xmlA S D F . H UPersonal websiteTamás T. Dezsődezso.t.tamas@gmail.comFix WSL DNS issue on VPN2023-09-13T00:00:00+00:002023-09-13T00:00:00+00:00https://xsnpdngv.github.io/development/WSL-VPN-DNS-fix<aside class="sidebar__right">
<nav class="toc">
<header><h4 class="nav__title"><i class="fa fa-file-text"></i> On This Page</h4></header>
<ul class="toc__menu" id="markdown-toc">
<li><a href="#re-enble-auto-generation-of-resolvconf-if-disabled" id="markdown-toc-re-enble-auto-generation-of-resolvconf-if-disabled">Re-enble auto-generation of resolv.conf (if disabled)</a></li>
<li><a href="#create-the-script" id="markdown-toc-create-the-script">Create the script</a></li>
<li><a href="#make-it-executablerun-as-sudo" id="markdown-toc-make-it-executablerun-as-sudo">Make it executable/run as sudo</a></li>
<li><a href="#run-as-superuser" id="markdown-toc-run-as-superuser">Run as superuser</a></li>
<li><a href="#set-interface-metric-in-admin-powershell" id="markdown-toc-set-interface-metric-in-admin-powershell">Set interface metric in admin PowerShell</a></li>
</ul>
</nav>
</aside>
<h2 id="re-enble-auto-generation-of-resolvconf-if-disabled">Re-enble auto-generation of resolv.conf (if disabled)</h2>
<p>by commented the disable with #</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>vi /etc/wsl.conf
</code></pre></div></div>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#[network]</span>
<span class="c">#generateResolvConf = false</span>
</code></pre></div></div>
<h2 id="create-the-script">Create the script</h2>
<p>sudo vi vpn-dns.sh</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/bin/bash</span>
<span class="nb">echo</span> <span class="s2">"Getting current DNS servers, this takes a couple of seconds"</span>
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe <span class="nt">-Command</span> <span class="s1">'
$ErrorActionPreference="SilentlyContinue"
Get-NetAdapter -InterfaceDescription "Cisco AnyConnect*" | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses
Get-NetAdapter | ?{-not ($_.InterfaceDescription -like "Cisco AnyConnect*") } | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses
'</span> | <span class="se">\</span>
<span class="nb">awk</span> <span class="s1">'BEGIN { print "# Generated by vpn fix func on", strftime("%c"); print } { print "nameserver", $1 }'</span> | <span class="se">\</span>
<span class="nb">tr</span> <span class="nt">-d</span> <span class="s1">'\r'</span> | <span class="nb">sudo tee</span> /etc/resolv.conf
</code></pre></div></div>
<h2 id="make-it-executablerun-as-sudo">Make it executable/run as sudo</h2>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo chmod</span> +x vpn-dns.sh
</code></pre></div></div>
<h2 id="run-as-superuser">Run as superuser</h2>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>vpn-dns.sh
</code></pre></div></div>
<h2 id="set-interface-metric-in-admin-powershell">Set interface metric in admin PowerShell</h2>
<pre><code class="language-PowerShell">Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000
</code></pre>
<p>It can be restored:</p>
<pre><code class="language-PowerShell">Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 1
</code></pre>
<p>Sources:
<a href="https://www.frakkingsweet.com/automatic-dns-configuration-with-wsl-and-anyconnect-client/">https://www.frakkingsweet.com/automatic-dns-configuration-with-wsl-and-anyconnect-client/</a>
<a href="https://stackoverflow.com/questions/66444822/wsl-2-dns-is-not-working-with-vpn-connection-on-win-10">https://stackoverflow.com/questions/66444822/wsl-2-dns-is-not-working-with-vpn-connection-on-win-10</a></p>Tamás T. Dezsődezso.t.tamas@gmail.comWorkaround to overcome the DNS issue when using VPNShrink VirtualBox disk image2023-08-10T00:00:00+00:002023-08-10T00:00:00+00:00https://xsnpdngv.github.io/development/Shrink-VirtualBox-VDI<aside class="sidebar__right">
<nav class="toc">
<header><h4 class="nav__title"><i class="fa fa-file-text"></i> On This Page</h4></header>
<ul class="toc__menu" id="markdown-toc">
<li><a href="#nullify-free-space" id="markdown-toc-nullify-free-space">Nullify free space</a></li>
<li><a href="#if-remount-read-only-fails" id="markdown-toc-if-remount-read-only-fails">If remount read-only fails</a> <ul>
<li><a href="#to-recover-the-system" id="markdown-toc-to-recover-the-system">To “recover” the system:</a></li>
</ul>
</li>
<li><a href="#shutdown-the-guest-os-linux" id="markdown-toc-shutdown-the-guest-os-linux">Shutdown the Guest OS (Linux)</a></li>
<li><a href="#compact-vdi-with-vboxmanage-on-the-host" id="markdown-toc-compact-vdi-with-vboxmanage-on-the-host">Compact VDI with VBoxManage on the host</a></li>
</ul>
</nav>
</aside>
<h1 id="nullify-free-space">Nullify free space</h1>
<p>In the Linux Guest system:</p>
<ul>
<li>Log out from the gui</li>
<li>Open shell (e.g., Host Key + F2)</li>
<li>Nullify free space:</li>
</ul>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">dd </span><span class="k">if</span><span class="o">=</span>/dev/zero <span class="nv">of</span><span class="o">=</span>/var/tmp/bigemptyfile <span class="nv">bs</span><span class="o">=</span>4096k <span class="p">;</span> <span class="nb">rm</span> /var/tmp/bigemptyfile
</code></pre></div></div>
<p>Note that dd will use up all the free space</p>
<p>Or</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>telinit 1
mount <span class="nt">-o</span> remount,ro /dev/sda1
zerofree <span class="nt">-v</span> /dev/sda1
</code></pre></div></div>
<h1 id="if-remount-read-only-fails">If remount read-only fails</h1>
<p>Edit fstab to have the mount point in question mounted read-only by default</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>vi /etc/fstab
</code></pre></div></div>
<p>Make the appropriate entry ‘ro’</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/dev/sda1 / ext4 ro 0 1
</code></pre></div></div>
<p>Reboot and run <code class="language-plaintext highlighter-rouge">zerofree -v /dev/sda1</code> now</p>
<h2 id="to-recover-the-system">To “recover” the system:</h2>
<ul>
<li>Re-mount read-write: <code class="language-plaintext highlighter-rouge">mount -o remount,rw /dev/sda1</code></li>
<li>Edit <code class="language-plaintext highlighter-rouge">/etc/fstab</code> again to restore the original content</li>
</ul>
<h1 id="shutdown-the-guest-os-linux">Shutdown the Guest OS (Linux)</h1>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>shutdown <span class="nt">-h</span> now
</code></pre></div></div>
<h1 id="compact-vdi-with-vboxmanage-on-the-host">Compact VDI with VBoxManage on the host</h1>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd --compact "c:\path\to\linux-disk-image.vdi"
</code></pre></div></div>Tamás T. Dezsődezso.t.tamas@gmail.comProcess of making dynamically growing vdi image smaller.C Strict Aliasing2017-12-09T00:00:00+00:002017-12-09T00:00:00+00:00https://xsnpdngv.github.io/development/Strict-Aliasing<aside class="sidebar__right">
<nav class="toc">
<header><h4 class="nav__title"><i class="fa fa-file-text"></i> On This Page</h4></header>
<ul class="toc__menu" id="markdown-toc">
<li><a href="#aliasing" id="markdown-toc-aliasing">Aliasing</a></li>
<li><a href="#problem" id="markdown-toc-problem">Problem</a></li>
<li><a href="#strict-aliasing" id="markdown-toc-strict-aliasing">Strict Aliasing</a></li>
<li><a href="#solution" id="markdown-toc-solution">Solution</a> <ul>
<li><a href="#no-strict-aliasing" id="markdown-toc-no-strict-aliasing">No Strict Aliasing</a></li>
<li><a href="#strict-aliasing-conformance" id="markdown-toc-strict-aliasing-conformance">Strict Aliasing Conformance</a></li>
</ul>
</li>
</ul>
</nav>
</aside>
<h1 id="aliasing">Aliasing</h1>
<p>Aliasing in C is about to refer to the same memory space as different types,
that is, accessing a variable’s value through a pointer of another type.
Practically it means interpreting a variable’s representation in memory as if it
was the represenation of a variable of a different type. In C it is quite
often.</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">unsigned</span> <span class="kt">char</span> <span class="n">uc</span> <span class="o">=</span> <span class="mi">65</span><span class="p">;</span> <span class="c1">// ascii code of 'A'</span>
<span class="kt">char</span> <span class="o">*</span><span class="n">cp</span> <span class="o">=</span> <span class="p">(</span><span class="kt">char</span> <span class="o">*</span><span class="p">)</span><span class="o">&</span><span class="n">uc</span><span class="p">;</span> <span class="c1">// alias to uc</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%c"</span><span class="p">,</span> <span class="o">*</span><span class="n">cp</span><span class="p">);</span> <span class="c1">// prints 'A'</span>
</code></pre></div></div>
<p>The example above shows this technique and there is no problem with it. An
<code class="language-plaintext highlighter-rouge">unsigned char</code> is interpreted as a <code class="language-plaintext highlighter-rouge">char</code> and is printed out.</p>
<p>The example below is OK too. If the actual value is changed through the lvalue
of either <code class="language-plaintext highlighter-rouge">*cp</code> or <code class="language-plaintext highlighter-rouge">uc</code>, since they are “compatible” in terms of aliasing, the
compiler will be aware of the change no matter through which lvalue was it
done.</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">unsigned</span> <span class="kt">char</span> <span class="n">uc</span> <span class="o">=</span> <span class="mi">65</span><span class="p">;</span> <span class="c1">// ascii code of 'A'</span>
<span class="kt">char</span> <span class="o">*</span><span class="n">cp</span> <span class="o">=</span> <span class="p">(</span><span class="kt">char</span> <span class="o">*</span><span class="p">)</span><span class="o">&</span><span class="n">uc</span><span class="p">;</span> <span class="c1">// alias to uc</span>
<span class="n">uc</span><span class="o">++</span><span class="p">;</span> <span class="c1">// 'A' + 1 = 'B'</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%c"</span><span class="p">,</span> <span class="o">*</span><span class="n">cp</span><span class="p">);</span> <span class="c1">// prints 'B'</span>
</code></pre></div></div>
<p>The compiler will not suppose - even if it optimizies - that <code class="language-plaintext highlighter-rouge">*cp</code> remains
intact, while <code class="language-plaintext highlighter-rouge">uc</code> is changed. It will print ‘B’ correctly.</p>
<h1 id="problem">Problem</h1>
<p>If the same memory location is refferred through two incompatible types,
the compiler may think that the two lvalues are completely different,
they do not rely on each other, so if one is changed, the other will remain
intact.</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">long</span> <span class="n">a</span> <span class="o">=</span> <span class="mh">0x12345678</span><span class="p">;</span>
<span class="kt">short</span> <span class="o">*</span><span class="n">bp</span> <span class="o">=</span> <span class="p">(</span><span class="kt">short</span> <span class="o">*</span><span class="p">)</span><span class="o">&</span><span class="n">a</span><span class="p">;</span>
<span class="p">(</span><span class="o">*</span><span class="n">bp</span><span class="p">)</span><span class="o">++</span><span class="p">;</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%ld"</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
<span class="c1">// may print either the decimal value equal to 0x12345678 or 0x12355678</span>
<span class="c1">// (assuming straight byte order and little endiannes for the sake of simplicity)</span>
</code></pre></div></div>
<p>There are more problems with it. Referencing the address of <code class="language-plaintext highlighter-rouge">a</code> as if it would
be a short, covers only a part of its storage in memory. Assuming that long is
4 bytes and short is 2 (with straight byte order, little endian storage) the
memory looks as follows:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> +----+----+----+----+
|0x12|0x34|0x56|0x78| a long
+----+----+----+----+
^ ^
| |
+----+----+
|0x12|0x34| aliased as short
+----+----+
</code></pre></div></div>
<p>It is obvious that on architectures with different endiannes it results
completely different value, so it is absolutely not portable.</p>
<p>Even bigger problem is that the compiler may think that the two lvalues <code class="language-plaintext highlighter-rouge">a</code> and
<code class="language-plaintext highlighter-rouge">*bp</code> are completely different variables, because of their incompatible types,
and assumes that if one is changed the other remains intact. It actually turns
into problem, when the compiler tries to optimize.</p>
<h1 id="strict-aliasing">Strict Aliasing</h1>
<p>Strict aliasing is a concept on wich in certain circumstances the compiler can
rely on. It says, that even if two lvalues refer to the same memory location,
if their types are incompatible, there is no relation between them, they can
be handled absolutely independently. Relying on this rule/assumption the
compiler has an easier job on optimization.</p>
<p>Errors occur when compiler thinks this is the case and in real it is not.</p>
<h1 id="solution">Solution</h1>
<p>There are two possible solutions to avoid hard to find bugs resulting from
misunderstanding between the programmer and the compiler: Either making the
compiler be aware of that we are not that pedantic, so it’s better not to rely
on such assumption, Or just always being type correct.</p>
<h2 id="no-strict-aliasing">No Strict Aliasing</h2>
<p>The easier way is to let the compiler know that we ignore the Strict aliasing
rules, and make sure that it does not suppose that we are type correct. This
can be done by providing a flag to the compiler: <code class="language-plaintext highlighter-rouge">-fno-strict-aliasing</code>. Using
Makefile it should be added to <code class="language-plaintext highlighter-rouge">CFLAGS</code> and <code class="language-plaintext highlighter-rouge">CXXFLAGS</code> too.</p>
<p>This may be the best practice if dealing with legacy code. It secures
that the compiler will not make assumptions that it should not.</p>
<h2 id="strict-aliasing-conformance">Strict Aliasing Conformance</h2>
<p>The prettier way is to be type correct and do not ever refer to the same memory
location as different incompatible types.</p>
<p>In terms of strict aliasing the following types are compatible:</p>
<ul>
<li>
<p>Those that differ only in signedness (<code class="language-plaintext highlighter-rouge">signed</code>/<code class="language-plaintext highlighter-rouge">unsigned</code>) or in qualifiers
(e.g. <code class="language-plaintext highlighter-rouge">volatile</code>, <code class="language-plaintext highlighter-rouge">const</code>).</p>
</li>
<li>
<p>A struct or union type can alias types contained inside them,
e.g, an <code class="language-plaintext highlighter-rouge">int</code> can be aliased with a <code class="language-plaintext highlighter-rouge">union { int a; char b }</code>.</p>
</li>
</ul>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">typdef</span> <span class="k">union</span> <span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">c</span><span class="p">;</span>
<span class="p">}</span> <span class="n">union_t</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mh">0x12345678</span><span class="p">;</span>
<span class="n">union_t</span> <span class="o">*</span><span class="n">up</span> <span class="o">=</span> <span class="p">(</span><span class="n">union_t</span> <span class="o">*</span><span class="p">)</span><span class="o">&</span><span class="n">i</span><span class="p">;</span>
<span class="n">i</span> <span class="o">*=</span> <span class="mi">2</span><span class="p">;</span> <span class="c1">// it will surely affect *up too</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%c"</span><span class="p">,</span> <span class="n">up</span><span class="o">-></span><span class="n">c</span><span class="p">);</span>
</code></pre></div></div>
<ul>
<li>A character type (<code class="language-plaintext highlighter-rouge">char *</code>, <code class="language-plaintext highlighter-rouge">signed char *</code>, <code class="language-plaintext highlighter-rouge">unsigned char *</code>) can point
to (alias) any memory location.</li>
</ul>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">int</span> <span class="n">a</span> <span class="o">=</span> <span class="mh">0x12345678</span><span class="p">;</span>
<span class="kt">char</span> <span class="o">*</span><span class="n">cp</span> <span class="o">=</span> <span class="p">(</span><span class="kt">char</span> <span class="o">*</span><span class="p">)</span><span class="o">&</span><span class="n">a</span><span class="p">;</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%c"</span><span class="p">,</span> <span class="o">*</span><span class="n">cp</span><span class="p">);</span>
</code></pre></div></div>Tamás T. Dezsődezso.t.tamas@gmail.comMeaning and dangers of aliasing in C and solutions to avoid related bugs.Using the X11-clipboard in Vim2017-05-06T00:00:00+00:002017-05-06T00:00:00+00:00https://xsnpdngv.github.io/development/Vim-clipboard<aside class="sidebar__right">
<nav class="toc">
<header><h4 class="nav__title"><i class="fa fa-file-text"></i> On This Page</h4></header>
<ul class="toc__menu" id="markdown-toc">
<li><a href="#vim-support" id="markdown-toc-vim-support">Vim Support</a> <ul>
<li><a href="#linux" id="markdown-toc-linux">Linux</a></li>
<li><a href="#macos" id="markdown-toc-macos">MacOS</a> <ul>
<li><a href="#add-vim-feature" id="markdown-toc-add-vim-feature">Add Vim feature</a></li>
<li><a href="#use-macvim" id="markdown-toc-use-macvim">Use MacVim</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#vimrc" id="markdown-toc-vimrc">.vimrc</a></li>
<li><a href="#x11-forwarding" id="markdown-toc-x11-forwarding">X11 Forwarding</a></li>
<li><a href="#downside" id="markdown-toc-downside">Downside</a></li>
</ul>
</nav>
</aside>
<p>Vim operations like copying (<code class="language-plaintext highlighter-rouge">y</code>), deleting (<code class="language-plaintext highlighter-rouge">x</code>, <code class="language-plaintext highlighter-rouge">X</code>, <code class="language-plaintext highlighter-rouge">D</code>, <code class="language-plaintext highlighter-rouge">dd</code>), pasting
(<code class="language-plaintext highlighter-rouge">p</code>, <code class="language-plaintext highlighter-rouge">P</code>) by default use an inner register which is not related to the
clipboard, so these operations cannot interwork neither with the system’s other
applications nor with Vim’s other instances. Though, it is possible to relate
this two to each other, doing so might not be straightforward and obvious.</p>
<p>The key concept here is to make Vim to use the X11-clipboard as the unnamed
register to which it saves what has been yanked (copied), deleted or changed, so
another program even other Vim instance can access it to be pasted.</p>
<h1 id="vim-support">Vim Support</h1>
<p>This can only be done, if Vim has support for <code class="language-plaintext highlighter-rouge">+clipboard</code> feature which can be
checked with</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>vim <span class="nt">--version</span> | <span class="nb">grep </span>clipboard
</code></pre></div></div>
<p>If there is a <code class="language-plaintext highlighter-rouge">-clipboard</code> (with the minus sign), then the feature is not supported.</p>
<h2 id="linux">Linux</h2>
<p>On Linux, packages like <code class="language-plaintext highlighter-rouge">vim-gnome</code> and <code class="language-plaintext highlighter-rouge">vim-gtk</code> have this feature
included, so installing any of them should solve this issue e.g.,</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt-get <span class="nb">install </span>vim-gnome
</code></pre></div></div>
<h2 id="macos">MacOS</h2>
<p>On MacOS, there are two ways to make the option available and working.</p>
<h3 id="add-vim-feature">Add Vim feature</h3>
<p>Brewing Vim with <code class="language-plaintext highlighter-rouge">--with-client-server</code> option will let the feature fairly work, but
requires <code class="language-plaintext highlighter-rouge">XQuartz</code> running because it needs the X11 forwarding protocol to access the
clipboard. If it is not running when opening Vim for the first time, it will be
started automatically but it takes a while. Moreover, the solution is not complete.
Though, the copy-paste between instances of Vim works fine, interaction with OS-X’s
native applications will work only after starting an <code class="language-plaintext highlighter-rouge">XQuartz</code> application, like a
terminal.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># install Vim with +clipboard support</span>
brew <span class="nb">install </span>vim <span class="nt">--with-client-server</span>
</code></pre></div></div>
<p>After installing, remember to check if the new version is executed:
<code class="language-plaintext highlighter-rouge">which vi</code>, <code class="language-plaintext highlighter-rouge">which vim</code>. If not, set <code class="language-plaintext highlighter-rouge">PATH</code> or add <code class="language-plaintext highlighter-rouge">alias</code> in profile accordingly.</p>
<h3 id="use-macvim">Use MacVim</h3>
<p>Brewing MacVim in a way to override system Vim will give a better result. This
will not require <code class="language-plaintext highlighter-rouge">XQuartz</code> for any reason, and is able to access the system
clipboard in a native way, without X11 (which is not used by default in MacOS).</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># install MacVim to support clipboard in a native way</span>
brew <span class="nb">install </span>macvim <span class="nt">--with-override-system-vim</span>
</code></pre></div></div>
<p>Installing MacVim this way is intended to substitute the system Vim, so probably
this will be the default for <code class="language-plaintext highlighter-rouge">vi</code> or <code class="language-plaintext highlighter-rouge">vim</code> after it’s done.</p>
<h1 id="vimrc">.vimrc</h1>
<p>If the clipboard is available, assign the <code class="language-plaintext highlighter-rouge">unnamed</code> and <code class="language-plaintext highlighter-rouge">unnamedplus</code> registers
to it as seen below. Ddepending on the system, it varies which is the better,
so having both set is a good approach. Adding <code class="language-plaintext highlighter-rouge">autoselect</code> also to the
clipboard makes visual Vim selections automatically be available to paste,
without the need to e.g., copy them. See <code class="language-plaintext highlighter-rouge">:help clipboard</code> for more
information.</p>
<div class="language-vimscript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="nb">has</span><span class="p">(</span><span class="s1">'clipboard'</span><span class="p">)</span>
<span class="k">set</span> <span class="nb">clipboard</span><span class="p">=</span>unnamed<span class="p">,</span>unnamedplus<span class="p">,</span>autoselect
<span class="k">endif</span>
</code></pre></div></div>
<h1 id="x11-forwarding">X11 Forwarding</h1>
<p>Since the clipboard belongs to the windowing system, in case of remote
sessions it requires X11 forwarding, even for pure terminal use. Using ssh
with option -Y will do it. For example connecting to a Linux running in the
virtual machine would look like below.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ssh <span class="nt">-Y</span> <span class="nt">-p</span> 2222 ubuntu@localhost
</code></pre></div></div>
<p>In order to make this kind of connection acceptable for a <strong>Vagrant</strong> virtual
machine, add the following to the <code class="language-plaintext highlighter-rouge">Vagrantfile</code>.</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># If true, X11 forwarding over SSH connections is enabled. Defaults to false.</span>
<span class="n">config</span><span class="p">.</span><span class="nf">ssh</span><span class="p">.</span><span class="nf">forward_x11</span> <span class="o">=</span> <span class="kp">true</span>
</code></pre></div></div>
<p>If <strong>MacOS</strong> is the host machine, so it runs the X server (<code class="language-plaintext highlighter-rouge">XQuartz</code>), then it
should have all options enabled under <em>Preferences</em> > <em>Pasteboard</em> to have the
feature surely work.</p>
<h1 id="downside">Downside</h1>
<p>Even without assigning the unnamed register to the X11-clipboard, when X11 forwarding
is active, Vim connects to it (except for MacVim). A slow remote connection might cause
Vim to connect to the clipboard very slowly, so it results noticable delay in starting.
In such annoying cases it might be better to make Vim not to connect to the clipboard.</p>
<div class="language-vimscript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">set</span> <span class="nb">clipboard</span><span class="p">=</span>exclude<span class="p">:.</span>*
</code></pre></div></div>Tamás T. Dezsődezso.t.tamas@gmail.comStep-by-step guide on how to assign the clipboard to Vim in order to use it by default for copying and pasting operationsProfiling with Callgrind2017-04-28T00:00:00+00:002017-04-28T00:00:00+00:00https://xsnpdngv.github.io/development/Callgrind<p>Callgrind is a profiling tool that can be used via the
<a href="http://valgrind.org/">Valgrind</a>
framework and its report can be displayed/inspected with the
<a href="https://kcachegrind.github.io/">KCachegrind</a>
profile data visualization tool.</p>
<p>When you use Callgrind to profile a program, the program is transformed into an
intermediate format and then is run in a virtual processor emulated by valgrind.
That makes possible to keep track of operations and that makes the program
run much more slower than otherwise.</p>
<h2 id="install">Install</h2>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt-get <span class="nb">install </span>valgrind kcachegrind graphviz
</code></pre></div></div>
<h2 id="prepare">Prepare</h2>
<p>Not necessarily required but useful to have the debugging information in the binary
so if it’s possible compile with the -g option.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gcc <span class="nt">-g</span> <span class="nt">-o</span> program program.c
</code></pre></div></div>
<h2 id="profile">Profile</h2>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># check options</span>
man valgrind
<span class="c"># profile</span>
valgrind <span class="nt">--tool</span><span class="o">=</span>callgrind <program> <span class="o">[</span>program-options]
<span class="c"># profile with additional options e.g.</span>
valgrind <span class="nt">--tool</span><span class="o">=</span>callgrind <span class="nt">--dump-instr</span><span class="o">=</span><span class="nb">yes</span> <span class="nt">--simulate-cache</span><span class="o">=</span><span class="nb">yes</span> <span class="nt">--collect-jumps</span><span class="o">=</span><span class="nb">yes</span> <program> <span class="o">[</span>program-options]
</code></pre></div></div>
<p>For more details on Callgrind’s features and way of working, it’s worth checking out its
<a href="http://valgrind.org/docs/manual/cl-manual.html">site</a>.</p>
<h2 id="inspect">Inspect</h2>
<p>KCahcegrind is a graphical program and its interface is quite self-explanatory.
If it is run from the directory where Callgrind just stored its reports into, it opens
those by default.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>kcachegrind &
</code></pre></div></div>Tamás T. Dezsődezso.t.tamas@gmail.comCallgrind is a profiling tool that can be used via the Valgrind framework and its report can be displayed/inspected with the KCachegrind profile data visualization tool.Installing Chromium OS2016-07-20T00:00:00+00:002016-07-20T00:00:00+00:00https://xsnpdngv.github.io/development/Chromium-OS<aside class="sidebar__right">
<nav class="toc">
<header><h4 class="nav__title"><i class="fa fa-file-text"></i> On This Page</h4></header>
<ul class="toc__menu" id="markdown-toc">
<li><a href="#considerables" id="markdown-toc-considerables">Considerables</a></li>
<li><a href="#download" id="markdown-toc-download">Download</a></li>
<li><a href="#prepare" id="markdown-toc-prepare">Prepare</a></li>
<li><a href="#install" id="markdown-toc-install">Install</a></li>
</ul>
</nav>
</aside>
<p><a href="http://www.neverware.com">NeverWare</a> has built a Chromium OS based image to be
easily installed, named CloudReady. Its home edition is free. It is available
for both 32 and 64 bit. The image will work on most machines.</p>
<h1 id="considerables">Considerables</h1>
<ul>
<li>
<p>Boot options: Dual boot with Windows (>XP), or Standalone.</p>
</li>
<li>
<p>Users: The user added at first is going to be the owner of the install, so it
cannot be removed. Another users can be added too but those can be easily
removed too.</p>
</li>
<li>
<p>Local storage: Everything under <code class="language-plaintext highlighter-rouge">Downloads</code> is locally stored. The whole
content of the local storage is encrypted, so one does not simply put out the
HDD and access its content.</p>
</li>
<li>
<p>Media: Adobe flash and MP3 codecs can be easily added in the settings. After
doing so music can be played with built in player.</p>
</li>
<li>
<p>Photos: Image viewer also works at a glance, even editing is available.
However the Gallery application works quite slow on limited hardware, while
e.g., browsing is surprisingly fast.</p>
</li>
<li>
<p>Development: In Chromium OS developer mode (which is the default in case of
CloudReady), e.g., Ubuntu can be easily installed and <code class="language-plaintext highlighter-rouge">chroot</code>-ed by using
<a href="https://github.com/dnschneid/crouton">crouton</a>, even with the whole Unity
Graphical Interface.</p>
</li>
</ul>
<h1 id="download">Download</h1>
<p>Download NeverWare’s CloudReady <a href="https://www.neverware.com/freedownload">image</a>
and Unzip the file to have <code class="language-plaintext highlighter-rouge">chromiumos_image.bin</code>.</p>
<h1 id="prepare">Prepare</h1>
<p>Plug a >=8GB USB flash disk and determine which device it became:
<code class="language-plaintext highlighter-rouge">sudo fdisk -l</code></p>
<p>For Windows and Mac there is a Chrome extension: <a href="https://chrome.google.com/webstore/detail/chromebook-recovery-utili/jndclpdbaamdhonoechobihbbiimdgai?hl=en">Chromebook Recovery
Utility</a>
with which the image can be written to flash drive.</p>
<p>For Linux <code class="language-plaintext highlighter-rouge">dd</code> is there to do it so. Write the file directly to device (change
<code class="language-plaintext highlighter-rouge">/dev/sdX</code> to the identified device id)</p>
<p><code class="language-plaintext highlighter-rouge">dd if=chromiumos_image.bin of=/dev/sdX bs=4M</code></p>
<p>Unmount and remove the flash drive.</p>
<h1 id="install">Install</h1>
<p>Boot from the flash drive on the target machine, and try as Guest to see how
it’s doing. Install if it seems fine.</p>
<p>Two boot options are available:</p>
<ul>
<li>
<p>Standalone: the whole disk will be erased and repartitioned.</p>
</li>
<li>
<p>Dual boot with Windows: keeps the windows install and occupies the residual
space.</p>
</li>
</ul>Tamás T. Dezsődezso.t.tamas@gmail.comPros and contras of having Chromiom OS installed, and detailed instructions on how to do so.