<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.4">Jekyll</generator><link href="http://wensheng.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="http://wensheng.github.io/" rel="alternate" type="text/html" /><updated>2024-02-10T00:40:45+00:00</updated><id>http://wensheng.github.io/feed.xml</id><title type="html">Wensheng</title><subtitle>乱七八糟的东西，主要是编程
</subtitle><author><name>Wensheng</name></author><entry><title type="html">Installing LunarVim with Github Copilot on Ubuntu 22.04 via Putty</title><link href="http://wensheng.github.io/2023/04/01/lunarvim-copilot-ubuntu.html" rel="alternate" type="text/html" title="Installing LunarVim with Github Copilot on Ubuntu 22.04 via Putty" /><published>2023-04-01T00:00:00+00:00</published><updated>2023-04-01T00:00:00+00:00</updated><id>http://wensheng.github.io/2023/04/01/lunarvim-copilot-ubuntu</id><content type="html" xml:base="http://wensheng.github.io/2023/04/01/lunarvim-copilot-ubuntu.html"><![CDATA[<p>I spent several hours setting up this combo on my home server, it’s finally working.</p>

<p>My home server is running Ubuntu 22.04, I access it remotely with Putty.  I can technically hook up a keyboard/mouse/monitor and install a window manager then just set everything up the desktop way but I was too lazy to do that.</p>

<h2 id="neovim">NeoVim</h2>

