command line 명령어로 메일 보내기 (mail) - 한글 제목 불가

리눅스/Mail|2020. 2. 20. 13:01
반응형

* SMTP 를 이용하지 않고 발송

* html 본문 사용 가능

* 한글 제목 불가


# cat mail_body.html |mail -a "From: sender@sysdocu.tistory.com" -a "MIME-Version: 1.0" -a "Content-Type: text/html" -s "[TEST] 테스트 메일 입니다." user@sysdocu.tistory.com



반응형

댓글()

curl (35) ssl connect error

리눅스/OS 일반|2020. 2. 6. 16:59
반응형

운영중 아래와 같은 에러 메세지를 만났다면..


curl (35) ssl connect error


다음과 같이 패키지를 업데이트 해주면 해결이 됩니다.


# yum update -y nss curl libcurl



반응형

댓글()

MySQL 5.7 사용자 계정 추가, root 패스워드 갱신

리눅스/MySQL|2020. 2. 3. 10:10
반응형

1. 사용자 계정 생성 및 권한 부여

 

기존 방법과 달리 MySQL 5.7 버전에서 부터 계정 생성하는 방법이 바뀌었으므로

아래와 같은 명령을 이용하여 계정 생성을 하고 DB 접근 권한을 부여 합니다.

 

mysql> create database sysdocu;

mysql> CREATE USER 'sysdocu'@'localhost' IDENTIFIED BY '12345678' PASSWORD EXPIRE NEVER;

mysql> GRANT ALL PRIVILEGES ON sysdocu.* TO 'sysdocu'@'localhost';

mysql> flush privileges;

 

* MariaDB 10.3.17 에서는 아래와 같이 하면 됩니다.

[mysql]> create user 'sysdocu'@'localhost' identified by '12345678';

[mysql]> grant all privileges on sysdocu.* to sysdocu@'localhost' identified by '12345678' with grant option;

[mysql]> flush privileges;

 

 

2. root 패스워드 변경

 

MySQL 5.7 버전 부터 root 패스워드 변경하는 방법 또한 변경되었습니다.

아래와 같은 쿼리를 이용하여 변경합니다.

 

mysql> use mysql;

mysql> update user set authentication_string=password('12345678') where user='root'; 

mysql> flush privileges;

 

이렇게도 안되는 경우 (MySQL 최초 설치시) 아래와 같이 사용해 봅니다.

mysql> alter user 'root'@'localhost' identified with mysql_native_password by '12345678';

mysql> flush privileges;

 

 

3. 사용자 정보 간략히 보기

 

mysql> select host, user, plugin, authentication_string, password_last_changed from user;

 

반응형

댓글()

SQLite 에서 중복값 있으면 insert 건너뛰기

프로그래밍/Android (Java)|2020. 1. 31. 16:25
반응형

방법1

INSERT OR IGNORE INTO favorite (no) VALUES 'str';



방법2

INSERT INTO favorite (no) SELECT 'str' WHERE NOT EXISTS (SELECT 1 FROM favorite WHERE no='str');



* str 은 데이터 입니다.




반응형

댓글()

CentOS 6.x 에 Root CA 인증서 설치 (추가) 하기

리눅스/OS 일반|2020. 1. 29. 12:00
반응형

아래는 CentOS 6 에서의 설치 과정을 담고 있습니다.

같은 리눅스라고 하더라도 OS 종류 및 버전에 따라 명령 혹은 crt 파일 복사 경로가 다른 점 참고하시기 바랍니다.

기존에 ca 인증서가 있는 경우 별도의 백업을 먼저 진행합니다.

그리고 아래 절차에 따라 새로운 인증서를 추가 합니다.



관련 패키지를 설치


# yum -y install ca-certificates


CA 저장소 공유 기능 활성화


# update-ca-trust enable


인증서 복사


# cp -arp RootCa.crt /etc/pki/ca-trust/source/anchors/


루트 인증서 업데이트


# update-ca-trust extract


끝.

반응형

댓글()

그라데이션 테두리 있는 버튼 만들기

프로그래밍/Android (Java)|2020. 1. 28. 12:14
반응형

drawable/bg.xml


<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >


    <item>

        <shape android:shape="rectangle" >

            <gradient

                android:angle="45"

                android:centerColor="@android:color/holo_blue_bright"

                android:endColor="@android:color/holo_red_light"

                android:startColor="@android:color/holo_green_light" />

            <corners android:radius="7dp" />

        </shape>

    </item>


    <item

        android:bottom="5dp"

        android:left="5dp"

        android:right="5dp"

        android:top="5dp">

        <shape android:shape="rectangle" >

            <solid android:color="#ffffff" />

            <corners android:radius="7dp" />

        </shape>

    </item>


</layer-list> 



[출처] https://stackoverflow.com/questions/20870853/android-shape-border-with-gradient

