Skip to main content

How to Install Powerline

· One min read

Go Installation

Install Go to install powerline-go.

brew install go

Powerline-go Installation

go get -u github.com/justjanne/powerline-go

Configuration

Bashrc

Open ~/ .bashrc with Vim or nano and add the following.

GOPATH=$HOME/go
function _update_ps1() {
PS1="$( $GOPATH/bin/powerline-go -newline -error $? )"
}
if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi

Run source ~/.bashrc to apply the changes.

Font

This should finish it, but there might be character encoding issues. You need to set a font that corresponds to Powerline. On Windows, you can use Cascadia Code PL or Cascadia Mono PL.

We recommend PlemolJP from https://github.com/yuru7/PlemolJP/. Download it from https://github.com/yuru7/PlemolJP/releases, click on PlemolJP_NF_vX.X.X.zip, download, extract, and install the font. Set the font to PlemolJP35 Console NF.

Avoid using delay() in Arduino

· One min read

Using delay() in Arduino prevents any other actions from being performed during the waiting time. I created a program that blinks an LED with a 1-second cycle using millis().

  1. Get the time using millis() and divide it by the interval, assigning the result to t.
  2. Compare the previous t and the new t and execute a function if they are different.

Example

unsigned long t = 0, ot;

void sетуp(){
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
ot = t;
t = millis() / 500;
if(ot != t){
if(t % 2){
digitalWrite(LED_BUILTIN, LOW);
}else{
digitalWrite(LED_BUILTIN, HIGH);
}
}
}

Setting up a Raspberry Pi without a monitor

· 2 min read

This guide explains how to set up a Raspberry Pi without needing a monitor.

  • Requires a Raspberry Pi device that can connect an Ethernet cable for a wired connection.
  • A computer is needed to operate the Raspberry Pi.

Install Raspberry Pi Imager, select the OS. Choose the micro SD card to write to, and click WRITE.

Raspberry Pi Imager

Configuration

Enable SSH

Enabling SSH allows you to operate the Raspberry Pi remotely.

Reinsert the micro SD card and create a text file named ssh directly in the root directory. No extension is needed.

Raspberry Pi enable SSH

Enable VNC

Open config.txt and uncomment and save the following lines:

framebuffer_width=1280
framebuffer_height=720

Raspberry Pi enable VNC

Boot Up

Insert the micro SD card into the Raspberry Pi, connect the power, and boot it up.

Connect via SSH

Connect using hostname raspberrypi, username pi, and password raspberry.

Raspberry Pi connect SSH

Update Packages

sudo apt update
sudo apt upgrade -y

Enable VNC

sudo raspi-config

Raspberry Pi config

Select 3 Interface Options, then P3 VNC, and select YES. Close with Finish.

Connect via VNC

Raspberry Pi VNC viewer

Use the same username and password as for SSH.

Raspberry Pi VNC connected

Enable Wi-Fi

Enabling Wi-Fi via VNC eliminates the need for a wired connection, allowing you to operate the Raspberry Pi with only power.

Troubleshooting CGI not working with Ruby installed via rbenv on Webrick

· One min read

When executing CGI in the browser, an error occurs stating: /usr/bin/env: 'ruby': No such file or directory

#!/usr/bin/env ruby

# ...

Cause

The $PATH is not set.

#!/usr/bin/env bash

echo -ne "Content-type: text/html\n\n"
echo $PATH

Running this will display:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

This shows that the directory containing Ruby is not present.

Solution

Set the Ruby path using :CGIPathEnv.

srv = WEBrick::HTTPServer.new({
:DocumentRoot => "./site/",
:Port => 8080,
:CGIPathEnv => ENV["PATH"]
})

How to create a gem

· One min read

Creating a Template

bundle gem <GEM Name> -t
cd <GEM Name>

Editing the Gemspec

  1. Open <GEM Name>.gemspec.
  2. Edit spec.summary, spec.description, spec.homepage,
  3. Write the homepage URL to spec.metadata["allowed_push_host"]
  4. Write the Gem's page to spec.homepage
  5. Write the repository URL to spec.metadata["source_code_uri"]
  6. Write the URL of changelog.md to spec.metadata["changelog_uri"]

Set at least this much.

Push to GitHub and Install

git init
git add .
git commit -m First Commit
git remote add origin [email protected]:<username>/<GEM Name>.git
git push -u origin master

Install

gem install specific_instal
gem specific_install -l "git://github.com/<username>/<GEM Name>.git"

Gemfile

gem "<GEM Name>", github: "<username>/<GEM Name>.git", branch: :main

Displaying Images in the Terminal

· One min read

Introducing the tiv command for displaying images in the terminal.

tiv

It's convenient when you don't want to open a file explorer.

git clone https://github.com/stefanhaustein/TerminalImageViewer.git
cd TerminalImageViewer/src/main/cpp
make -j
sudo make install

Euclidean Algorithm in Bash

· One min read
  1. Let C be the remainder when A is divided by B.

  2. Let D be the remainder when B is divided by C.

  3. Let E be the remainder when C is divided by D.

    ...

  4. Let Y be the remainder when X is divided by 0.

    Then Y is the greatest common divisor.

Bash Script

#!/usr/bin/env bash

function gcd(){
test $2 -eq 0 && echo $1 || gcd $2 $(( $1 % $2 ))
}

gcd 1071 1029
# 21

Installing ImageMagick (Ubuntu)

· One min read
wget https://download.imagemagick.org/ImageMagick/download/ImageMagick-7.0.11-14.tar.xz

Extract

tar xf ImageMagick-7.0.11-14.tar.xz

Make

sudo apt update
cd ImageMagick-7.0.11-14.tar.xz
./configure
make -j
sudo make install
sudo ldconfig /usr/local/lib

Denoising with a Gaussian Filter (Python / Scipy)

· One min read

As an example, let's use a 1[Hz] sine wave as the signal. Add noise generated from random numbers following a normal distribution with a mean of 0 and a standard deviation of 0.5 to the signal.

import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter1d

t = np.arange(1000) / 100
s = np.sin(2*np.pi*t)
noise = np.random.normal(0, 0.5, size=len(t))
x = s + noise

plt.plot(t, x, label="+noise")
plt.plot(t, s, label="signal")
plt.legend(loc=1)
plt.show()

pyplot

Apply a Gaussian filter with a standard deviation of 5. The larger the standard deviation, the smoother the result, but the more it deviates from the original signal.

y = gaussian_filter1d(x, 5)
plt.plot(t, y, label="filtered")
plt.plot(t, s, label="signal")
plt.legend(loc=1)
plt.show()

pyplot