Category Archives: Programing

Android build & run Command line Batch

@echo off
start /B gradlew.bat assembleDebug
adb -d install -r {APK LOCATION}
adb shell monkey -p {Package Name} -c android.intent.category.LAUNCHER 1

PHP7 Uncaught Error: Class “ZipArchive” 오류시

Centos 6.x x86_64 기준

remi REPO 활성화 되어 있어야함.

remi REPO 추가
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

#yum install php70-php-pecl-zip

centos 6 PHP7 + MSSQL

YUM REPO 추가
1. epel
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

2. remi
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

기존 PHP 삭제
# yum remove php*

PHP 7 설치 (php 패키지는 개인의 용도에 맞게 설치)
# yum –enablerepo=remi install php70 php70-php php70-php-cli php70-php-common php70-php-gd php70-php-json php70-php-mbstring php70-php-mcrypt php70-php-mysqlnd php70-php-opcache php70-php-pear php70-php-xml php70-php-devel php70-php-imagick php-pdo

※ php.ini 파일은 /etc/opt/remi/php70/php.ini로 변경 됨

PHP 7에서 MSSQL로의 쿼리는 PDO를 통해 가능하며 접속 및 테스트 코드는 아래와 같음

”config.php”

<?
 // 반드시 DRIVER는 dblib로
 $_DB_INFO_MSSQL = array(
  "_DRIVER" => "dblib", 
  "_HOST" => "", 
  "_PORT" => "1433", 
  "_USER" => "", 
  "_PASS" => "", 
  "_DB" => ""
 );
?>

”MSSQL_SAMPLE.php”

<?
/*
* Project : MSSQL DBMS Class (PHP 7 PDO)
* Author : colorweb <enjoyteam@nate.com>
* Last : 2016-08-02
*/
class MSSQL extends PDO
{
    private $dns;
    private $engine; 
    private $host; 
    private $database; 
    private $user; 
    private $pass; 
    private $port; 
    private $_CONN; 
    private $_RESULT;
    
    public function __construct(){ 
        $this->engine = $GLOBALS["_DB_INFO_MSSQL"]["_DRIVER"]; 
        $this->host = $GLOBALS["_DB_INFO_MSSQL"]["_HOST"]; 
        $this->database = $GLOBALS["_DB_INFO_MSSQL"]["_DB"]; 
        $this->user = $GLOBALS["_DB_INFO_MSSQL"]["_USER"]; 
        $this->pass = $GLOBALS["_DB_INFO_MSSQL"]["_PASS"]; 
        $this->port = $GLOBALS["_DB_INFO_MSSQL"]["_PORT"]; 
        $this->dns = $this->engine.\':dbname=\'.$this->database.";host=".$this->host.":".$this->port; 
    } 

    function connect()
    {
        try {
            $this->_CONN = new PDO ($this->dns, $this->user, $this->pass);
        } catch (PDOException $e) {
            //$this->logsys .= "Failed to get DB handle: " . $e->getMessage() . "\\n";
            echo "Failed to get DB handle: " . $e->getMessage();
        }
    }

 function select($sql)
 {
  if(!$this->_CONN) { $this->connect(); }

  $_CONN = $this->_CONN;

  $this->_RESULT = $_CONN->query($sql);

  return $this->_RESULT;
 }

 function get_rows()
 {
  return $this->_RESULT->fetchAll();
 }

 function excute($sql)
 {
  if(!$this->_CONN) { $this->connect(); }

  $_CONN = $this->_CONN;

  $this->_RESULT = $_CONN->prepare($sql);
  $this->_RESULT->execute();

  return $this->_RESULT;
 }
}
?>

”MSSQL_TEST.php”

<?
include "config.php";
include "MSSQL_SAMPLE.php";

$_MSSQL = new MSSQL($_DEBUG);
$_MSSQL->connect();
$db_list = $_MSSQL->select("select * from [table_name]");
$db_data = $_MSSQL->get_rows();

// 전체 데이터를 가져와서 출력하는 예제 #1
for($i=0; $i<sizeof($db_data); $i++)
{
    echo $db_data[$i][FIELD_NAME];
}
?>

 

javascript replace all

// 자바스크립트 replace의 경우 1회성 변경만 되므로, 
// 전체 변경을 할 경우 정규식을 통한 변경을 해야됨

function replace_all(str, search_str, replace_str)
{
 return unescape(escape(str).replace(new RegExp(escape(search_str),\'gi\'), replace_str));
}

var return_str = replace_all([문자열], [변경할 문자], [변경될 문자]);
alert(return_str);

 

Cordova 유용한 플러그인

1. Splash Plugin
– cordova plugin add cordova-plugin-splashscreen
– android, ios, windows 8, windows 7 and 8 phone, blackberry 10 지원
– https://github.com/apache/cordova-plugin-splashscreen

2. Local Notification Plugin
– cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications
– android, ios, windows 8.1, windows 10, windows 8.1 phone 지원
– https://github.com/katzer/cordova-plugin-local-notifications

3. Push Notification Plugin
– cordova plugin add https://github.com/phonegap-build/PushPlugin.git
– android, ios, windows 8, windows 8 phone, blackberry 10 지원
– https://github.com/phonegap-build/PushPlugin

4. Device Plugin
– cordova plugin add cordova-plugin-device
– android, ios, windows 8, windows 7 and 8 phone, blackberry 10, Tizen 지원
– https://github.com/apache/cordova-plugin-device

5. Dialog Plugin
– cordova plugin add cordova-plugin-dialogs
– android, ios, windows 8, windows 7 and 8 phone, blackberry 10, Tizen 지원
– https://github.com/apache/cordova-plugin-dialogs

Cordova (Phonegap) 프로젝트 생성

  1. 프로젝트 생성
    – cordova create [project명]
  2. 플랫폼 생성
    – 생성된 [project명] 디렉토리내에서 실행
    – cordova platform add [플랫폼 명]
    – 플랫폼은 android, ios 등 상황에 맞게 설정
    : https://cordova.apache.org/docs/en/4.0.0/guide/platforms/ 참조

Android Base64 Encoding 주의점

android 에서 base64 encoding시 76byte가 넘는경우 자동으로 개행문자를 삽입합니다.

이를 위해서 아래와 같은 코드를 통해 encoding 하면 됩니다.

byte[] data = txt.getBytes(”UTF-8”);
return Base64.encodeToString(data, Base64.NO_WRAP );

edittext 자동 focus 막기

edittext가 포함된 최상단 Layout(Linear혹은 Relative)에 해당 옵션 추가

android:focusable=”true”
android:focusableInTouchMode=”true”

Android Studio SVN Ignore List

File : .idea/workspace.xml
File : .gradle
File : local.properties
Directory : build/
Directory : .idea/libraries/
Directory : app/build/
Mask : *.iws

python CCFI py2exe 관련 오류

RuntimeError: Attempted implicit compile of a cffi module. All cffi modules shou ld be pre-compiled at installation time.

위 오류 출력시

Lib\site-packages\cryptography\hazmat\bindings\utils.py에

tmpdir=’’,

tmpdir=os.path.dirname(os.path.realpath(sys.argv[0])),
로 변경

import os 반드시 추가