반응형

댓글()

플로팅 액션 버튼 (Floating Action Button)

프로그래밍/Android (Java)|2020. 1. 22. 11:33
반응형

In previous post, I had talked about some popular designs of Floating Action Button (FAB) - a component of Design Support Library. Beside that, there is a design from Inbox application (developed by Google) which containing some FABs are combined into a group and they will be shown after the "representative button" clicked. This design called Floating Action Menu:

    Up to now, there is no official component from Google which allows us making this design so we must use third-party library to building a Floating Action Menu (FAM). Fortunately, libraries to resolve this problem is not unpopular!
    In this post, I will use a third-party developed by Dmytro Tarianyk Clans. It's very simple to implement and solving this problem quickly!
    DEMO VIDEO:

 

 

Import the library

    Adding this dependency to your application level build.gradle:
dependencies { compile 'com.github.clans:fab:1.6.4' }     Now, we have two objects called FloatingActionMenu and FloatingActionButton to build this layout.

Some important features

   FloatingActionMenu has some attributes in xml that we have to pay attention:

  • fab:menu_fab_label: Label for Menu button
  • fab_colorNormal, fab_colorPressed, fab_colorRipple: Change button color based on it's status.
  • fab_showAnimation, fab_hideAnimation: Animation when menu expand/collapse.
  • menu_labels_position: Position of buttons label (left/right).
  • menu_openDirection: Open menu up or down.

Usages in activity

Declaring a layout for our activity like this:

activity_main.xml

 

    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/fab_menu"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:paddingBottom="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        fab:menu_backgroundColor="#ccffffff"
        fab:menu_fab_label="Choose an action"
        fab:fab_colorNormal="#DA4336"
        fab:fab_colorPressed="#E75043"
        fab:fab_colorRipple="#99FFFFFF"
        fab:fab_showShadow="true"
        fab:menu_labels_colorNormal="#333333"
        fab:menu_labels_colorPressed="#444444"
        fab:menu_labels_colorRipple="#66FFFFFF"
        fab:menu_labels_showShadow="true"
        fab:menu_labels_maxLines="-1"
        fab:menu_labels_position="left"
        fab:menu_openDirection="up"
        fab:fab_shadowColor="#66000000"
        fab:menu_labels_ellipsize="end"
        fab:menu_labels_singleLine="true">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_edit"
            fab:fab_label="Edit an item"
            fab:fab_size="mini" />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_add"
            fab:fab_label="Menu item 2"
            fab:fab_size="mini" />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_delete"
            fab:fab_label="@string/lorem_ipsum"
            fab:fab_size="mini" />

    </com.github.clans.fab.FloatingActionMenu>

 


MainActivity.java

 

package info.devexchanges.floatingactionmenu;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.github.clans.fab.FloatingActionButton;
import com.github.clans.fab.FloatingActionMenu;

public class MainActivity extends AppCompatActivity {

    private FloatingActionMenu fam;
    private FloatingActionButton fabEdit, fabDelete, fabAdd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fabAdd = (FloatingActionButton) findViewById(R.id.fab2);
        fabDelete = (FloatingActionButton) findViewById(R.id.fab3);
        fabEdit = (FloatingActionButton) findViewById(R.id.fab1);
        fam = (FloatingActionMenu) findViewById(R.id.fab_menu);

        //handling menu status (open or close)
        fam.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() {
            @Override
            public void onMenuToggle(boolean opened) {
                if (opened) {
                    showToast("Menu is opened");
                } else {
                    showToast("Menu is closed");
                }
            }
        });

        //handling each floating action button clicked
        fabDelete.setOnClickListener(onButtonClick());
        fabEdit.setOnClickListener(onButtonClick());
        fabAdd.setOnClickListener(onButtonClick());

        fam.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (fam.isOpened()) {
                    fam.close(true);
                }
            }
        });
    }

    private View.OnClickListener onButtonClick() {
        return new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (view == fabAdd) {
                    showToast("Button Add clicked");
                } else if (view == fabDelete) {
                    showToast("Button Delete clicked");
                } else {
                    showToast("Button Edit clicked");
                }
                fam.close(true);
            }
        };
    }

    private void showToast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }
}

 

 

    Running application, we'll have this output:

    Click the "representative button" to open Menu:

    After click the "delete button" in Menu:

    Animation for expanding/collapsing process:

 

Conclusions

    As you can see, with a small third-party library, we can build a FAM easily. By searching on Internet, you can find out another similar libraries:

    You should try to use them and choose the best one!
    Reference to the libary Github page: https://github.com/Clans/FloatingActionButton

 View project on Github

 

 

[출처] http://www.devexchanges.info/2016/07/floating-action-menu-in-android.html

반응형

댓글()

sed 로 문자열 개행 제거

