2016년 7월 25일 월요일

dfs 알고리즘 : NQueen


package N_Queen;

import java.util.Scanner;

public class source {
static int n;
static int arr[][] = new int[15][15];
static boolean chk[] = new boolean[15];
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
n = sc.nextInt();
System.out.println(back(1));
}
static int back(int k){
if (k==n+1) return 1;
int total=0;
for (int i=1;i<=n; i++){
if(chk[i]) continue;
boolean impossible = false;
for(int j=1; j<k; j++){
if (i-j>0 && arr[k-j][i-j]==1) impossible = true;
if (i+j<=n && arr[k-j][i+j]==1) impossible = true;
}
if(impossible) continue;
arr[k][i] = 1;
chk[i] = true;
total += back(k+1);
arr[k][i] = 0;
chk[i] = false;
}
return total;
}
}

2016년 2월 5일 금요일

composite key in hive with hbase

CREATE TABLE hbase_table_3(key string, value2 int)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES (
"hbase.columns.mapping" = ":key,a:b"
);


INSERT OVERWRITE TABLE hbase_table_3
SELECT coalesce(concat(stock_symbol,'-',year(trade_date)),'NULL'), count(*)
FROM stock_trade
group by coalesce(concat(stock_symbol,'-',year(trade_date)),'NULL');

2016년 1월 16일 토요일

Fitbit REST API : Getting an access_token

After Obtaining User's Consent,
Fitbit.com will redirect to your server.

This is a code for the server.

I'll store access_token and refresh_token.




@RequestMapping(value="/restTest", method=RequestMethod.GET)
public String restTest(@RequestParam(value="code", required=false) String code) {
    StringBuilder sb = new StringBuilder();
    if(code!=null) {
        HttpClient httpclient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(REST_URL_TO_GET_TOKEN);
        httpPost.setHeader("Authorization",AUTH_APPID_APPSECRET);
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("client_id", CLIENT_ID));
        nvps.add(new BasicNameValuePair("grant_type", "authorization_code"));
        nvps.add(new BasicNameValuePair("redirect_uri", REDIRECT_URL));
        nvps.add(new BasicNameValuePair("code", code));
        StringBuilder contentSb = new StringBuilder();
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(nvps));
            HttpResponse response = httpclient.execute(httpPost);
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
                BufferedReader rd = new BufferedReader(new InputStreamReader(
                        response.getEntity().getContent()));
                String line = null;
                while ((line = rd.readLine()) != null) {
                    contentSb.append(line);
                }
            }
            httpPost.abort();
        } catch (Exception e) {
            sb.append("Exception::" + e.getStackTrace().toString());
        }
        sb.append(contentSb.toString());

    } //if(code!=null)
    return sb.toString();
}




Authorization Header Example

This example assumes that the code URI parameter value in the callback URI was 1234567890.
POST https://api.fitbit.com/oauth2/token
Authorization: Basic Y2xpZW50X2lkOmNsaWVudCBzZWNyZXQ=
Content-Type: application/x-www-form-urlencoded

client_id=22942C&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fexample.com%2Fcallback&code=1234567890
Example Response:
{
    "access_token": "eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0MzAzNDM3MzUsInNjb3BlcyI6Indwcm8gd2xvYyB3bnV0IHdzbGUgd3NldCB3aHIgd3dlaSB3YWN0IHdzb2MiLCJzdWIiOiJBQkNERUYiLCJhdWQiOiJJSktMTU4iLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJpYXQiOjE0MzAzNDAxMzV9.z0VHrIEzjsBnjiNMBey6wtu26yHTnSWz_qlqoEpUlpc",
    "expires_in": 3600,
    "refresh_token": "c643a63c072f0f05478e9d18b991db80ef6061e4f8e6c822d83fed53e5fafdd7",
    "token_type": "Bearer",
    "user_id": "26FWFL"
}


2015년 12월 4일 금요일

카산드라에서 하둡으로



SSTable에 대한 이해(cassandra)
http://bcho.tistory.com/657


aeigisthus 참고

NETFILX Tech blod 내용 (2012.2)
http://techblog.netflix.com/2012/02/aegisthus-bulk-data-pipeline-out-of.html


--> rdb와 hdfs간의 데이터 이동은 여간해선 sqoop으로 해결.

hadoop install on my centos7

http://javaworld.tistory.com/77

2015년 11월 27일 금요일

인증서를 포함한 proxy 서버 내에서의 빌드

2015. 11. 19.

Intellij(IDE)로 gradle(or maven) project import 하는데

프로젝트 에러가 남!!

r1> 메모리 부족

a> 여유 메모리를 만들고 나니 다음 스텝으로 이동
 또는 실행설정에 메모리설정을 해줘도 된다고 함.
 (gradle의 경우 여유 메모리가 적을 경우 빌드 시에 에러 발생)


r2> connection 이 안된다. (Connection Failed)

a> 사용자/.m/settings.xml 에 proxy 설정
  <proxies>
    <proxy>
      <id>myproxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>(Proxy서버)</host>
      <port>(Proxy서버 포트)</port>
      <username></username>
      <password></password>
      <nonProxyHosts>localhost,127.0.0.1</nonProxyHosts>
    </proxy>
  </proxies>


a> gradle 설정파일에 http, https proxy를 설정해줘야 한다!!
systemProp.http.proxyHost=(Proxy서버)
systemProp.http.proxyPort=(Proxy서버 포트)
systemProp.http.proxyUser=
systemProp.http.proxyPassword=
systemProp.http.nonProxyHosts=localhost


r3> https 인증 오류

 https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.3.0.RELEASE/spring-boot-gradle-plugin-1.3.0.RELEASE.pom


 Could not GET 'https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.3.0.RELEASE/spring-boot-gradle-plugin-1.3.0.RELEASE.pom.
     > peer not authenticated
여기서 받아와야 하는데,.두둥...
SSL 인증오류가 난다!!!!!!!!!!!!!!!!!!!!!!!!!!!!
(https가 아니라 http로 repository를 변경할 수 있는 건 변경해서 쓰면 해결!)
(내부적으로 설정된 https 주소로 접속한다면............. 아래로 더 내려가보자)

a>

you need to import certificate :

open the 'https://some_server.com/some/path/some.pom' in your favorite browser
export the cert using the Steps to export cert from a web site
copy the cer into JDK_HOME/jre/lib/security folder
open a shell and go to  JDK_HOME/jre/lib/security folder
then import the cer into java using the

cmd창에 입력(원문은 import였는데 해당 명령이 없어서 importcert로 변경해서 씀)
keytool -import -alias <the short name of the server> -file <cert_file_name_you_exported.cer> -keystore cacerts -storepass changeit


keytool -importcert -alias internal_cert -file AAA.cer -keystore cacerts -storepass changeit


--> 내가 속해있는 곳의 네트워크망이 인증서를 가지고 있었다. 그 인증서 파일을 위와 같은 방법으로 저장을 해주면, java를 통한 https 통신을 할 때 자동으로 사용하게 된다. 


(추가설명)
  keytool은 java tool로서, java를 시스템 path에 설정해 놓은 경우 실행 가능하다. 당연히 keytool로 명령을 실행하면 시스템 path에 설정한 java에 인증서를 등록한 것이다.
  그러므로, 이 설정이 통하려면 IDE, Gradle 또는 Maven 작업 시에 사용되는 jdk가 시스템 path에 잡힌 java와 동일해야 한다.



***
2015.12.04 추가 읽어볼 자료.
https, ssl 인증에 대한 내용.

https://opentutorials.org/course/228/4894