<p>Do not use <code class="language-plaintext highlighter-rouge">sudo apt install</code>, it will install an older version of NeoVim.  Instead download appimage from github, then unpack it and copy it to /usr/local.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># download nvim.appimage from github
./nvim.appimage --appimage-extract
sudo cp -rp squashfs-root/usr/* /usr/local/
</code></pre></div></div>

<p>Test with nvim to confirm it is installed.</p>

<h2 id="lunarvim">LunarVim</h2>

<p>Just copy the installation command from <a href="https://www.lunarvim.org/docs/installation">https://www.lunarvim.org/docs/installation</a> and run it.  Answer yes when prompted.</p>

<p>Launch lvim to verify.</p>

<h2 id="github-copilot">Github Copilot</h2>

<p>While in lvim dashboard (default with no file), press ‘c’ for configuration file.  This will edit <code class="language-plaintext highlighter-rouge">~/.config/lvim/config.lua</code>, add:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lvim.plugins = {
    {
      "github/copilot.vim",
    },
}
vim.g.copilot_no_tab_map = true
vim.g.copilot_assume_mapped = true
vim.g.copilot_tab_fallback = ""
local cmp = require "cmp"
lvim.builtin.cmp.mapping["&lt;Tab&gt;"] = function(fallback)
  if cmp.visible() then
    cmp.select_next_item()
  else
    local copilot_keys = vim.fn["copilot#Accept"]()
    if copilot_keys ~= "" then
      vim.api.nvim_feedkeys(copilot_keys, "i", true)
    else
      fallback()
    end
  end
end
</code></pre></div></div>

<p>to (near the end of) the file.</p>

<p>Then do a <code class="language-plaintext highlighter-rouge">:Copilot setup</code>, this will be un-successful because it will try to connect to Github via browser.  But I was connected to the server with ssh and don’t have any browser on my server.  See Next step.</p>

<h2 id="browser">Browser</h2>

<p>To run a GUI I need to run an X server.  I use XMing on Windows. I have to enable X11 forwarding (in Connection-SSH-X11) in Putty.  I run xclock to verify it works.  Now all I have to do is install a browser on the server.</p>

<p>It should be simple right? Just <code class="language-plaintext highlighter-rouge">sudo apt install firefox</code>.  However the browser installed this way will not work. For some reason it can not connect to X server locally.</p>

<p>When using <code class="language-plaintext highlighter-rouge">apt install</code>, both firefox and Chromium will be installed from Snap, I got so confused and mad I completely deleted snap from my server.</p>

<p>I installed firefox with mozilla ppa (just google non-snap firefox), it successfully run on my windows, but it’s so slow it’s unusable.</p>

<p>I ended up donwload chrome from <a href="https://www.google.com/chrome/?platform=linux">google</a> (actualy get the link by copy link from downloaded file in Windows Chrome then wget the link).  It finally worked fine.</p>

<p>Inside lvim, do <code class="language-plaintext highlighter-rouge">:Copilot seteup</code> again, everthing was set up.</p>]]></content><author><name>Wensheng</name></author><summary type="html"><![CDATA[I spent several hours setting up this combo on my home server, it’s finally working. My home server is running Ubuntu 22.04, I access it remotely with Putty. I can technically hook up a keyboard/mouse/monitor and install a window manager then just set everything up the desktop way but I was too lazy to do that. NeoVim Do not use sudo apt install, it will install an older version of NeoVim. Instead download appimage from github, then unpack it and copy it to /usr/local. # download nvim.appimage from github ./nvim.appimage --appimage-extract sudo cp -rp squashfs-root/usr/* /usr/local/ Test with nvim to confirm it is installed. LunarVim Just copy the installation command from https://www.lunarvim.org/docs/installation and run it. Answer yes when prompted. Launch lvim to verify. Github Copilot While in lvim dashboard (default with no file), press ‘c’ for configuration file. This will edit ~/.config/lvim/config.lua, add: lvim.plugins = { { "github/copilot.vim", }, } vim.g.copilot_no_tab_map = true vim.g.copilot_assume_mapped = true vim.g.copilot_tab_fallback = "" local cmp = require "cmp" lvim.builtin.cmp.mapping["&lt;Tab&gt;"] = function(fallback) if cmp.visible() then cmp.select_next_item() else local copilot_keys = vim.fn["copilot#Accept"]() if copilot_keys ~= "" then vim.api.nvim_feedkeys(copilot_keys, "i", true) else fallback() end end end to (near the end of) the file. Then do a :Copilot setup, this will be un-successful because it will try to connect to Github via browser. But I was connected to the server with ssh and don’t have any browser on my server. See Next step. Browser To run a GUI I need to run an X server. I use XMing on Windows. I have to enable X11 forwarding (in Connection-SSH-X11) in Putty. I run xclock to verify it works. Now all I have to do is install a browser on the server. It should be simple right? Just sudo apt install firefox. However the browser installed this way will not work. For some reason it can not connect to X server locally. When using apt install, both firefox and Chromium will be installed from Snap, I got so confused and mad I completely deleted snap from my server. I installed firefox with mozilla ppa (just google non-snap firefox), it successfully run on my windows, but it’s so slow it’s unusable. I ended up donwload chrome from google (actualy get the link by copy link from downloaded file in Windows Chrome then wget the link). It finally worked fine. Inside lvim, do :Copilot seteup again, everthing was set up.]]></summary></entry><entry><title type="html">EC2 Azure GCP reserved VM price comparison</title><link href="http://wensheng.github.io/2020/01/23/ec2-azure-gcp-reserved.html" rel="alternate" type="text/html" title="EC2 Azure GCP reserved VM price comparison" /><published>2020-01-23T00:00:00+00:00</published><updated>2020-01-23T00:00:00+00:00</updated><id>http://wensheng.github.io/2020/01/23/ec2-azure-gcp-reserved</id><content type="html" xml:base="http://wensheng.github.io/2020/01/23/ec2-azure-gcp-reserved.html"><![CDATA[<p>I was looking for a small virtual machine (or VPS virtual private server) for development.  Normally I would go with either digitalocean or linode.  Their prices are the same: $10 per month for 2GB vm and $20 for 4GB.  Because I know I will be using this VM for more than a year, I started look into the VM’s that offered by big 3 cloud providers with long term discount.</p>

<p>Below are the findings.</p>

<h2 id="amazon-ec2">Amazon EC2</h2>

<table>
  <thead>
    <tr>
      <th>type</th>
      <th>cpu/ram</th>
      <th>term</th>
      <th>price</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>t3a.micro</td>
      <td>2cpu 1GB</td>
      <td>standard 3-year all-upfront</td>
      <td>$93 ($2.58/Mon)</td>
    </tr>
    <tr>
      <td>t3a.small</td>
      <td>2cpu 2GB</td>
      <td>standard 3-year all-upfront</td>
      <td>$186 ($5.16/Mon)</td>
    </tr>
    <tr>
      <td>t3a.medium</td>
      <td>2cpu 4GB</td>
      <td>standard 3-year all-upfront</td>
      <td>$372 ($10.33/Mon)</td>
    </tr>
  </tbody>
</table>

<p>Note price is for us-east-1 region.  Different regions has different price, for example, for northern-California region (us-west-1) t3a.medium costs $509 for 3-year all-upfront, for Tokyo region (ap-northeast-1), t3a.medium costs $553 for 3-year all-upfront. us-east-2, us-west-2 have the same price as us-east-1.</p>

<p>Also note t3a use AMD cpu’s, t2 and t3 use Intel cpu’s and are more expensive.  But in real world application it shouldn’t make much a difference.</p>

<h2 id="azure-vm">Azure VM</h2>

<table>
  <thead>
    <tr>
      <th>type</th>
      <th>cpu/ram</th>
      <th>term</th>
      <th>price</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>B1S</td>
      <td>1cpu 1GB</td>
      <td>3-year</td>
      <td>$3.50/Mon</td>
    </tr>
    <tr>
      <td>B1MS</td>
      <td>1cpu 2GB</td>
      <td>3-year</td>
      <td>$7.69/Mon</td>
    </tr>
    <tr>
      <td>B2S</td>
      <td>2cpu 4GB</td>
      <td>3-year</td>
      <td>$13.77/Mon</td>
    </tr>
  </tbody>
</table>

<h2 id="gcp-compute-engine-vm-committed-use">GCP Compute Engine VM Committed use</h2>

<table>
  <thead>
    <tr>
      <th>type</th>
      <th>cpu/ram</th>
      <th>term</th>
      <th>price</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>N1</td>
      <td>1cpu 2GB</td>
      <td>3-year</td>
      <td>$15.82/Mon</td>
    </tr>
    <tr>
      <td>N1</td>
      <td>1cpu 4GB</td>
      <td>3-year</td>
      <td>$19.16/Mon</td>
    </tr>
  </tbody>
</table>

<p>Looks like AWS has best price if you just want a 2-4GB VM without considering other factors.</p>]]></content><author><name>Wensheng</name></author><summary type="html"><![CDATA[I was looking for a small virtual machine (or VPS virtual private server) for development. Normally I would go with either digitalocean or linode. Their prices are the same: $10 per month for 2GB vm and $20 for 4GB. Because I know I will be using this VM for more than a year, I started look into the VM’s that offered by big 3 cloud providers with long term discount. Below are the findings. Amazon EC2 type cpu/ram term price t3a.micro 2cpu 1GB standard 3-year all-upfront $93 ($2.58/Mon) t3a.small 2cpu 2GB standard 3-year all-upfront $186 ($5.16/Mon) t3a.medium 2cpu 4GB standard 3-year all-upfront $372 ($10.33/Mon) Note price is for us-east-1 region. Different regions has different price, for example, for northern-California region (us-west-1) t3a.medium costs $509 for 3-year all-upfront, for Tokyo region (ap-northeast-1), t3a.medium costs $553 for 3-year all-upfront. us-east-2, us-west-2 have the same price as us-east-1. Also note t3a use AMD cpu’s, t2 and t3 use Intel cpu’s and are more expensive. But in real world application it shouldn’t make much a difference. Azure VM type cpu/ram term price B1S 1cpu 1GB 3-year $3.50/Mon B1MS 1cpu 2GB 3-year $7.69/Mon B2S 2cpu 4GB 3-year $13.77/Mon GCP Compute Engine VM Committed use type cpu/ram term price N1 1cpu 2GB 3-year $15.82/Mon N1 1cpu 4GB 3-year $19.16/Mon Looks like AWS has best price if you just want a 2-4GB VM without considering other factors.]]></summary></entry><entry><title type="html">Install Taskwarrior server and client on Ubuntu</title><link href="http://wensheng.github.io/2018/04/23/taskwarrior.html" rel="alternate" type="text/html" title="Install Taskwarrior server and client on Ubuntu" /><published>2018-04-23T00:00:00+00:00</published><updated>2018-04-23T00:00:00+00:00</updated><id>http://wensheng.github.io/2018/04/23/taskwarrior</id><content type="html" xml:base="http://wensheng.github.io/2018/04/23/taskwarrior.html"><![CDATA[<p>On Ubuntu &gt;16.04, installing Taskwarrior client is simply:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt install task
</code></pre></div></div>

<p>But you need a taskwarrior server to sync from clients.  Follow these steps to set up a Taskwarrior server.</p>

<ol>
  <li>
    <p>install dependencies:</p>

    <p>sudo apt install cmake uuid-dev libgmp-dev libreadline-dev</p>
  </li>
  <li>
    <p>clone, compile, install taskwarrior:</p>

    <p>git clone –recurse-submodules https://github.com/GothenburgBitFactory/taskserver.git
 cd taskserver/
 cmake -DCMAKE_BUILD_TYPE=release .
 make
 sudo make install</p>
  </li>
  <li>
    <p>configure task server:</p>

    <p>mkdir ~/taskd_data
 export TASKDDATA=~/taskd_data
 taskd init
 # we are still in taskserver directory from step 2
 cd pki
 vi vars</p>

    <p>Here change CN from “localhost” to your domain name or IP. Assume we used “your_server”.</p>

    <p>./generate
 cp client.cert.pem $TASKDDATA
 cp client.key.pem  $TASKDDATA
 cp server.cert.pem $TASKDDATA
 cp server.key.pem  $TASKDDATA
 cp server.crl.pem  $TASKDDATA
 cp ca.cert.pem     $TASKDDATA
 taskd config –force client.cert $TASKDDATA/client.cert.pem
 taskd config –force client.key $TASKDDATA/client.key.pem
 taskd config –force server.cert $TASKDDATA/server.cert.pem
 taskd config –force server.key $TASKDDATA/server.key.pem
 taskd config –force server.crl $TASKDDATA/server.crl.pem
 taskd config –force ca.cert $TASKDDATA/ca.cert.pem
 taskd config –force log $TASKDDATA/taskd.log
 taskd config –force pid.file $TASKDDATA/taskd.pid
 taskd config –force server your_server:53589  # change “your_server” to your real server</p>
  </li>
  <li>
    <p>Start task server</p>

    <p>taskdctl start  # if it’s already started, just do restart
 taskdctl status   # show if it’s running</p>
  </li>
  <li>
    <p>Create user</p>

    <p># we are still in taskserver/pki directory
 taskd add org Public
 taskd add user ‘Public’ ‘yourname’  # yourname is your username</p>
  </li>
</ol>

<p>Now that the server is installed, we need to configure our clients to use this server.</p>]]></content><author><name>Wensheng</name></author><summary type="html"><![CDATA[On Ubuntu &gt;16.04, installing Taskwarrior client is simply: sudo apt install task But you need a taskwarrior server to sync from clients. Follow these steps to set up a Taskwarrior server. install dependencies: sudo apt install cmake uuid-dev libgmp-dev libreadline-dev clone, compile, install taskwarrior: git clone –recurse-submodules https://github.com/GothenburgBitFactory/taskserver.git cd taskserver/ cmake -DCMAKE_BUILD_TYPE=release . make sudo make install configure task server: mkdir ~/taskd_data export TASKDDATA=~/taskd_data taskd init # we are still in taskserver directory from step 2 cd pki vi vars Here change CN from “localhost” to your domain name or IP. Assume we used “your_server”. ./generate cp client.cert.pem $TASKDDATA cp client.key.pem $TASKDDATA cp server.cert.pem $TASKDDATA cp server.key.pem $TASKDDATA cp server.crl.pem $TASKDDATA cp ca.cert.pem $TASKDDATA taskd config –force client.cert $TASKDDATA/client.cert.pem taskd config –force client.key $TASKDDATA/client.key.pem taskd config –force server.cert $TASKDDATA/server.cert.pem taskd config –force server.key $TASKDDATA/server.key.pem taskd config –force server.crl $TASKDDATA/server.crl.pem taskd config –force ca.cert $TASKDDATA/ca.cert.pem taskd config –force log $TASKDDATA/taskd.log taskd config –force pid.file $TASKDDATA/taskd.pid taskd config –force server your_server:53589 # change “your_server” to your real server Start task server taskdctl start # if it’s already started, just do restart taskdctl status # show if it’s running Create user # we are still in taskserver/pki directory taskd add org Public taskd add user ‘Public’ ‘yourname’ # yourname is your username Now that the server is installed, we need to configure our clients to use this server.]]></summary></entry><entry><title type="html">Migrate Gitlab to New Server</title><link href="http://wensheng.github.io/2017/07/25/migrate-gitlab-to-new-server.html" rel="alternate" type="text/html" title="Migrate Gitlab to New Server" /><published>2017-07-25T00:00:00+00:00</published><updated>2017-07-25T00:00:00+00:00</updated><id>http://wensheng.github.io/2017/07/25/migrate-gitlab-to-new-server</id><content type="html" xml:base="http://wensheng.github.io/2017/07/25/migrate-gitlab-to-new-server.html"><![CDATA[<p>I recently migrated my <a href="https://about.gitlab.com/">Gitlab</a> to a new server, here are the steps and gotchas that I took notes for future references.</p>

<p>The source and target server need to run the same version of Gitlab.</p>

<p>back-up</p>

<p>restore</p>

<p>change /etc/gitlab/gitlab.rb,</p>

<p>change 8080, to 8082</p>

<p>change</p>]]></content><author><name>Wensheng</name></author><summary type="html"><![CDATA[I recently migrated my Gitlab to a new server, here are the steps and gotchas that I took notes for future references. The source and target server need to run the same version of Gitlab. back-up restore change /etc/gitlab/gitlab.rb, change 8080, to 8082 change]]></summary></entry><entry><title type="html">apeflac2mp3</title><link href="http://wensheng.github.io/2017/07/13/apeflac2mp3.html" rel="alternate" type="text/html" title="apeflac2mp3" /><published>2017-07-13T00:00:00+00:00</published><updated>2017-07-13T00:00:00+00:00</updated><id>http://wensheng.github.io/2017/07/13/apeflac2mp3</id><content type="html" xml:base="http://wensheng.github.io/2017/07/13/apeflac2mp3.html"><![CDATA[<p><a href="https://github.com/wensheng/apeflac2mp3">apeflac2mp3</a> is a Python script I wrote to bulk convert APE, FLAC or other music files to mp3.</p>

<p>I have a lot of musics in APE and FLAC formats, for example this gem: <code class="language-plaintext highlighter-rouge">Mozart Complete Works [Brilliant] 170 CDs</code>.  It has 170 FLAC files, one for each CD. Each FLAC file also have a <code class="language-plaintext highlighter-rouge">cue</code> file that tells title and start time for every tracks in the FLAC file.</p>

<p>Convert them manually will take a lot of time.  I’m sure there are bulk converters for this type of task, but I just could not find any.  So I wrote it.  It basically use <a href="https://ffmpeg.zeranoe.com/builds/">ffmpeg</a> to do the conversion.  The bulk of cue parsing code is from <a href="https://gist.github.com/bancek/b37b780292540ed2d17d">this gist</a>.</p>

<p>With it, I converted 170 CD Mozart library to a directory that contains 2215 MP3 files. The size of original FLAC files is 42GB, it was reduced to 8GB in MP3 format.</p>

<p>For <code class="language-plaintext highlighter-rouge">Chopin The Complete Works 16CD</code>, I got 258 MP3 files with a total size of only 1GB.</p>]]></content><author><name>Wensheng</name></author><summary type="html"><![CDATA[apeflac2mp3 is a Python script I wrote to bulk convert APE, FLAC or other music files to mp3. I have a lot of musics in APE and FLAC formats, for example this gem: Mozart Complete Works [Brilliant] 170 CDs. It has 170 FLAC files, one for each CD. Each FLAC file also have a cue file that tells title and start time for every tracks in the FLAC file. Convert them manually will take a lot of time. I’m sure there are bulk converters for this type of task, but I just could not find any. So I wrote it. It basically use ffmpeg to do the conversion. The bulk of cue parsing code is from this gist. With it, I converted 170 CD Mozart library to a directory that contains 2215 MP3 files. The size of original FLAC files is 42GB, it was reduced to 8GB in MP3 format. For Chopin The Complete Works 16CD, I got 258 MP3 files with a total size of only 1GB.]]></summary></entry><entry><title type="html">Installing Streisand on Linode</title><link href="http://wensheng.github.io/2017/07/12/installing-streisand.html" rel="alternate" type="text/html" title="Installing Streisand on Linode" /><published>2017-07-12T00:00:00+00:00</published><updated>2017-07-12T00:00:00+00:00</updated><id>http://wensheng.github.io/2017/07/12/installing-streisand</id><content type="html" xml:base="http://wensheng.github.io/2017/07/12/installing-streisand.html"><![CDATA[<p><a href="https://github.com/jlund/streisand">Streisand</a> is a set of <a href="https://github.com/ansible/ansible">Ansible</a> playbooks that set up a VPN automatically.</p>

<p>It can create a new virtual machine on one of the cloud providers, such as Linode, from a remote server.  Since I already have a spare Linode, I decided to set up Streisand on that server <code class="language-plaintext highlighter-rouge">locally</code>.  Streisand run only on Ubuntu 16.04, my linode is 16.04 so it’s all good.</p>

<p>Streisand installation requires AppArmor enabled in the kernel.  The custom kernel by Linode does not have apparmor.  I have to edit the linode profile and change the kernel to <code class="language-plaintext highlighter-rouge">GRUB 2</code> (so it will pick the kernel that comes with the distro), reboot and verify apparmor is enabled by <code class="language-plaintext highlighter-rouge">sudo apparmor_status</code>.</p>

<p>Then install the dependencies:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt install libssl-dev
sudo pip install ansible markupsafe linode-python
</code></pre></div></div>

<p>Get Streisand:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://github.com/jlund/streisand.git 
cd streisand
</code></pre></div></div>

<p>Install Streisand:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo su
./streisand
</code></pre></div></div>

<p>Select <code class="language-plaintext highlighter-rouge">localhost (Advanced)</code> as provider, then wait for the setup to complete, it should take about 10-15 minutes.</p>

<p>If the installation is successful, a folder called <code class="language-plaintext highlighter-rouge">generated-docs</code> will be created, inside it are the directions (in html format) for setting up clients.</p>

<p>First download and install the SSL certificate by following the instruction in the html file. Then following the instructions in <code class="language-plaintext highlighter-rouge">Connecting to your Streisand Gateway</code> section at the bottom of that page.</p>

<p>Open the website from that page, enter the usename and password, we are presented with <code class="language-plaintext highlighter-rouge">Connection Instructions</code>.  There are several clients to choose from.  I chose OpenVPN(direct) since it’s simple.</p>

<p>Download OpenVPN windows installer, install and run OpenVPN.  Download of the OpenVPN profiles from the web page, I just chose the first: <code class="language-plaintext highlighter-rouge">client-1</code>.  Right click OpenVPN taskbar icon and select <code class="language-plaintext highlighter-rouge">Import file...</code> and import the profile that’s just downloaded.  Then right click again and select <code class="language-plaintext highlighter-rouge">Connect</code>.  Now we should be connected to our VPN.  Go to <a href="https://www.whatismyip.com/">whatismyip.com</a> to verify, the IP address it detected should be the IP of the streisand server.  Disconnect and the IP detected will be back to the real IP.</p>]]></content><author><name>Wensheng</name></author><summary type="html"><![CDATA[Streisand is a set of Ansible playbooks that set up a VPN automatically. It can create a new virtual machine on one of the cloud providers, such as Linode, from a remote server. Since I already have a spare Linode, I decided to set up Streisand on that server locally. Streisand run only on Ubuntu 16.04, my linode is 16.04 so it’s all good. Streisand installation requires AppArmor enabled in the kernel. The custom kernel by Linode does not have apparmor. I have to edit the linode profile and change the kernel to GRUB 2 (so it will pick the kernel that comes with the distro), reboot and verify apparmor is enabled by sudo apparmor_status. Then install the dependencies: sudo apt install libssl-dev sudo pip install ansible markupsafe linode-python Get Streisand: git clone https://github.com/jlund/streisand.git cd streisand Install Streisand: sudo su ./streisand Select localhost (Advanced) as provider, then wait for the setup to complete, it should take about 10-15 minutes. If the installation is successful, a folder called generated-docs will be created, inside it are the directions (in html format) for setting up clients. First download and install the SSL certificate by following the instruction in the html file. Then following the instructions in Connecting to your Streisand Gateway section at the bottom of that page. Open the website from that page, enter the usename and password, we are presented with Connection Instructions. There are several clients to choose from. I chose OpenVPN(direct) since it’s simple. Download OpenVPN windows installer, install and run OpenVPN. Download of the OpenVPN profiles from the web page, I just chose the first: client-1. Right click OpenVPN taskbar icon and select Import file... and import the profile that’s just downloaded. Then right click again and select Connect. Now we should be connected to our VPN. Go to whatismyip.com to verify, the IP address it detected should be the IP of the streisand server. Disconnect and the IP detected will be back to the real IP.]]></summary></entry><entry><title type="html">How to stream from RaspberryPi PiCamera</title><link href="http://wensheng.github.io/2017/05/18/stream-from-raspberrypi.html" rel="alternate" type="text/html" title="How to stream from RaspberryPi PiCamera" /><published>2017-05-18T00:00:00+00:00</published><updated>2017-05-18T00:00:00+00:00</updated><id>http://wensheng.github.io/2017/05/18/stream-from-raspberrypi</id><content type="html" xml:base="http://wensheng.github.io/2017/05/18/stream-from-raspberrypi.html"><![CDATA[<h2 id="pre-requisites">Pre-requisites</h2>

<p>OS: Raspbian &gt;= 8</p>

<p>Do <code class="language-plaintext highlighter-rouge">sudo raspi-config</code> and enable PiCamera, in ‘Memory Split’, give GPU more than 128M of memory.  Connect PiCamera, reboot.</p>

<p>Test PiCamera works by <code class="language-plaintext highlighter-rouge">raspistill -o photo.jpg</code>.</p>

<p>Load v4l2 module:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo modprobe bcm2835-v412
</code></pre></div></div>

<p>Optionally add <code class="language-plaintext highlighter-rouge">bcm2835-v412</code> to <code class="language-plaintext highlighter-rouge">/etc/modules</code> file.</p>

<p>v4l2 should already present in the OS, if not:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt-get install v4l-utils
</code></pre></div></div>

<p>There’re multiple ways to stream PiCamera to remote clients. Here I present 4.</p>

<h2 id="method-1-vlc">Method 1: vlc</h2>

<p>Make sure vlc is installed:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt-get install vlc
</code></pre></div></div>

<p>shell script:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>raspivid <span class="nt">-o</span> - <span class="nt">-n</span> <span class="nt">-fps</span> 15 <span class="nt">-w</span> 1280 <span class="nt">-h</span> 720 <span class="nt">-t</span> 0 <span class="se">\</span>
|cvlc <span class="nt">-vvv</span> stream:///dev/stdin <span class="se">\</span>
<span class="nt">--sout</span> <span class="s1">'#rtp{sdp=rtsp://:8554/}'</span> <span class="se">\</span>
:demux<span class="o">=</span>h264 :h264-fps<span class="o">=</span>15

</code></pre></div></div>

<p>When you run the script, it will stream, the stream can be viewed from <code class="language-plaintext highlighter-rouge">rtsp://raspberrypi_ip:8554/</code> from VLC on a remote computer.</p>

<h2 id="method-2-v4l2rtspserver">Method 2: v4l2rtspserver</h2>

<p>Details are in <a href="https://github.com/mpromonet/v4l2rtspserver">v4l2rtspserver github</a>.  But basically:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt-get install cmake liblog4cpp5-dev libv4l-dev
wget www.live555.com/liveMedia/public/live555-latest.tar.gz
tar xfz live555-latest.tar.gz
cd live/
./genMakefiles linux
make CPPFLAGS=-DALLOW_RTSP_SERVER_PORT_REUSE=1
sudo make install
cd
git clone https://github.com/mpromonet/v4l2rtspserver.git
cd v4l2rtspserver/
cmake .
make
sudo make install
</code></pre></div></div>

<p>Then you can run:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>v4l2rtspserver -F15 -H 720 -W1280 -P 8555 /dev/video0
</code></pre></div></div>

<p>The stream can now be viewed from <code class="language-plaintext highlighter-rouge">rtsp://raspberrypi_ip:8555/unicast</code> from VLC on another computer.</p>

<h2 id="method-3-ffmpegavconv">Method 3: ffmpeg/avconv</h2>

<p>Install avconv by <code class="language-plaintext highlighter-rouge">sudo apt-get install libav-tools</code>.</p>

<p>Don’t bother trying to get ffmpeg from third-part apt source, it mostly likely would not work.  Also don’t bother compile (it takes a long time) or cross-compile (hassle) ffmpeg.  avconv works for our purpose.</p>

<p>shell script:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>avconv <span class="nt">-f</span> video4linux2 <span class="nt">-framerate</span> 15 <span class="nt">-video_size</span> 960x540 <span class="se">\</span>
 <span class="nt">-i</span> /dev/video0 <span class="nt">-an</span> <span class="nt">-f</span> flv <span class="nt">-y</span> <span class="se">\</span>
 rtmp://yourstreamserver/live/pi
</code></pre></div></div>

<p>Run it and view the stream on another computer with vlc: <code class="language-plaintext highlighter-rouge">rtmp://yourstreamserver/live/pi</code>.</p>

<p><code class="language-plaintext highlighter-rouge">yourstreamserver</code> is the name or IP of your RTMP stream server, it can be set up with Nginx-rtmp, Wowza, or srs etc.</p>

<p>Using this method, the stream has longest delay, cpu load is pretty high.  I will try to reduce it when I get time.</p>

<h2 id="method-4-gstreamer">Method 4: gstreamer</h2>

<p>Install gstreamer 1.0:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt-get install gstreamer1.0-tools
</code></pre></div></div>

<p>Test we can stream with a MP4 video file:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gst-launch-1.0 <span class="nt">-v</span> filesrc <span class="nv">location</span><span class="o">=</span><span class="s2">"video.mp4"</span> <span class="se">\</span>
 <span class="o">!</span> qtdemux <span class="o">!</span> video/x-h264 <span class="o">!</span> h264parse <span class="se">\</span>
 <span class="o">!</span> flvmux <span class="o">!</span> rtmpsink <span class="se">\</span>
 <span class="nv">location</span><span class="o">=</span><span class="s2">"rtmp://yourstreamserver/live/pi"</span>
</code></pre></div></div>
<p>After this works, we try to make it work with camera.  Unfortunately I couldn’t get v4l2src to work with gstreamer to stream RTMP.</p>

<p>I turned to <a href="https://github.com/thaytan/gst-rpicamsrc">gst-rpicamsrc</a>.</p>

<p>Install dependencies:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt-get install autoconf automake libtool 
sudo apt-get install libgstreamer1.0-dev
sudo apt-get install libgstreamer-plugins-base1.0-dev 
sudo apt-get install libraspberrypi-dev
</code></pre></div></div>

<p>Build gst-rpicamsrc:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://github.com/thaytan/gst-rpicamsrc.git
cd gst-rpicamsrc/
./autogen.sh --prefix=/usr --libdir=/usr/lib/arm-linux-gnueabihf/
make
sudo make install
sudo reboot
</code></pre></div></div>

<p>After reboot, create a script:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gst-launch-1.0 <span class="nt">-v</span> rpicamsrc <span class="se">\</span>
 <span class="o">!</span><span class="s1">'video/x-h264,width=1280,height=720,framerate=15/1'</span> <span class="se">\</span>
 <span class="o">!</span> h264parse <span class="o">!</span> flvmux <span class="se">\</span>
 <span class="o">!</span> rtmpsink <span class="nv">location</span><span class="o">=</span><span class="s2">"rtmp://yourstreamserver/live/pi"</span>
</code></pre></div></div>

<p>The stream from this method has much lower delay compared with method 3.  It’s still much slower than method 1 and 2.  This is because it send stream to a RTMP server, you request stream from the server, In method 1/2, the stream is sent directly to you from RPi.  The streams from method 3/4 can be viewed in a browser (using for example JWPlayer), while the streams from method 1/2 can’t.</p>]]></content><author><name>Wensheng</name></author><summary type="html"><![CDATA[Pre-requisites OS: Raspbian &gt;= 8 Do sudo raspi-config and enable PiCamera, in ‘Memory Split’, give GPU more than 128M of memory. Connect PiCamera, reboot. Test PiCamera works by raspistill -o photo.jpg. Load v4l2 module: sudo modprobe bcm2835-v412 Optionally add bcm2835-v412 to /etc/modules file. v4l2 should already present in the OS, if not: sudo apt-get install v4l-utils There’re multiple ways to stream PiCamera to remote clients. Here I present 4. Method 1: vlc Make sure vlc is installed: sudo apt-get install vlc shell script: raspivid -o - -n -fps 15 -w 1280 -h 720 -t 0 \ |cvlc -vvv stream:///dev/stdin \ --sout '#rtp{sdp=rtsp://:8554/}' \ :demux=h264 :h264-fps=15 When you run the script, it will stream, the stream can be viewed from rtsp://raspberrypi_ip:8554/ from VLC on a remote computer. Method 2: v4l2rtspserver Details are in v4l2rtspserver github. But basically: sudo apt-get install cmake liblog4cpp5-dev libv4l-dev wget www.live555.com/liveMedia/public/live555-latest.tar.gz tar xfz live555-latest.tar.gz cd live/ ./genMakefiles linux make CPPFLAGS=-DALLOW_RTSP_SERVER_PORT_REUSE=1 sudo make install cd git clone https://github.com/mpromonet/v4l2rtspserver.git cd v4l2rtspserver/ cmake . make sudo make install Then you can run: v4l2rtspserver -F15 -H 720 -W1280 -P 8555 /dev/video0 The stream can now be viewed from rtsp://raspberrypi_ip:8555/unicast from VLC on another computer. Method 3: ffmpeg/avconv Install avconv by sudo apt-get install libav-tools. Don’t bother trying to get ffmpeg from third-part apt source, it mostly likely would not work. Also don’t bother compile (it takes a long time) or cross-compile (hassle) ffmpeg. avconv works for our purpose. shell script: avconv -f video4linux2 -framerate 15 -video_size 960x540 \ -i /dev/video0 -an -f flv -y \ rtmp://yourstreamserver/live/pi Run it and view the stream on another computer with vlc: rtmp://yourstreamserver/live/pi. yourstreamserver is the name or IP of your RTMP stream server, it can be set up with Nginx-rtmp, Wowza, or srs etc. Using this method, the stream has longest delay, cpu load is pretty high. I will try to reduce it when I get time. Method 4: gstreamer Install gstreamer 1.0: sudo apt-get install gstreamer1.0-tools Test we can stream with a MP4 video file: gst-launch-1.0 -v filesrc location="video.mp4" \ ! qtdemux ! video/x-h264 ! h264parse \ ! flvmux ! rtmpsink \ location="rtmp://yourstreamserver/live/pi" After this works, we try to make it work with camera. Unfortunately I couldn’t get v4l2src to work with gstreamer to stream RTMP. I turned to gst-rpicamsrc. Install dependencies: sudo apt-get install autoconf automake libtool sudo apt-get install libgstreamer1.0-dev sudo apt-get install libgstreamer-plugins-base1.0-dev sudo apt-get install libraspberrypi-dev Build gst-rpicamsrc: git clone https://github.com/thaytan/gst-rpicamsrc.git cd gst-rpicamsrc/ ./autogen.sh --prefix=/usr --libdir=/usr/lib/arm-linux-gnueabihf/ make sudo make install sudo reboot After reboot, create a script: gst-launch-1.0 -v rpicamsrc \ !'video/x-h264,width=1280,height=720,framerate=15/1' \ ! h264parse ! flvmux \ ! rtmpsink location="rtmp://yourstreamserver/live/pi" The stream from this method has much lower delay compared with method 3. It’s still much slower than method 1 and 2. This is because it send stream to a RTMP server, you request stream from the server, In method 1/2, the stream is sent directly to you from RPi. The streams from method 3/4 can be viewed in a browser (using for example JWPlayer), while the streams from method 1/2 can’t.]]></summary></entry><entry><title type="html">Using Squid as the internal http proxy</title><link href="http://wensheng.github.io/2017/05/14/squid.html" rel="alternate" type="text/html" title="Using Squid as the internal http proxy" /><published>2017-05-14T00:00:00+00:00</published><updated>2017-05-14T00:00:00+00:00</updated><id>http://wensheng.github.io/2017/05/14/squid</id><content type="html" xml:base="http://wensheng.github.io/2017/05/14/squid.html"><![CDATA[<p>I moved to a new building.  In the old building I used to have a few Linux machines and virtual machines connected to internet directly.  Now we are on a temporary network, all our machines and VMs are behind a firewall.  To connect a machine to internet, I have to open the browser from that machine and load the login page, enter my username and password.  This is fine with desktop PC’s.</p>

<p>The problem is my Linux machines and VMs don’t have graphical interface, and because that login page use Javascript to post-process login form before submitting, I can not use text-base browsers such as <code class="language-plaintext highlighter-rouge">lynx</code> or <code class="language-plaintext highlighter-rouge">w3m</code>.  So I can not connect these machines and VM’s to internet.</p>

<p>To launch brower in a GUI on them I need to install X server and Firefox, but then again I need internet access to run <code class="language-plaintext highlighter-rouge">apt</code> to get and install any packages.  Chicken and eggs.</p>

<p>I can inspect the Javascript on the login page and write a Python program the do the same processing then submit the form with curl, but that take too much time and the script will be useless when we have permanet network.</p>

<p>Squid to the rescue!</p>

<p>On my internet connected Linux desktop (which has ip: 10.16.18.25), I install Squid by:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt install squid
squid3 -v  # verify
</code></pre></div></div>

<p>Then configure Squid by editing /etc/squid/squid.conf:</p>

<p>Add:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>acl lan src 10.16.18.0/24
</code></pre></div></div>

<p>at the end of <code class="language-plaintext highlighter-rouge">TAG: acl</code> block.</p>

<p>Add:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>http_access allow lan
</code></pre></div></div>

<p>at the beginning of <code class="language-plaintext highlighter-rouge">TAG: http_access</code>. (before any other <code class="language-plaintext highlighter-rouge">http_access</code>s)</p>

<p>Change:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>http_port 3128
</code></pre></div></div>

<p>To:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>http_port 3128 intercept
</code></pre></div></div>

<p>(Not sure these are all really needed) At <code class="language-plaintext highlighter-rouge">TAG: request_header_access</code> block, add:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>request_header_access Referer deny all
request_header_access X-Forwarded-For deny all
request_header_access Via deny all
request_header_access Cache-Control deny all
forwarded_for off
</code></pre></div></div>

<p>Put in a visible_hostname:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>visible_hostname proxy01
</code></pre></div></div>

<p>We now finished editing squid.conf.  Do:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cat /proc/sys/net/ipv4/ip_forward
</code></pre></div></div>

<p>If it’s 0, do:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo su  # as root
echo 1 &gt; /proc/sys/net/ipv4/ip_forward
</code></pre></div></div>

<p>Then configure local iptables:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ifconfig  # shows my IP and network interface (enp3s0) 
iptables -t nat -A PREROUTING -i enp3s0 -p tcp --dport 80 -j DNAT --to 10.16.18.25:3128
</code></pre></div></div>

<p>Now Squid configuration is finished. My desktop now acts as an HTTP gateway.  Restart Squid:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>service squid restart  
# or systemctl restart squid.service  # on Ubuntu &gt;=16.04
</code></pre></div></div>

<p>On my Linux machine that’s need to be connected to internet, look at <code class="language-plaintext highlighter-rouge">/etc/network/interface</code>, if it’s static IP, change it to dhcp, then restart network.  This is to make sure it’s at least connected to local network.  Do a <code class="language-plaintext highlighter-rouge">ifconfig</code>, get its automatically assigned IP, i.e. 10.16.18.158.</p>

<p>Now we change it back to use static IP and our desktop Linux machine as a gateway.  Do <code class="language-plaintext highlighter-rouge">sudo vi /etc/network/interfaces</code>.</p>

<p>Comment out the dhcp line, add:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>iface eth0 inet static
address 10.16.18.158
netmask 255.255.255.0
gateway 10.16.18.25
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">eth0</code> is the interface device name, it might be different on other machines, but should be the same as the now commented-out dhcp line.</p>

<p>Do a <code class="language-plaintext highlighter-rouge">sudo /etc/init.d/networking restart</code>, now the linux machine should be ‘connected’ to internet.  I put quotes around ‘connected’ because technically it only connected with HTTP protocal (on port 80) but no others, I can do <code class="language-plaintext highlighter-rouge">lynx</code>, <code class="language-plaintext highlighter-rouge">apt</code> etc., but I still can’t ping internet or send email.  This is fine with me for now as we are getting permanent networking in a few weeks.</p>]]></content><author><name>Wensheng</name></author><category term="squid" /><category term="proxy" /><summary type="html"><![CDATA[I moved to a new building. In the old building I used to have a few Linux machines and virtual machines connected to internet directly. Now we are on a temporary network, all our machines and VMs are behind a firewall. To connect a machine to internet, I have to open the browser from that machine and load the login page, enter my username and password. This is fine with desktop PC’s. The problem is my Linux machines and VMs don’t have graphical interface, and because that login page use Javascript to post-process login form before submitting, I can not use text-base browsers such as lynx or w3m. So I can not connect these machines and VM’s to internet. To launch brower in a GUI on them I need to install X server and Firefox, but then again I need internet access to run apt to get and install any packages. Chicken and eggs. I can inspect the Javascript on the login page and write a Python program the do the same processing then submit the form with curl, but that take too much time and the script will be useless when we have permanet network. Squid to the rescue! On my internet connected Linux desktop (which has ip: 10.16.18.25), I install Squid by: sudo apt install squid squid3 -v # verify Then configure Squid by editing /etc/squid/squid.conf: Add: acl lan src 10.16.18.0/24 at the end of TAG: acl block. Add: http_access allow lan at the beginning of TAG: http_access. (before any other http_accesss) Change: http_port 3128 To: http_port 3128 intercept (Not sure these are all really needed) At TAG: request_header_access block, add: request_header_access Referer deny all request_header_access X-Forwarded-For deny all request_header_access Via deny all request_header_access Cache-Control deny all forwarded_for off Put in a visible_hostname: visible_hostname proxy01 We now finished editing squid.conf. Do: cat /proc/sys/net/ipv4/ip_forward If it’s 0, do: sudo su # as root echo 1 &gt; /proc/sys/net/ipv4/ip_forward Then configure local iptables: ifconfig # shows my IP and network interface (enp3s0) iptables -t nat -A PREROUTING -i enp3s0 -p tcp --dport 80 -j DNAT --to 10.16.18.25:3128 Now Squid configuration is finished. My desktop now acts as an HTTP gateway. Restart Squid: service squid restart # or systemctl restart squid.service # on Ubuntu &gt;=16.04 On my Linux machine that’s need to be connected to internet, look at /etc/network/interface, if it’s static IP, change it to dhcp, then restart network. This is to make sure it’s at least connected to local network. Do a ifconfig, get its automatically assigned IP, i.e. 10.16.18.158. Now we change it back to use static IP and our desktop Linux machine as a gateway. Do sudo vi /etc/network/interfaces. Comment out the dhcp line, add: iface eth0 inet static address 10.16.18.158 netmask 255.255.255.0 gateway 10.16.18.25 eth0 is the interface device name, it might be different on other machines, but should be the same as the now commented-out dhcp line. Do a sudo /etc/init.d/networking restart, now the linux machine should be ‘connected’ to internet. I put quotes around ‘connected’ because technically it only connected with HTTP protocal (on port 80) but no others, I can do lynx, apt etc., but I still can’t ping internet or send email. This is fine with me for now as we are getting permanent networking in a few weeks.]]></summary></entry><entry><title type="html">Set up both 32 and 64 bit Anaconda on Windows</title><link href="http://wensheng.github.io/2017/05/13/setup-conda-32-64.html" rel="alternate" type="text/html" title="Set up both 32 and 64 bit Anaconda on Windows" /><published>2017-05-13T00:00:00+00:00</published><updated>2017-05-13T00:00:00+00:00</updated><id>http://wensheng.github.io/2017/05/13/setup-conda-32-64</id><content type="html" xml:base="http://wensheng.github.io/2017/05/13/setup-conda-32-64.html"><![CDATA[<p>I need to have both 32 bit and 64 bit Python on my Windows machine.  For 32 bit, I only need Python 2.</p>

<p>First, I installed Anaconda 4.3 into my home directory (C:\Users\wensheng).  Then I downloaded <a href="https://conda.io/miniconda.html">Miniconda</a> Python 2.7 32-bit installer.  I run the installer as usual, but at the last step, where it ask if you want to add path to environment, uncheck that option.</p>

<p>So now I have both 32 bit and 64 bit Anaconda installed, 32-bit is in <code class="language-plaintext highlighter-rouge">Miniconda2</code>, 64-bit is in <code class="language-plaintext highlighter-rouge">Anaconda3</code>, both under <code class="language-plaintext highlighter-rouge">C:\Users\wensheng</code>.  But I only have path for 64-bit in my environment.  When I type <code class="language-plaintext highlighter-rouge">python</code>, <code class="language-plaintext highlighter-rouge">conda</code>, or <code class="language-plaintext highlighter-rouge">activate</code> in cmd.exe, I get 64-bit version.</p>

<p>To create a 32-bit conda env, I use full name of 32-bit conda, like:</p>

<p><code class="language-plaintext highlighter-rouge">C:\Users\wensheng\Miniconda2\Scripts\conda create -n ...</code></p>

<p>Because this is done only once or twice so it’s not that painful.  However once conda env is created, I do use activate quite often.  But typing just <code class="language-plaintext highlighter-rouge">activate</code> in cmd.exe will invoke the 64-bit Python 3 version.  To make it easier to run 32-bit <code class="language-plaintext highlighter-rouge">activate</code>, I create a bat file in my bin directory called act.bat with just one line:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>%USERPROFILE%\Miniconda2\Scripts\activate %1
</code></pre></div></div>

<p>Now <code class="language-plaintext highlighter-rouge">act</code> is for 32-bit <code class="language-plaintext highlighter-rouge">activate</code>.  (My <code class="language-plaintext highlighter-rouge">bin</code> directory is already in my PATH environment variable.)</p>

<p>Side note: On linux, when you run just <code class="language-plaintext highlighter-rouge">env</code>, it will print out all environment variables.  On Windows, the equivalent is typing just <code class="language-plaintext highlighter-rouge">set</code>.</p>]]></content><author><name>Wensheng</name></author><category term="python" /><category term="anaconda" /><category term="windows" /><summary type="html"><![CDATA[I need to have both 32 bit and 64 bit Python on my Windows machine. For 32 bit, I only need Python 2. First, I installed Anaconda 4.3 into my home directory (C:\Users\wensheng). Then I downloaded Miniconda Python 2.7 32-bit installer. I run the installer as usual, but at the last step, where it ask if you want to add path to environment, uncheck that option. So now I have both 32 bit and 64 bit Anaconda installed, 32-bit is in Miniconda2, 64-bit is in Anaconda3, both under C:\Users\wensheng. But I only have path for 64-bit in my environment. When I type python, conda, or activate in cmd.exe, I get 64-bit version. To create a 32-bit conda env, I use full name of 32-bit conda, like: C:\Users\wensheng\Miniconda2\Scripts\conda create -n ... Because this is done only once or twice so it’s not that painful. However once conda env is created, I do use activate quite often. But typing just activate in cmd.exe will invoke the 64-bit Python 3 version. To make it easier to run 32-bit activate, I create a bat file in my bin directory called act.bat with just one line: %USERPROFILE%\Miniconda2\Scripts\activate %1 Now act is for 32-bit activate. (My bin directory is already in my PATH environment variable.) Side note: On linux, when you run just env, it will print out all environment variables. On Windows, the equivalent is typing just set.]]></summary></entry><entry><title type="html">Move files from all sub-directories to current directory</title><link href="http://wensheng.github.io/2017/05/11/move-files-from-subdir.html" rel="alternate" type="text/html" title="Move files from all sub-directories to current directory" /><published>2017-05-11T00:00:00+00:00</published><updated>2017-05-11T00:00:00+00:00</updated><id>http://wensheng.github.io/2017/05/11/move-files-from-subdir</id><content type="html" xml:base="http://wensheng.github.io/2017/05/11/move-files-from-subdir.html"><![CDATA[<p>On Linux or Windows (with Windows Subsystem for Linux, or <a href="https://msdn.microsoft.com/en-us/commandline/wsl/install_guide">Bash on Ubuntun on Windows</a> ), if you want to move all files from all sub-directories to the current one, do this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>find ./*/ -type f -exec mv -t . '{}' +
</code></pre></div></div>

<p>You can then remove all those empty directories:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>find ./* -type d -exec rmdir '{}' +
</code></pre></div></div>]]></content><author><name>Wensheng</name></author><summary type="html"><![CDATA[On Linux or Windows (with Windows Subsystem for Linux, or Bash on Ubuntun on Windows ), if you want to move all files from all sub-directories to the current one, do this: find ./*/ -type f -exec mv -t . '{}' + You can then remove all those empty directories: find ./* -type d -exec rmdir '{}' +]]></summary></entry></feed>