프로그래밍/BASH SHELL|2020. 1. 17. 10:50
반응형

N 옵션이 첫번째 줄의 개행을 제거하여 두번째줄과 붙여준다고 합니다. (개행을 콤마로 변경)

뒤에 g 옵션을 붙여도 결과는 마찬가지 입니다.

 

sed -e '{N;s/\n/,/}'

 

여러줄의 개행을 제거하고 싶을때 아래와 같은 옵션을 사용해보세요.

 

sed -e ':a;N;$!ba;s/\n/,/g'

 

 

반응형

댓글()

Telegram Bot 을 사용하여 메세지 전송하기

프로그래밍/BASH SHELL|2020. 1. 15. 15:19
반응형



■ 텔레그램 봇을 사용하여 메세지 전송하기




#01. BotFather를 통한 메세지 봇 생성하기



텔레그램의 봇은 @BotFather를 통해 관리된다.


텔레그램 응용프로그램을 실행한뒤 아래 이미지와 같은 순서대로 작업을 진행한다.



01. 메시지 봇 생성하기




 ① 텔레그램 검색창에 BotFather 라고 입력한다.

 ② 검색결과에서 BotFather를 선택하고 대화를 시작한다.

 ③ /start라고 입력한다.

 ④ /newbot이라고 입력하여 새로운 봇을 생성할 준비를 한다.

 ⑤ 자신이 사용할 봇의 아이디를 입력한다.(예 : wicked_test)

 ⑥ 생성한 봇 아이디에 _bot 이라고 추가적으로 입력해 준다.(예 : wicked_test_bot)
 ⑦ 텔레그램의 답변문구의 토큰 API키 값을 확인한다.




02. 정상적으로 메시지 봇이  생성되었다면 텔레그램 API에 getUpdate 값을 웹 브라우저로 전달하여 생성이 잘 되었는지를 확인해보자.


# 예시

 https://api.telegram.org/bot + 토큰 API 키값 + /getUpdates


# 출력결과

 https://api.telegram.org/bot682811095:AAEfPFpuEOrq5uCk7KK6aP8BLlX-fpHov8k/getUpdates











#02. Chart ID 확인하기


01. 먼저 메시지를 전달받을 텔레그램 계정으로 로그인한 텔레그램 채팅창에서 위에서 제작한 봇을 검색한다.

 ① 검색창에서 제작한 텔레그램 봇의 아이디 값을 입력한다.(예 : wicked_test)

 ② 검색결과에 제작한 봇 아이디가 나온다면 선택해준다.

 ③ 대화를 시작한다.






02. 대화가 시작되면 위와같이 /start 라고 자동으로 입력되는것을 확인 할 수 있다.






03. 이제 다시 위에서 실행한 웹 브라우저를 새로고침 하여 다시 getUpdates 를 전달해보면 입력한 값이 잘 출력되는 것을 확인 할 수 있다.











#03. 사용자에게 메세지 전송하기



01. 웹 브라우저를 실행해서 아래와 같이 코드를 작성하 메시지를 보내보도록 하자.


# 예시

 https://api.telegram.org/bot + 토큰 API 키값 + /sendmessage?chat_id= + 사용자차트ID + &text= + 전송할 메세


# 출력결과

 https://api.telegram.org/bot682811095:AAEfPFpuEOrq5uCk7KK6aP8BLlX-fpHov8k/sendmessage?chat_id=39538219&text=Message





02. 실제 텔레그램 상에서도 작성한 메세지 내용이 정상적으로 출력되는 것을 확인 할 수 있다.




[출처] http://magic.wickedmiso.com/66

반응형

댓글()

c언어로 파일 생성 (내용 입력)

프로그래밍/C, C++|2020. 1. 10. 13:48
반응형

[코드]

char *text = 'aaaaa';

FILE* fp = fopen("/tmp/test.txt", "a");

fprintf(fp, "%s", text);

fclose(fp);



[결과]

aaaaa 라는 내용의 파일 /tmp/test.txt 가 생성됩니다.

파일 내용을 덮어 씌우기 할 경우 "a" 가 아닌 "w" 로 사용하면 됩니다.


반응형

댓글()

C 언어로 리눅스 명령어 실행하기

프로그래밍/C, C++|2020. 1. 8. 15:16
반응형

C 프로그래밍을 할 때, 리눅스 시스템의 명령을 사용해야 하는 경우가 있습니다.

아래 소스와 같이 사용이 가능합니다.


# vi sysdocu.c


#include <stdio.h>


int main()

{

    printf("\n아래는 현재 디렉토리의 파일 리스트 입니다.\n\n");

    system("ls -al");


    return 0;

} 



실행 가능한 바이너리 파일로 변환합니다.


# cc -o sysdocu sysdocu.c


변환된 파일을 실행합니다.


# ./sysdocu



반응형

댓글()