13 Oct 2018
|
리눅스
Network Interface 우선 순위 변경하기
Ubuntu에서 랜카드를 여러 개 꽂아서 네트워크 인터페이스(Network Interface)가 여러 개 존재할 경우 우선 순위를 바꾸는 방법입니다.
먼저 ifmetric를 설치합니다.
sudo apt install ifmetric
이후 다음 명령어를 이용해 Routing Table을 확인합니다.
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.51.0.1 0.0.0.0 UG 100 0 0 eth0
0.0.0.0 192.168.0.1 0.0.0.0 UG 600 0 0 wlan0
맨 뒤의 Iface 항목이 각 네트워크 인터페이스 이름이며 Metric 항목이 우선 순위라고 생각하면 됩니다. Metric 값이 낮을 수록 우선 순위가 높습니다.
ifmetric 명령어를 이용해서 다음과 같이 우선 순위를 변경할 수 있습니다.
sudo ifmetric wlan0 50
다시 route -n 명령어로 Routing Table을 확인해봅니다.
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 50 0 0 wlan0
0.0.0.0 10.51.0.1 0.0.0.0 UG 100 0 0 eth0
우선 순위가 바뀐 것을 확인할 수 있습니다.
12 Oct 2018
|
ROS
문자열(std_msg)을 수신(Subscribe)하고 전송(Publish)하는 예제 코드(C++)
하나의 프로그램내에서 ROS 2.0 문자열 메시지를 수신하고, 바로 그 내용을 다른 토픽(Topic)으로 전송하는 예제 코드입니다. 메시지 수신부는 람다 함수로 되어 있습니다.
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include <iostream>
using namespace std;
using std::placeholders::_1;
const string NODE_NAME = "snowdeer_msg_echo_example";
int main(int argc, char *argv[]) {
cout << "Hello, ROS2 ECHO Example" << std::endl;
rclcpp::init(argc, argv);
auto node = rclcpp::Node::make_shared(NODE_NAME);
auto publisher = node->create_publisher<std_msgs::msg::String>("snowdeer_output");
auto subscription = node->create_subscription<std_msgs::msg::String>
("snowdeer_input", [publisher](std_msgs::msg::String::SharedPtr inMessage) {
auto outMessage = std::make_shared<std_msgs::msg::String>();
outMessage->data = inMessage->data;
publisher->publish(outMessage);
});
auto message = std::make_shared<std_msgs::msg::String>();
rclcpp::spin(node);
rclcpp::shutdown();
return 0;
}
07 Oct 2018
|
Android
Intent를 이용해서 전화 및 화상 통화 호출하는 방법
제조사마다 방식이나 특정 Flag 값이 다를 수 있습니다.
import android.Manifest.permission;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText etPhoneNumber;
static final int PERMISSION_REQUEST_CODE = 100;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etPhoneNumber = findViewById(R.id.et_phone_number);
findViewById(R.id.btn_call).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse("tel:" + getPhoneNumber()));
i.putExtra("android.phone.extra.calltype", 0);
startActivity(i);
}
});
findViewById(R.id.btn_video_call).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse("tel:" + getPhoneNumber()));
i.putExtra("videocall", true);
startActivity(i);
}
});
if (checkSelfPermission(permission.CALL_PHONE)
!= PackageManager.PERMISSION_GRANTED) {
String[] permissions = new String[]{permission.CALL_PHONE};
requestPermissions(permissions, PERMISSION_REQUEST_CODE);
}
}
String getPhoneNumber() {
return etPhoneNumber.getText().toString();
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case PERMISSION_REQUEST_CODE:
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), "Permission 완료", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Permission 실패", Toast.LENGTH_SHORT).show();
}
break;
}
}
}
27 Sep 2018
|
리눅스
ZSH Plug-in 사용 방법
ZSH에는 수 많은 플러그인(Plug-in) 들이 있습니다. 그런데, 그 중에서 쓸만한 것들이 아주 많은 것 같지는 않습니다. 다음은 개인적으로 쓰고 있는, 범용적으로 쓰일 수 있는 플러그인들입니다.
ZSH 플러그인 설치는 ~/.oh-my-zsh/custom/plugins 디렉토리에 하면 되며, 사용 유무는 ~/.zshrc 파일에서 설정 할 수 있습니다.
플러그인 설치 예시
cd ${ZSH_CUSTOM1:-$ZSH/custom}/plugins
git clone https://github.com/djui/alias-tips.git
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
그 이후 ~/.zshrc 파일에 다음과 같이 설정합니다.
plugins=(
git
alias-tips
zsh-autosuggestions
zsh-syntax-highlighting
)
그 외에도 저는 wd 같은 플러그인도 사용하고 있습니다.
26 Sep 2018
|
리눅스
ZSH 기본 설정 변경
ZSH 기본 설정은 ~/.zshrc 파일에서 세팅할 수 있습니다. ~/.zshrc 파일은 터미널을 처음 실행했을 때 실행되는 환경 변수 파일이기도 합니다. (.bashrc 파일과 유사)
기본 테마를 agnoster로 변경
~/.zshrc 파일을 열어서 다음과 같이 변경합니다. 기본 값은 ZSH_THEME="robbyrussell" 입니다.
ZSH_THEME="agnoster"
만약 실행할 때마다 랜덤으로 테마를 변경하고 싶으면 다음과 같이 설정할 수도 있습니다.
ZSH_THEME="random"
테마 색상(팔레트) 변경
가독성이 좋은 Solarize 색상 테마로 변경하는 방법입니다. 저는 Solarize 색상 테마 안의 Dark Theme를 사용하고 있습니다.
sudo apt-get install dconf-cli
git clone git://github.com/sigurdga/gnome-terminal-colors-solarized.git ~/.solarized
cd ~/.solarized
./install.sh
This script will ask you which color scheme you want, and which Gnome Terminal profile to overwrite.
Please note that there is no uninstall option yet. If you do not wish to overwrite any of your profiles, you should create a new profile before you run this script. However, you can reset your colors to the Gnome default, by running:
Gnome >= 3.8 dconf reset -f /org/gnome/terminal/legacy/profiles:/
Gnome < 3.8 gconftool-2 --recursive-unset /apps/gnome-terminal
By default, it runs in the interactive mode, but it also can be run non-interactively, just feed it with the necessary options, see 'install.sh --help' for details.
Please select a color scheme:
1) dark
2) dark_alternative
3) light
#? 1
Please select a Gnome Terminal profile:
1) Unnamed
#? 1
~~~
그런 다음 .zshrc 파일 맨 아래에 아래 항목을 추가합니다.
eval `dircolors ~/.dir_colors/dircolors`
그 다음 터미네이터의 Preferences 에서 Profiles > Colors의 Built-in schemes 항목을 엽니다. Solarized dark 항목이 추가되어 있는 것을 확인할 수 있습니다.
저는 백그라운드 색을 White on Black으로 설정하며, Palette 항목은 Solarized로 설정하고 있습니다.
(Ubuntu 20.04 기준으로는 Foreground and Blackground에서 Built-in schemes를 White on Black, Palette의 Built-in schemes를 Solarized로 설정했습니다.)
.zshrc 예제
예제
# 터미널 색상 테마 적용
eval `dircolors ~/.dir_colors/dircolors`
# for (i-search)
stty stop undef
# for Java
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
# for Android
export ANDROID_SDK=~/Android/Sdk
export ANDROID_NDK=~/Android/Ndk/android-ndk-r17b
export ANDROID_HOME=$ANDROID_SDK
export PATH=$PATH:$ANDROID_SDK:$ANDROID_TOOLS:$ANDROID_NDK:$ANDROID_HOME/tools:$ANDROID_SDK/platform-tools
# for TERM setting
export TERM=xterm
# for ZSH AutoSuggestion
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=cyan'
# 프롬프트에서 컴퓨터 이름 삭제
prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
fi
}