用語まとめ

関数

プログラミングにおいての関数とは、計算式や処理を指す。



関数型言語

宣言型プログラミング
どのような手段で探すかを記さない。それは任せる。

命令型プログラミング
データに何らかの処理を加えて、その連続で組み立てていくもの。
関数型言語はここに分類される。



高階関数

関数を引数として受け取る関数のこと。
mapとかとか。



再帰呼び出し

処理が終わった後に自分自身に戻ってくること。
for文とかとか。

とりあえずApache PDFBoxを使ってみる

まずApache PDFBoxをインストール(Gradle)

compile 'org.apache.pdfbox:pdfbox:2.0.5'



とりあえずコードを書いてみる

@Path("/job")
public class Resource {
    @GET
    @UnitOfWork
    @Path("/pdf")
    @Produces(MediaType.TEXT_HTML)
    public PDDocument pdf() throws Exception {
    PDDocument document = new PDDocument();
    PDPage blankPage = new PDPage();
        document.addPage( blankPage );
        // Save the newly created document
        document.save("BlankPage.pdf");
            
        // finally make sure that the document is properly
        // closed.
        document.close();
    return document;
     }
}



実行したらエラー。

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=text/html.



調べてみたら、JSONサービスが足りてなかったっぽいので足す。

compile 'org.glassfish.jersey.media:jersey-media-moxy:2.22.2'



もう一回実行したらまたエラー。

ERROR [2017-05-01 11:49:39,487] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: d92592dce5a88ddf
! org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=text/html, type=class org.apache.pdfbox.pdmodel.PDDocument, genericType=class org.apache.pdfbox.pdmodel.PDDocument.
! at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:247)



@Produces(MediaType.TEXT_HTML)から@Produces(MediaType.APPLICATION_JSON)に変更してみた。



JSONで何かが帰ってきたから成功なのかこれは?
{“allSecurityToBeRemoved”:false,“documentInformation”:{},“resourceCache”:{},“version”:1.4}

BlankPage.pdfというファイルが新たに保存されていたから成功かな…

コンソールからJSONでPOSTする方法

curl -H 'Content-Type:application/json' -X POST -d "{"key":"value", "key":"value"}" http://



エラー

{"code":400,"message":"Unable to process JSON"}



解決方法

curl -H 'Content-Type:application/json' -X POST -d '{"key":"value", "key":"value"}' http://

オプション-d" "から' 'に変更したらうまくいった。

gitでクローンしたプロジェクトがEclipseに反映できない

gitでクローンしたファイルをEclipseでみようと思ってインポートしたら、

No projects are found to import.

とエラー。



原因

cloneしたファイルの中に.classpath.projectがないから



解決

cloneしたファイルのあるディレクトリにEclipseから新規プロジェクトを作成。
さっき作ったプロジェクト内にある.classpath.projectをコピーして、cloneしたファイルにペースト。

インポートできた。

Git リモートのブランチをcloneする

リモートリポジトリをcloneしたものの、ファイルの中身がなかったよー



原因

cloneはmasterにあるものしか含んでいないから (違うブランチにファイルがあった)

解決

なので、リモートにあるブランチをcloneしたい



.gitがあるディレクトリに移動して、リモートにあるブランチを調べる

git branch -r


リモートにあるブランチをcloneする

git checkout -b ブランチ名 origin/ブランチ名

ローカルリポジトリを最新版にして、プッシュするまでの流れ

まずはmasterブランチを最新の状態にする

masterに移動

git checkout master


upstream(fork元)から最新のものを取ってくる

git fetch upstream


fetchしたものをローカルのmasterに反映させる(ローカルのmasterを最新にする)

git rebase upstream/master


最新にしたmasterをプッシュしておく

git push origin master



作業ブランチのコミットを1つにまとめてから最新にする

作業ブランチへ移動

git checkout 作業してるブランチ名


作業中のものを避ける

git stash


masterと差分のコミットを一つにまとめる

git rebase -i master


すると、こんな感じのが出てくる

pick ai9j38h 新機能追加
pick onw832h 修正
pick ji8h84h エラー修正

# Rebase bdd3996..bd66e17 onto bdd3996
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#


iを押してINSERTモードにして二つ目以降のコミットのpicksquashへ変更する

pick ai9j38h 新機能追加
squash onw832h 修正
squash ji8h84h エラー修正

# Rebase bdd3996..bd66e17 onto bdd3996
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

escを押して、:wqで保存する


作業してるブランチを最新にする

git rebase master 作業してるブランチ名


コンフリクトしたら、奴らと戦う


最新にした作業ブランチをプッシュ

git push origin 作業してるブランチ名




参考:GitHubへpull requestする際のベストプラクティス - hnwの日記