petitviolet blog

    icon
    Written by petitviolet

    Getting Started with Panda CSS

    2023-10-15ReactTypeScript
    PandaCSS is a zero runtime CSS-in-JS library powered by Chakra. This post tries to give a getting started document with React.
    [Panda CSS](https://panda-css.com) is a zero runtime CSS-in-JS library powered by [Chakra](https://chakra-ui.com/). What "zero runtime" means is that Panda CSS statically analyze codes during preprocessing phase and then generates CSS which is not JavaScript. It's better in terms of performance an

    Seeded Random in Unity C#

    2023-07-30UnityC#
    Unity provide UnityEngine.Random to access 'random' capabilities, but it's not easy to test it because of its interface. This post describes how to deal with it.
    In Unity, UnityEngine.Random is to deal with random capabilities that can be used as below: cs using System; UnityEngine.Random.value It looks simple, however, as UnityEngine.Random.value is a shared value in the global scope, it's nearly impossible to test codes that are using Unity

    Singleton MonoBehavior to data live through Scene transitions

    2023-06-15UnityC#
    MonoBehavior in Unity spawn in a scene and then get destroyed when the scene is unloaded. But, data should be living even after scene transitions happens. To make it possible, keeping MonoBehaviors live before and after scene transitions.
    This post instructs how to achieve Singleton MonoBehavior in Unity C that stay living even after scene transitions. Singleton is a well-known design pattern in the industry for long time and it's useful for having data and states in-memory or limit an active instance only one at the same time. In

    Terraform to provision GCP CDN for GCS backend

    2023-02-20TerraformGCP
    Provision CDN on GCS in GCP using Terraform
    Google Cloud offers CDN(content delivery/distributed network) that can be backed by Cloud Storage, a.k.a GCS. Terraform supports provisioning CDN in GCP as always. As well as the previous post, in Terraform, variables should be declared in variables.tf but use locals here instead for simplicity

    GCP IAP protected Cloud Run Application by Terraform

    2023-01-18GCPCloudRunTerraform
    Terraform to build a Cloud Run Application protected by GCP Identity-Aware Proxy
    Google Cloud(GCP) has Identity-Aware Proxy that uses ID and contexts to protect applications and VMs from unexpected access. https://cloud.google.com/iap Thanks to IAP, it's a way easy to protect an application running on Cloud Run by requiring Google login within the organization, for example.

    Show filter input if applyable records exist in ReactAdmin

    2022-12-29ReactReactAdmin
    Switch visibility of a filter if records to be applied not exist in React Admin
    [React Admin](https://marmelab.com/react-admin/) provides a capability to filter records shown in a list. https://marmelab.com/react-admin/FilteringTutorial.html Basically, the combo of ReferenceInput and SelectInput works when applying a filter based on referenced resources. However, it some

    How to use Firestore SDK in WebGL built by Unity

    2022-10-15UnityFirestoreC#
    Official Firestore SDK can't run on Unity WebGL. Use .jslib for interacting JS SDK and C#.
    Firebase offers Cloud Firestore which is a well-known NoSQL document datastore that has been widely used in particularly mobile app development. One of the key features of Firestore I think is realtime-ish data propagation through Firestore SDK. When a client is subscribing a (sub-)collection and

    Working with Json over HTTP in Unity

    2022-09-15UnityC#
    To send and receive JSON payload over HTTP in Unity, some techniques needed for de-/serialization.
    Unity provides handy class called UnityWebRequest for sending HTTP requests. See the document for details. [Unity - Scripting API: UnityWebRequest](https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html) As the document illustrates, UnityWebRequest handles Web requests with

    Terraform to manage GCP Service Accounts

    2022-06-30TerraformGCP
    Terraform provides a few methods for managing Service Accounts in GCP. This post attempts to describe how to create Service Accounts in a good manner.
    The Google provider of Terraform has some mechanisms to manage Service Accounts in GCP as followings. - [google_service_account_iam](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_service_account_iam) - google_service_account_iam_policy - google_servi

    Send Google Form notification to Slack via GoogleAppScript

    2022-04-15GAS
    Using GAS to notify new update of Google Form immediately with fancy layout in Slack
    This post aims to describe how to integrate Google Form and Slack through Google App Script. The goal is that when a user submits a response to a form, the result shows up in Slack immediately. Setup Slack App First of all, create a Slack App and let it authorized to be allowed to send chat me

    Merge sorted arrays with ordering in some manner in TypeScript

    2022-02-14TypeScript
    Arrays can be concatnated with Array#concat method but there is no built-in function to concatnating sorted arrays with giving a certain order
    In Rust, iterable objects have peek method to get the next value without advancing the iterator. [Peekable in std::iter - Rust](https://doc.rust-lang.org/stable/std/iter/struct.Peekable.html) This concept could be used to achieve the purpose. In merging 2 arrays with giving a certain order, peek

    How to deploy a Next.js application running on Cloud Run via GitHub Actions

    2022-01-25GCPNext.jsCloud RunGitHub Actions
    Explain how to deploy a blog powered by Next.js to GCP Cloud Run through GitHub Actions
    As I posted before, this blog is running on GCP Cloud Run and also is built with Next.js. https://blog.petitviolet.net/post/2021-12-28/running-a-blog-powered-by-next.js-on-cloud-run Previously, before migrating to Next.js from Gatsby, this blog used to get deployed automatically via GitHub Action

    Running a blog powered by Next.js on Cloud Run

    2021-12-28Next.jsGCPCloud Run
    Build a blog with Next.js and run it on GCP Cloud Run which is a managed platform for enabling users to run containers very easily
    This blog had been built with [Gatsby](https://nextjs.org), but I decided to migrate to [Next.js](https://nextjs.org) just for learning it. This post is going to describe what the arcitecture is and how to deploy this blog to [GCP Cloud Run](https://cloud.google.com/run) which is a serverless platf

    Rehype plugin for oEmbed

    2021-12-20Node.js
    Build a rehype plugin for oEmbed which is a format for allowing embedding a url with nice looking.
    I've posted a couple of posts about oEmbed like https://blog.petitviolet.net/post/2020-03-06/oembed-expansion Needless to say, the above card is build via oEmbed. What Rehype Plugin is First of all, according to [the official repository(rehypejs/rehype)](https://github.com/rehypejs/rehype),

    GraphQL on Scala3 with Sangria

    2021-10-25ScalaGraphQLSangria
    Use sangria-graphql to build GraphQL HTTP server on top of Akka-HTTP in Scala3
    Almost two and a half years ago, I posted a post about how to build a GraphQL HTTP server using sangria-graphql library in Scala2. https://blog.petitviolet.net/post/2018-01-26/scala-sangriaを使ってgraphql-apiを実装する I've spent some time to refresh my knowledge and learn Scala3 features like contextural

    Make Thread synchronous in Rspec

    2021-09-25Ruby
    Stop using sleep to wait for asynchronous execution run on another Thread in Rspec
    tl;dr ruby allow(Thread).to receive(:new).and_yield What's the problem? In Ruby, Thread can be used for asynchronous processings that would take a while. However, the asynchronousity sometimes cause unexpected results in unit tests, like Rspec. Say, a class that uses Thread inte

    allow_any_instance_of to count up number of method calls behind the scene

    2021-08-25Ruby
    Rspec offers allow_any_instance_of to stub any instances that matches given class
    Rspec is one of the most popular test framework in Ruby, and of course it offers lots of functionalities for being able to write various type of test cases, like mock, stub, matcher, etc. allow_any_instance_of is a powerful method, which is able to stub any instance of a class even though using i

    Rust async/await with Trait

    2021-07-24Rust
    Quick note for how to use async/await syntax with Trait in Rust
    Rust supports asynchronous programming with async and await syntax since Rust 1.39.0. https://blog.rust-lang.org/2019/11/07/Rust-1.39.0.html [Asynchronous Programming in Rust](https://rust-lang.github.io/async-book/) would be the best material to learn asynchronous programming in Rust. This

    Subscribe a Web Page using GoogleAppScript

    2021-06-20GASJavaScript
    GoogleAppScript to watch and notify new updates of a web page that doesn't publish RSS feed.
    Some of web pages have RSS feed so that we can get notified when the pages updated through Feedly, Slack, etc. However, some of them don't have such useful features. This post describes how to _subscribe_ web pages that don't offer RSS feeds or something like that. HOW TO Use Google App Script

    Building Relational Database on top of RocksDB in Rust

    2021-05-25DBRustRocksDB
    Developed a tiny database system in Rust with using RocksDB as its underlying storage layer and rust-rocksdb library to interact with RocksDB
    Recently I developed a tiny database system called rrrdb in Rust on top of RocksDB, which is a well-known Key-Value store. "rrrdb" came from Relational-database in Rust with RocksDB, though I'd not say rrrdb is a relational database since it doesn't support having relations between objects at all

    Use RocksDB from Rust

    2021-03-25RustRocksDB
    Basic usage of rust-rocksdb, and some findings
    RocksDB is an embeddable key-value storage that has been developed by Facebook. Many database products are using RocksDB as their low-level storage layer, such as MySQL, MongoDB, TiDB, etc. This post describes the basic usage of RocksDB from Rust. OSS community has been developing [rust-rocksdb](h

    Apache Flink Basics

    2021-02-10Apache Flink
    Apache Flink overview and basic knowledges
    The last 2 posts described how to launch Apache Flink and run realtime streaming applications on it with Apache Kafka. https://blog.petitviolet.net/post/2020-12-14/getting-started-with-apache-flink https://blog.petitviolet.net/post/2021-01-15/apache-flink-with-apache-kafka In order to understand

    Apache Flink with Apache Kafka

    2021-01-15Apache FlinkApache Kafka
    Running a simple streaming application on top of Apache Flink with using Apache Kafka as Source and Sink
    This post describes how to utilize Apache Kafka as Source as well as Sink of realtime streaming application that run on top of Apache Flink. The previous post describes how to launch Apache Flink locally, and use Socket to put events into Flink cluster and process in it. Please refer to it to get

    Getting Started with Apache Flink

    2020-12-14Apache Flink
    How to launch Apache Flink locally by standalone, Docker, and Kubernetes. Also how to run my own streaming application on that.
    > Apache Flink is a framework and distributed processing engine for stateful computations over unbounded and bounded data streams. https://flink.apache.org/flink-architecture.html In my words, we can run stateful streaming applications on top of it that consume unbounded data come from wherever

    Fix GCP Deployment from GitHub Action

    2020-11-23GoogleAppEngineGitHub Actions
    Update GCP related GitHub Action configurations to fix deployment issues
    Previously, I posted about how to deploy this blog via GitHub Actions to Google AppEngine. https://blog.petitviolet.net/post/2020-03-10/deploy-blog-via-github-actions However, because of recent updates, it started failing. This post describes how to update the GitHub Action configurations to fix

    Call Another Controller Action In Rails

    2020-11-16Rails
    Implement a controller action depending on another controller without using inheritance and redirection
    Sometimes we want to reuse a controller's action in another controller for some reasons. We know redirect is an answer of that, however, there is no way to touch the response when using redirect, and it might be necessary to modify the response, such as transforming response body to another format.

    GitHub Action for Rust Project Test and Benchmark

    2020-10-08Rust
    Set up GitHub Action for Rust project to run tests and benchmarks
    I've been learning Rust as posted previously. https://blog.petitviolet.net/post/2020-09-15/sorted-string-table-in-rust This project has a small amount of tests as well as benchmark. To enable running tests and benchmark to validate how recent changes affect both functionality and performance, I d

    Sorted String Table in Rust

    2020-09-15RustDB
    Implement SSTable to learn Rust and for fun
    Recently, I've been learning Rust. Then, I started implementing sorted string table in Rust in order to learn Rust deeply and also understand SSTable architecture, which is used by underlying storage engines in various modern database softwares. I'm going to describe what I implemented as my first

    Reading Note - Spanner paper

    2020-08-01DBReading
    Reading note of a paper of Google's Spanner which is a well-known globally distributed database
    This post is my reading note for the paper of Spanner. Distributed SQL database and also NewSQL are a kind of trends in our industry. I think that Spanner, Google's globally-distributed database, is the beginning of such era. The paper is available [here](https://research.google.com/archive/spanne

    Ruby on Rails on YugabyteDB

    2020-07-13RubyDB
    How to use YugabyteDB as a backend storage of Ruby on Rails application.
    YugabyteDB is "The Leading High-Performance Distributed SQL Database". https://www.yugabyte.com/ It has been developed as an open source and called [Distributed SQL](https://blog.yugabyte.com/what-is-distributed-sql/). YugabyteDB is a Distributed SQL product, like Google Cloud Spanner which is

    Tiny compiler written in Ruby

    2020-06-20Ruby
    Build a tiny compiler for a toy programming language in Ruby
    As a software engineer's habit, I've implemented a toy programming language in Ruby for my learning. GitHub repository is [petitviolet/9cc-ruby](https://github.com/petitviolet/9cc-ruby.git). What it looks like Almost *basic* syntax is supported, and only int type is available. - use number

    Reading Note - Presto The Definitive Guide

    2020-06-06DBReading
    Reading note of Presto the Definitive Guide, architecture ovewview, terminologies
    A book about [Presto](https://prestosql.io/), "Presto: The Definitive Guide" has been published by Starburst. We can get PDF for free from here [O'Reilly Presto Guide Download – Starburst Data](https://www.starburstdata.com/oreilly-presto-guide-download/) The book covers a broader themes of [Prest

    Build oEmbed API for Gatsby blog

    2020-05-22GatsbyGo
    Build an API for oEmbed expansion of blog posts powered by Gatsby
    Previously, I wrote a post about that this blog has a capability to expand oEmbed articles using [raae/gatsby-remark-oembed](https://github.com/raae/gatsby-remark-oembed). https://blog.petitviolet.net/post/2020-03-06/oembed-expansion As it is embed here, this blog is also able to expand self post

    ksqlDB first impression

    2020-05-08Apache Kafka
    Getting started ksqlDB, and how it works
    Recently, I've listened a couple of podcast episodes about ksqlDB. - [kSQLDB: Kafka Streaming Interface with Michael Drogalis - Software Engineering Daily](https://softwareengineeringdaily.com/2020/04/07/ksqldb-kafka-streaming-interface-with-michael-drogalis/) - [Easier Stream Processing On Kafka

    Configure custom 404 in GAE with Gatsby

    2020-05-01GoogleAppEngineGatsby
    How to write app.yaml to specify 404 in static file hosting
    tl;dr Use require_matching_file: true for not 404, and wildcard routing for 404 to handle the other paths. yaml:title=app.yaml - url: /(.*) static_files: public/\1 upload: public/(.*) secure: always require_matching_file: true - url: /(.*) static_files: public/404.html upload

    Empower Pattern Matching in Ruby

    2020-04-10RubyFunctional Programming
    Quick overview of pattern match in Ruby and Gems to empower it
    Ruby2.7 provides Pattern Matching feature as an experimental one. https://www.ruby-lang.org/en/news/2019/12/25/ruby-2-7-0-released/ I used to do pattern matching in Scala, so I'm excited to be able to use it in Ruby! tl;dr [Rstructural Gem](https://github.com/petitviolet/rstructural) what I'

    Circuit Breaker in Ruby

    2020-04-16RubyFunctional Programming
    Introduction of Circuit Breaker and RCB gem I developed
    I've developed a circuit breaker in Ruby, and published it as rcb gem in RubyGems.org. - GitHub: [petitviolet/rcb](https://github.com/petitviolet/rcb) - RubyGems: [rcb](https://rubygems.org/gems/rcb) What is CircuitBreaker? CircuitBreaker is a well-known pattern to make services stable that

    Imported blogs from Qiita

    2020-03-28QiitaRuby
    Download my contents and tranform into Gatsby style
    Qiita began to provide a feature to show what types of articles I write and put +1. At that time, they made when I read public without opt-in. [ユーザーページをリニューアルしました - Qiita Blog](https://blog.qiita.com/user-page-renewal/) I'd like not to make my browsing histories public, so I was going to delete my

    Scheduled blog publishing

    2020-03-25GitHub Actions
    Schedule a pulishing of new blog entry using GitHub Action
    When I write a new blog entry, I'd like to schedule its publishing since usually write them at night and it's not a good time to make it open. As I write in [the last post](/post/deploy-blog-via-github-actions), this blog is running on GAE and deployed via GitHub Actions when PR is merged. Therefor

    Manage new entry using GitHub Actions

    2020-03-18GoogleAppEngineGitHub Actions
    Deploy preview version and notify it
    [The previous entry](/post/deploy-blog-via-github-actions) describes how to deploy static sites through GitHub Actions. As the next step, this entry is going to show how to manage new entries, and also how to publish entries based on schedules. Deploy preview versions triggered by pull requests

    Deploy blog via GitHub Actions

    2020-03-10GoogleAppEngineGitHub Actions
    Deploy automation using GitHub Actions.
    This blog(https://blog.petitviolet.net) is hosted on Google AppEngine(a.k.a GAE). GAE is super useful not only for dynamic WEB applications but also for static sites. To deploy applications and sites on GAE, it just needs to call gcloud app deploy command. Speaking of GAE deployments, it usuall

    oEmbed expansion in Gatsby

    2020-03-06Gatsby
    oEmbed expansion in Gatsby
    [oEmbed](https://oembed.com/) > oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.

    Hello World

    2020-03-04Gatsby
    New Blog using Gatsby
    Created a new blog with using [GatsbyJS](https://www.gatsbyjs.org/) and [gatsby-starter-blog](https://github.com/gatsbyjs/gatsby-starter-blog). The end of the fiscal year is a good time to build something new. 1 year ago, I renewed my portfolio as well using Gatsby. https://petitviolet.hatenabl

    KubernetesにおけるPodの初期化処理

    2018-12-04Qiitakubernetes
    これはなに?本記事ではKubernetesにおけるPodという形でアプリケーショ
    これはなに? 本記事では Kubernetes における Pod という形でアプリケーションを起動する際、どのように初期化処理を実行できるのかについて取り上げる。 なお終了処理は触れない。 lifecycle.postStart を使う spec.containers.lifecycle.postStartを利用すればライフサイクルにおける"起動"直後に何かしら処理を差し込むことが可能。 これは Pod の起動、ENTRYPOINT や CMD と同時(非同期)に実行される。 ドキュメント: [Attach Handlers to Container Lifecycle

    ScalaをGraalVMで動かす&ネイティブイメージ化する

    2018-12-01QiitaJavaScalagraalvm
    Scalaプログラマの観点からGraalVMを紹介、使ってみる。GraalVM?
    Scala プログラマの観点から[GraalVM](https://www.graalvm.org)を紹介、使ってみる。 GraalVM? [GraalVM](https://www.graalvm.org)は、思い切り雑に紹介すると Scala(Java)プログラムを高速化することが出来る(ことがある)らしい。 このあたりを読むともう少し詳しく書いてある。 https://www.graalvm.org/docs/why-graal/for-java-programs 簡単にまとめておくと、特徴としては 1. Java を高速化 JIT コンパイルになにかしら改良が

    GraphQLの認証をどこでやるか

    2018-07-16QiitaScalaGraphQLsangria
    GraphQLなAPIを実装するにあたって、認証をどうするか。-GraphQL内
    GraphQL な API を実装するにあたって、認証をどうするか。 - GraphQL 内部で認証する - GraphQL の外で認証する - 認証とスキーマ 参考: - [A guide to authentication in GraphQL – Apollo GraphQL](https://dev-blog.apollodata.com/a-guide-to-authentication-in-graphql-e002a4039d1) - [Learn Sangria](https://sangria-graphql.org/learn/)の[Authentication a

    SangriaでGraphQLのinterfaceを扱うには

    2018-07-01QiitaScalaGraphQLsangria
    sangria-graphql/sangriaを使ってGraphQLなAPIを実
    [sangria-graphql/sangria](https://github.com/sangria-graphql/sangria/)を使って GraphQL な API を実装する時に interface をどうやって使うか、という話。 interface 自体は特に難しい話ではないが、地味に動かなくて困ったので残しておく。 まとめ - interface の実装自体はInterfaceTypeを使うだけ - Field.fieldTypeにInterfaceTypeを与えるだけだと Scheme がエラーになる - 解決策として - Schema.a

    Scala - SangriaでUpdateCtxを使ってGraphQLの認証を実装する

    2018-04-27QiitaScalaGraphQLsangria
    Scala用GraphQLフレームワークのsangriaでUpdateCtxを使
    Scala 用 GraphQL フレームワークの[sangria](https://github.com/sangria-graphql/sangria/)でUpdateCtxを使って認証処理を実装する。 使い方に注意点がいくつかあるが、まずは普通に動かすための方法について。 UpdateCtx を使って実装する 認証処理に関するドキュメントは[Learn Sangria](http://sangria-graphql.org/learn)の[Authentication and Authorisation](http://sangria-graphql.org/learn/

    kubernetesで動かすコンテナのヘルスチェック

    2018-04-01Qiitakubernetes
    この記事は何タイトル通り。kubernetes上でコンテナなWebアプリを動かす
    この記事は何 タイトル通り。 kubernetes 上でコンテナな Web アプリを動かす時に必要になってくるヘルスチェックや起動時のデータ読み込みをどうやって設定するか。 ドキュメントはこの辺り。 [Configure Liveness and Readiness Probes | Kubernetes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/define-readiness-probes) コンテナのヘルスチェックには 2 種類

    kubernetesで動かすソフトウェアの設定をConfigMapで記述する

    2018-03-18Qiitakuberneteskubectl
    まとめnginx.confなどの設定ファイルをkubernetesのConfig
    まとめ nginx.conf などの設定ファイルを kubernetes の ConfigMap で記述し、Volume としてマウントすることが出来る。 ドキュメントはこの辺り。 - [Configure a Pod to Use a ConfigMap | Kubernetes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/add-configmap-data-to-a-volume) - [Volumes | Kubernetes](https://ku

    Macでminikubeを使ってkubernetesクラスタを動かす

    2018-03-17Qiitakubernetesminikube
    タイトル通り。minikubeでローカルにkubenetesクラスタを構築してみ
    タイトル通り。 [minikube](https://github.com/kubernetes/minikube)でローカルに kubenetes クラスタを構築してみる。 インストール Homebrew-Cask で簡単にインストール出来る。 $ brew cask install minikube 事前準備 $ minikube start して minikube を起動する。 そして、kubectlで認識されることを確認する。 $ kubectl config current-context minikube

    gRPCのサーバ/クライアントをScalaで実装する

    2018-02-28QiitaScalasbtgRPC
    この記事はなに?ScalaでgRPCなアプリケーションを作るためのやりかた。具体
    この記事はなに? Scala で gRPC なアプリケーションを作るためのやりかた。 具体的には 4 つの通信方式、 - unary - server straming - client streaming - bidirectional streaming それぞれについてサーバ/クライアントを Scala で実装する。 **参考** - [gRPC | Scala での Protocol Buffer](http://xuwei-k.github.io/scala-protobuf-docs/grpc.html) - [scala で gRPC する - Qiita](

    Scalaで作ったWebアプリをDockerizeして動かす

    2018-02-09QiitaScalasbtDocker
    この記事はなにタイトル通り。主にsbt-native-packagerのとりあえ
    この記事はなに タイトル通り。 主に sbt-native-packager のとりあえずの使い方紹介。 Akka-HTTP で Web アプリを実装し、sbt-native-packager を使って Docker イメージを作成、localhost で稼働させて HTTP リクエストを受け付けられるようにするまで。 環境 - Scala 2.12.4 - sbt 1.0.4 - [Akka-HTTP](https://doc.akka.io/docs/akka-http/current/) 10.0.10 - [sbt-native-packager](http:/

    SangriaでGraphQL APIを実装するのに知っておきたいこと

    2018-01-30QiitaScalaGraphQLsangria
    この記事はなにSangriaでGraphQLなAPIを実装するにあたって、公式の
    この記事はなに [Sangria](http://sangria-graphql.org)で GraphQL な API を実装するにあたって、公式のサンプルだけだと少し足りないためそれの補足というか tips 的な記事。 Sangria の導入にはこちらをどうぞ。 [[Scala]Sangria を使って GraphQL API を実装する - Qiita](https://qiita.com/petitviolet/items/e3e87c3f3e740b3c57ba) 複数のモデルにアクセスしたい [Ctx と Val についての補足](https://qiit

    Scala - Sangriaを使ってGraphQL APIを実装する

    2018-01-26QiitaScalaGraphQLsangria
    この記事はなに?ScalaでGraphQLサーバを実装するためのsangria/
    この記事はなに? Scala で GraphQL サーバを実装するための[sangria/sangria](https://github.com/sangria-graphql/sangria)の導入。 [公式ドキュメント](http://sangria-graphql.org)および[Larning Sangria](http://sangria-graphql.org/learn/)を読むのが一番速い。 さらに公式がサンプルも用意しているので、そちらを参照するのが良い。 [sangria-graphql/sangria-akka-http-example](https://

    GAE SE for Java8でStackdriver Loggingのログがずれる問題

    2017-12-17QiitaJavaScalaGAEgcpStackdriverLogging
    GoogleAppEngineStandardEnvironmentforJav
    Google AppEngine Standard Environment for Java8 に乗せたアプリケーションで非同期処理しつつログ出力すると、 ログがリクエストに正しく紐付かずに別のリクエストのログとして出力されてしまう、という細かすぎて伝わらない問題と戦った話です。 なお言語は Scala で、[Skinny Micro](http://skinny-framework.org/documentation/micro.html)を使用。 まとめ まず結論。 GAE では独自のスレッドではなくThreadManager.createThreadForCurrentR

    テストコードを楽に書きたい

    2017-12-04QiitaScalaunittestScalaCheckproperty-based-testing
    この記事はなにPropertyBasedTestingは何となく難しくて普通のア
    この記事はなに Property Based Testing は何となく難しくて普通のアプリケーション開発におけるテストコードには使用しないイメージかも知れないが、単にテストデータ自動生成器くらいに捉えてカジュアルに使ってみてはいかがでしょうか?という紹介です。 言語には Scala を用いますが、他言語でも探せばライブラリやフレームワークは見つかると思います。 UnitTest って面倒くさいですよね JUnit とか ScalaTest で書いているテストは Example Based Testing と呼ばれるもので、いわゆる UnitTest が指しているもののはず

    Scala - ScalazのTaskを使う上で知っておきたいこと

    2017-11-17QiitaScalascalaz
    この記事は何?scalazのTaskを使う上で知っておきたいtipsとか注意点と
    この記事は何? scalaz の Task を使う上で知っておきたい tips とか注意点とか。 以前、こういう記事を書いた。 [[Scala]scalaz の Task は何が嬉しいのか - Qiita](https://qiita.com/petitviolet/items/18b1108ab904172baf61) > Scala の Future と同じようなこと出来る + 便利な API が生えているというイメージ。 と書いたが、実際に使っていく上ではもう少し知っておくべきことがあるのでまとめておく。 Task は遅延評価される 改めて、Task は遅延評

    Scala - scalazのTaskは何が嬉しいのか

    2017-09-30QiitaScalascalaz
    Task?scalaz/scalazにあるクラス。[scalaz/Task.sc
    Task? [scalaz/scalaz](https://github.com/scalaz/scalaz)にあるクラス。 [scalaz/Task.scala](https://github.com/scalaz/scalaz/blob/473c99f0fe07bf51a36cf5a08fa334659422f7b3/concurrent/src/main/scala/scalaz/concurrent/Task.scala) これは[scalaz/Future.scala](https://github.com/scalaz/scalaz/blob/473c99f0fe0

    Scala - case classのコンストラクタを隠蔽する

    2017-09-26QiitaScala
    この記事はなに?caseclassを使いながらコンストラクタを隠蔽してファクトリ
    この記事はなに? case class を使いながらコンストラクタを隠蔽してファクトリー経由で生成するように強制したい。 ここでいう"コンストラクタ"はnewで生成する通常コンストラクタに加えて case class で自動生成されるapplyも対象としている。 まとめ - sealed abstract case classを使う - [こちらのコメント](https://qiita.com/petitviolet/items/b6af2877f64ebe8fe312comment-08e2ffe396177bf5a252)をご参照下さい(@aoiroa

    shellでTTL付きのキャッシュをしたい

    2017-05-04QiitaZshshell
    こんな感じsleep3;echoの結果を最大5秒間キャッシュしている様子。![c
    こんな感じ sleep 3 ; echoの結果を最大 5 秒間キャッシュしている様子。 ![cache-ttl-on-sh.gif](https://qiita-image-store.s3.amazonaws.com/0/280/48a2a249-cc43-3a5b-ab5a-511e6df326da.gif) キャッシュの実装 実装は[このあたり](https://github.com/petitviolet/dotfiles/blob/71e0102270dfb424f4204a4cedb36b3020ac81ee/_zshrc.aliasL327-L369)に置

    メタプログラミングScala

    2017-04-18QiitaScalametaprogramming
    社内勉強会の資料をちょっと改変したやつ。メタプロ&scala.metaの入門編。
    社内勉強会の資料をちょっと改変したやつ。 メタプロ & scala.meta の入門編。 メタプログラミングとは > プログラミング技法の一種で、ロジックを直接コーディングするのではなく、あるパターンをもったロジックを生成する高位ロジックによってプログラミングを行う方法、またその高位ロジックを定義する方法のこと。 [メタプログラミング - wikipedia ](https://ja.wikipedia.org/wiki/メタプログラミング) つまり プログラムを引数としてプログラムを出力とする関数、みたいなもの。 リフレクションも一種のメタプログラミングで、文字列から

    scalametaに入門する

    2017-02-19QiitaScalametaprogrammingmeta
    scalametaはinlinemacroと呼ばれるmacroannotatio
    scalameta は inline macro と呼ばれる macro annotation のためのツールキット。 型安全に macro 出来る。 公式とチュートリアルは以下。 - [scala.meta](http://scalameta.org/) - [A Whirlwind Tour of scala.meta](http://scalameta.org/tutorial/Part4-Macroannotations) setup まずは使えるようにするために build.sbt に追記。 sbt libraryDependencies += "org.sc

    scalametaでの型パラメータとコンストラクタ

    2017-02-19QiitaScalametaprogrammingmeta
    tl;dr直接、annotationclassの型パラメータやコンストラクタには
    tl;dr 直接、annotation class の型パラメータやコンストラクタにはアクセス出来ない。 その代わりに、thisを用いてパターンマッチで取得することが出来る。 題材 mix-in injection とか minimal cake pattern と呼ばれる、DI 対象となる class を mix-in する macro annotation を実装した。 - Uses[MyService]とするとval myService: MyServiceがフィールドに追加される - MixIn[MyService](new MyServiceImpl)

    Akka-PersistenceのserializerとしてKryoを使う

    2017-01-23QiitaScalaAkkaactor
    とりあえず使えるようにするAkka-PersistenceでKryoをとりあえず
    とりあえず使えるようにする Akka-Persistence で Kryo をとりあえず使えるようにする設定については以前書いた。 [Akka-Persistence コトハジメserializer として kryo を使う](http://qiita.com/petitviolet/items/92826357bd10aace14f5serializer%E3%81%A8%E3%81%97%E3%81%A6kryo%E3%82%92%E4%BD%BF%E3%81%86) serializer 選択について Akka-Persistence のPersistentActo

    ActorでCircuitBreakerを実装してみた話

    2016-12-05QiitaScalaAkkaactor
    実装してみる理由ReactiveSystemやMicroservices等の文脈
    実装してみる理由 ReactiveSystem や Microservices 等の文脈で登場する CircuitBreaker について以前調べた。 - [[Akka]CircuitBreaker はどう動くのか - Qiita](http://qiita.com/petitviolet/items/777be810e3c5756a393d) - [Akka の CircuitBreaker と Netflix の Hystrix の違い - Qiita](http://qiita.com/petitviolet/items/f1975fba06655a95e3b0) Circu

    AkkaのCircuitBreakerとNetflixのHystrixの違い

    2016-12-03QiitaJavaScalaAkka
    この記事はなに?マイクロサービス等の文脈で登場するCircuitBreaker。
    この記事はなに? マイクロサービス等の文脈で登場する[CircuitBreaker](http://martinfowler.com/bliki/CircuitBreaker.html)。 Scala で使えるものの代表(要出典)として以下の 2 つを比較する。 - [Circuit Breaker - Akka Documentation](http://doc.akka.io/docs/akka/current/common/circuitbreaker.html) - シンプルだが単機能 - [Netflix/Hystrix](https://github.com/Netf

    Akka - CircuitBreakerはどう動くのか

    2016-11-28QiitaScalaAkka
    CircuitBreakerとは原典にあたるのは[MartinFowler氏のp
    CircuitBreaker とは 原典にあたるのは[Martin Fowler 氏の post](http://martinfowler.com/bliki/CircuitBreaker.html)になるはず。 リモートへのリクエストが失敗した時にうまいこと障害が伝搬しないようにするためのデザイン。 昨今の Microservice アーキテクチャな文脈だと考えやすい。 特定のサービスがダウンしてしまった時に、 それに依存するサービスが引きずられてダウンしてしまわないようにするもの。 Reactive なシステムを作る上で欠かせない存在になりそう。 CircuitBreak

    Akka-StreamのRunnableGraphの構築パターン

    2016-10-22QiitaScalaAkkaactorAkka-Stream
    Akka-Streamでアプリケーションを実装する場合、SourceとFlowと
    [Akka-Stream](http://doc.akka.io/docs/akka/current/scala/stream/)でアプリケーションを実装する場合、 Source と Flow と Sink を組み合わせてRunnableGraphを構築し、runして実行する。 本記事では Akka-Stream の部品のメインとなる Source, Flow, Sink を、 [Akka-Actor](http://doc.akka.io/docs/akka/current/scala/actors.html)および[ActorPublisher](https://github.

    2016年だけどMakefileを使ってみる

    2016-10-19QiitaMakefile
    この資料はなに?Makeの良さを伝えるものです-CとかC++の持ち物じゃない-普
    この資料はなに? Make の良さを伝えるものです - C とか C++の持ち物じゃない - 普段使うコマンドのショートカットみたいな - 2016 年でも Makefile は便利 --- ![ 2016-10-19 19.11.07.png](https://fringe81.qiita.com/files/6b83b0a2-f9d5-4505-67e0-647d64e1ffd2.png " 2016-10-19 19.11.07.png") [頑張らないで Scala 〜VOYAGE GROUP におけるアドネットワーク開発の戦略〜 // Speaker Deck](ht

    akka.actor.FSMを永続化出来るPersistentFSM

    2016-08-30QiitaScalaAkkaactor
    状態の保持/状態遷移に長けたFSMと、その状態/状態遷移を永続化する[Akka-
    状態の保持/状態遷移に長けた[FSM](http://doc.akka.io/docs/akka/current/scala/fsm.html)と、その状態/状態遷移を永続化する[Akka-Persistent](http://doc.akka.io/docs/akka/current/scala/persistence.html)の組み合わせとして[PersistentFSM](http://doc.akka.io/docs/akka/current/scala/persistence.htmlPersistent_FSM)がある。 状態を持つ Actor でイベントを永続化したいケー

    Akka-Persistenceコトハジメ

    2016-08-28QiitaScalaAkkaactor
    Akka-Persistenceはstatefulなactorの内部状態
    [Akka-Persistence](http://doc.akka.io/docs/akka/current/scala/persistence.html)は stateful な actor の内部状態を永続化することによって、生成時、再開時、migration 時などに状態を復旧することを可能とするもの。 内部状態に至るまでのイベント(メッセージ)を永続化しておくことで、そのイベントを再生すれば全く同じ状態を再現させることが出来るため、CQRS/ES の文脈で最近はよく出てきている(気がする)。 build.sbt まずは build.sbt に依存を追加する。 バージョンは

    Actorで作る有限オートマトン

    2016-08-24QiitaScalaAkkaactor
    有限オートマトン?FiniteStateMachine(FSM)ざっくり言うとイ
    有限オートマトン? Finite State Machine(FSM) ざっくり言うとイベントを受け取って状態遷移するステートマシン。 詳しくは[Wikipedia](https://ja.wikipedia.org/wiki/有限オートマトン)参照 FSM を Actor で実装する まさにそのためのakka.actor.FSMがあるので、これを使って実装する。 FSM に必要な型を定義する 必要となるのは以下の 3 つの型 - State - FSM の状態 - Data - FSM が内部的に持つ情報 - Event - FSM の

    Akka-HTTP - spray-jsonの使い方とAkka-HTTP

    2016-06-02QiitaScalaAkka-HTTP
    Akka-HTTPで公式にサポートされているJSONライブラリのspray-js
    Akka-HTTP で公式にサポートされている JSON ライブラリの[spray-json](https://github.com/spray/spray-json)の使い方。 [JSON Support — Akka Documentation](http://doc.akka.io/docs/akka/2.4.4/scala/http/common/json-support.html) Akka-HTTP と一緒に使いたいので、Marshaller/Unmarshaller として使用法も載せる。 tl;dr - クラスのフィールドに独自の型を使わない場合 or 独自の型に対応

    Akka-HTTP - DSLにおける暗黙の型変換

    2016-05-28QiitaScalaAkkaAkka-HTTP
    akka.http.scaladslパッケージをimportすることで使えるよう
    akka.http.scaladslパッケージを import することで使えるようになる DSL が、 裏側でどのように実装されているか気になったので調べた。 題材 akka-http において、単純なルーティングについて考えてみる。 scala val route = path("ping") { get { complete("pong") } } localhost:8080/pingに GET リクエストを送ると期待通りにpongと返ってくる。 $ curl localhost:8080/ping pong

    Akka-HTTPを型で縛る

    2016-05-27QiitaScalaAkkaAkka-HTTP
    httpリクエスト/レスポンスでやり取りするStringな値をアプリケーションが
    http リクエスト/レスポンスでやり取りする String な値をアプリケーションが期待する Scala の型に変換する方法について。 リクエストを型で縛る ユーザーからのリクエストをなるべくStringとして触らないようにする。 URL パラメータ 以下のルーティングを考える。 GET /message?id=&body=' URL パラメータのidとbodyをなるべくString以外で扱う。 まず、型を用意する。 scala sealed trait Content { val id: Long

    Akka-HTTP - カスタムヘッダーの取り扱い方

    2016-05-19QiitaScalaAkkaAkka-HTTP
    標準で用意されていない独自のヘッダーを定義して使いたいケース。大雑把に、文字列と
    標準で用意されていない独自のヘッダーを定義して使いたいケース。 大雑把に、文字列として扱う場合と型で扱う場合に分ける 文字列で扱う headerValueByNameで良い。 引数にSymbolかStringを渡せば、それにマッチするヘッダーの値が取り出せる。 scala val route = path("header" / "ping") { get { headerValueByName('Message) { msg: String => complete(s"pong: $msg") } }

    Akka-HTTP - ルーティングDSLの基本となるPathMatcherのまとめ

    2016-05-17QiitaScalaAkkaAkka-HTTP
    Pathを構築するためのDSLであるDirectiveとPathMathcerに
    Path を構築するための DSL であるDirectiveとPathMathcerについて。 ドキュメントは以下。 [The PathMatcher DSL — Akka Documentation](http://doc.akka.io/docs/akka/2.4.4/scala/http/routing-dsl/path-matchers.html) tl;dr 大体ここに書いてある。 [The PathMatcher DSL — Akka Documentation](http://doc.akka.io/docs/akka/2.4.4/scala/http/rout

    MonadicでReactiveなSlick3.xを使う

    2016-03-30QiitaScala
    MonadicでReactiveだと言われているSlick3.xを使ってみる。本
    Monadic で Reactive だと言われている Slick3.x を使ってみる。 本記事時点での最新はは 3.1.1 となっている。 公式のサンプルだと h2 を使っていたが、今回はローカルに立てた MySQL を使用する。 [Getting Started — Slick 3.1.1 documentation](http://slick.typesafe.com/doc/3.1.1/gettingstarted.htmlquick-introduction) 準備 事前にuserテーブルを作っておく sql Create Table: CREATE TAB

    静的ダックタイピングのパフォーマンスとその仕組み

    2015-12-22QiitaScala
    ここでの静的ダックタイピングはScalaの構造的部分型(StructuralTy
    ここでの静的ダックタイピングは Scala の構造的部分型(Structural Typing)を用いて実現されるものを指しています。 構造的部分型については以下が参考になるかと思います。 - [構造的部分型について - Qiita](http://qiita.com/tacke_jp/items/657626a08a02b5ecd0a62-1) - [Scala School - Advanced types](https://twitter.github.io/scala_school/advanced-types.htmlstructural) - [Structural typ

    気持ちよくAndroidを書くために

    2015-12-03QiitaJavaAndroid
    ちょっとでもJava7なAndroidを気持ちよくプログラミングしたい、Java
    ちょっとでも Java7 な Android を気持ちよくプログラミングしたい、 Java っぽい(?)ところがありつつもモダンなパラダイムが取り入れられている Scala が羨ましく見えたので、Scala っぽく書きたいという意志から書いています サンプルコードでは紙面の都合上、retrolambda で lambda 式使っています Scala の羨ましいところ 挙げればキリが無いですが、以下とします - 関数型プログラミング - 強力な式 関数型プログラミングっぽく これについては[Roppongi.aar 2 - connpass](http://roppon

    数字の文字列をread使って数字列に変換する

    2015-09-22QiitaHaskell
    やり方read.returnを使って型を指定すれば良い haskellPrelu
    やり方 read . returnを使って型を指定すれば良い haskell Prelude> let n = "123456789" :: String Prelude> n "123456789" Prelude> map return n :: [String] ["1","2","3","4","5","6","7","8","9"] Prelude> map (read . return) n :: [Int] [1,2,3,4,5,6,7,8,9] Prelude> map (read . return) n :: [Float] [1.0,2.0,3.0,4.

    React Native for Androidでアプリを作る

    2015-09-16QiitaAndroidreactnative
    [ReactNativeforAndroid:Howwebuiltthefirs
    [React Native for Android: How we built the first cross-platform React Native app | Engineering Blog | Facebook Code](https://code.facebook.com/posts/1189117404435352/) [React Native | A framework for building native apps using React](http://facebook.github.io/react-native/) Setup Android S

    constなNSStringでdiscards qualifiers警告が出る

    2015-09-08QiitaObjective-CiOS
    元の解説はこちら[objectivec-"sending'constNSStr
    元の解説はこちら [objective c - "sending 'const NSString _' to parameter of type 'NSString _' discards qualifiers" warning - Stack Overflow](http://stackoverflow.com/questions/6828831/sending-const-nsstring-to-parameter-of-type-nsstring-discards-qualifier) 起こったこと 以下のように constant な文字列を定義したとき、discard

    AndroidでAssertJを使ってテストする

    2015-08-10QiitaJavaAndroid
    最近知ったAssertJというテストライブラリを使ってみた[AssertJ/Fl
    最近知った AssertJ というテストライブラリを使ってみた [AssertJ / Fluent assertions for java](http://joel-costigliola.github.io/assertj/index.html) > Fluent assertions とあるように流れるような assertion が出来ると聞いてちょっと気になった AssertJ の導入 gradle の設定 [AssertJ / Fluent assertions for java](http://joel-costigliola.github.io/assertj

    h2oをリバースプロキシとして導入してみた

    2015-07-29QiitaHTTPさくらVPSh2o
    流行りのh2o/h2oをインストールして動かしてみたApacheがすでに動いてい
    流行りの[h2o/h2o](https://github.com/h2o/h2o)をインストールして動かしてみた Apache がすでに動いていてその上で PHP とか uwsgi とか動いていたので、今回はリバースプロキシとして導入することにした 環境 さくら VPS $ cat /etc/redhat-release CentOS release 6.6 (Final) $ uname -r 2.6.32-504.3.3.el6.x86_64 インストール [Install - H2O](https://h2o.examp1e.net/install.

    RxJava(RxAndroid)でのBackpressureについて

    2015-07-21QiitaAndroidRxJava
    RxJavaのAndroidバインディングであるRxAndroidを使い始めてB
    RxJava の Android バインディングである[RxAndroid](https://github.com/ReactiveX/RxAndroid)を使い始めて Backpressure ではまったので整理 [retrolambda](https://github.com/orfjackal/retrolambda)で lambda 式使っていますが、使っていなければ適宜newするコードに置き換えてください Backpressure [Backpressure · ReactiveX/RxJava Wiki](https://github.com/ReactiveX/Rx

    OkHttpのメインスレッドコールバックの実装

    2015-07-05QiitaJavaAndroid
    OkHttpがサンプルとして用意している[AsynchronousGet](ht
    OkHttp がサンプルとして用意している[Asynchronous Get](https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/AsynchronousGet.java)レシピのように、OkHttp をバックグラウンド通信に使用した時、CallbackクラスのonFailuerとonResponseはどちらもバックグラウンドで実行される Android で OkHttp を使う場合、バックグラウンド通信しなければならない理由から、コールバックをメインス

    Androidバージョンの違いをCustomViewで吸収する

    2015-06-01QiitaAndroid
    新し目のバージョンのAndroidにしか無いViewを使いたいが、xmlをバージ
    新し目のバージョンの Android にしか無い View を使いたいが、xml をバージョンで分けたりしたくない そこで、そういった View をラップする CustomView を作る 今回、ICS 以上でTextureView、それ以下でSurfaceViewを使ったカメラを実装した リポジトリ https://github.com/petitviolet/MultiCamera 記事中のコードはこのリポジトリの一部抜粋となっています ライブラリとして使用 Github に aar をアップロードしたので、以下のように記述するとライブラリとして使用できます

    Gradleのtaskをpecoで選択する

    2015-05-24QiitaAndroidZshgradle
    Gradleを使ってAndroid開発しているとき、Gradleのtaskを選択
    Gradle を使って Android 開発しているとき、Gradle の task を選択することが多く、以前書いた内容で TAB 補完は出来るようになった [Android - Gradle を Zsh で補完する - Qiita](http://qiita.com/petitviolet/items/11ae1c7791e6343a6c1e) 今回は、task を TAB 補完ではなく peco で選択出来るようにした ![gradle_comp.gif](https://qiita-image-store.s3.amazonaws.com/0/280/5b09e355-75e7-7

    treeからpecoで選択したファイルをvimで開く

    2015-04-28QiitaZsh
    shfunctionpeco-tree-vim(){localSELECTED
    sh function peco-tree-vim(){ local SELECTED_FILE=$(tree --charset=o -f | peco | tr -d '\|||-' | xargs echo) BUFFER="vim $SELECTED_FILE" zle accept-line } bindkey "^t" peco_tree_vim -fオプションでフルパスを表示しつつ--charsetオプションで罫線に使用する文字を変更して扱いやすくし、pecoで選択した行にある罫線をtrで除去してvimで開く

    CSVのデータを使って散布図とヒストグラムを作る

    2015-02-09QiitaR
    はじめにR-Tips見たら全部わかるデータの用意ファイルの読
    はじめに [R-Tips](http://cse.naro.affrc.go.jp/takezawa/r-tips/r.html) 見たら全部わかる データの用意 ファイルの読み込み R > data <- read.csv('./plot_tfidf.csv', header=T, sep=",") > data a b 1 0.688 0.1930 2 0.701 0.7370 3 0.705 0.6860 4 0.732 0.0174 5 0.341 0.1390 read.csvの引数のheaderにT[RUE]

    TeXを監視して自動コンパイルする

    2015-01-05QiitaRubyTeX
    rubyのguard/guardを使ってファイルの変更を監視して、裏で自動コンパ
    ruby の[guard/guard](https://github.com/guard/guard)を使ってファイルの変更を監視して、 裏で自動コンパイルする 準備 まずguardをインストールする 以下の様な Gemfile を用意する Gemfile source 'http://rubygems.org' gem 'guard' gem 'guard-shell' gem 'rb-readline' gem 'rb-inotify' そして sh gem install bundle bundle install でguard

    Vimでブラウザを操る

    2014-12-22QiitaVimVimperator
    この記事はVimAdventCalendar2014-Qiita22日目の記事で
    この記事は[Vim Advent Calendar 2014 - Qiita](http://qiita.com/advent-calendar/2014/vim) 22 日目の記事です 21 日目の記事は @mitsuse さんの[非英語ネイティブでも Vim で快適に英語を書きたい](http://mitsuse.jp/2014/12/20/vim-ac-2014-writing-english/)でした Vim アドベントカレンダーですが、ちょっと趣向を変えて[Vimperator](https://addons.mozilla.org/ja/firefox/addon/vimper

    Zshで長い処理をしている間に読込中を表示する

    2014-12-21QiitaZshshellgradle
    内容-shellでのバックグラウンド処理 -ジョブ制御フラグ-メタ文字による標準
    内容 - shell でのバックグラウンド処理 - ジョブ制御フラグ - メタ文字による標準出力の管理 [Android - Gradle を Zsh で補完する - Qiita](http://qiita.com/petitviolet/items/11ae1c7791e6343a6c1e)という記事を書いた時に > なお、初回のみタスクの読み込みに時間がかかるが、2 回目以降はファイルキャッシュを読み込むため比較的速くなる と書いたが、初回の読み込み時の長さが気になるので読み込み中である indicator を表示することにした 参考 [Python でローディン

    Qiita API v2のPythonラッパー実装した

    2014-12-20QiitaPythonQiitaAPI
    QiitaAPIv2のPythonラッパーがなかったので作りました-Github
    Qiita API v2 の Python ラッパーがなかったので作りました - Github: [petitviolet/qiita_py](https://github.com/petitviolet/qiita_py) - Pypi: [qiita_v2 0.1.0 : Python Package Index](https://pypi.python.org/pypi/qiita_v2) テストとかdoctestで適当に書いてるのしか無いので、バージョンは0.1.0としています インストール Pypi に登録しているのでpipで出来ます sh pip

    GradleをZshで補完する

    2014-12-18QiitaAndroidZshgradle
    快適なAndroid(Studio)ライフを送りたい内容ZshでもGradleコ
    快適な Android(Studio)ライフを送りたい 内容 Zsh でも Gradle コマンドを補完出来るようにした ![gradle_zsh_complete.gif](https://qiita-image-store.s3.amazonaws.com/0/280/19ab9d9b-a5b8-8bad-5e2d-410e2234fe83.gif "gradle_zsh_complete.gif") 参考 [zsh 補完関数を自作すると便利 - はこべブログ ♨](http://hakobe932.hatenablog.com/entry/2012/02/13/2

    GsonとProguard

    2014-12-11QiitaAndroid
    AndroidでJsonを扱うライブラリとして有名なGsonですが、Progua
    Android で Json を扱うライブラリとして有名な Gson ですが、 Proguard を有効にしたビルドだと問題が発生します 問題 普通だと java new Gson().fromJson(jsonString, Hoge.class); でjsonStringをHogeクラスに変換出来るはずです しかし Proguard を有効にしてあると、Hogeクラスのフィールド名が難読化されて例えばアルファベット 1 文字に変更されているため、 jsonStringにおける json のキー名とHogeクラスのフィールド名が一致しなくなり

    Pythonistaなら知ってるオプションパーサ

    2014-12-02QiitaPythoncliCUI
    この記事はPythonAdventCalendar2014-Qiita2日目の記
    この記事は[Python Advent Calendar 2014 - Qiita](http://qiita.com/advent-calendar/2014/python) 2 日目の記事です 前日は @kureikei さんの[Blender 関連](http://pronama.azurewebsites.net/2014/12/01/python-pronama-chan-blender-add-on/) でした 最近は golang でツールを作るのが流行っていますが、負けじと python ももっと盛り上がって欲しいですね ということで、コマンドラインツールを作る時に必要な引

    Androidのoptions menuまわりのtips

    2014-11-28QiitaJavaAndroid
    -ActionBarメニューの表示/非表示を切り替える-Fragmentにメニュ
    - ActionBar メニューの表示/非表示を切り替える - Fragment にメニューを表示させる ActionBar メニューの表示/非表示を切り替える 概要 ActionBarActivityな Activity の ActionBar にあるメニュー(options menu)について、 java MenuItem item = menu.findItem(R.id.menu_id); item.setVisible(false); をしても消えてくれなかった options menu を何とかして消す やり方 java:ti

    DexIndexOverflowExceptionと戦った話

    2014-11-16QiitaJavaAndroidAndroidStudio
    AndroidStudioでビルドした時に、com.android.dex.De
    Android Studio でビルドした時に、 com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 っていうが出て困った。 なんとか解決したので、メモ 参考 - [Building Apps with Over 65K Methods | Android Developers](http://developer.android.com/tools/building/multidex.html) - [android - Unable to execute dex: met

    Android StudioでJavaDocを生成する

    2014-11-08QiitaJavaAndroid
    頑張って書いたJavaDocをAndroidStudioから生成する手順環境An
    頑張って書いた JavaDoc を Android Studio から生成する手順 環境 Android Studio 0.8.6 jdk1.7.0_60.jdk 手順 メニューの[Tools] -> [Generate JavaDoc...]を選択 ![スクリーンショット_2014-11-09_0_19_48.png](https://static.petitviolet.net/image/qiita_58_431bb849-2283-5bc7-71f9-1dfe225409d1.png "スクリーンショット_2014-11-09_0_19_48.png")

    Fragment自身を終了させる

    2014-11-08QiitaAndroid
    Fragment自身でActivityで言うところのfinish()を実行したい
    Fragment自身でActivityで言うところのfinish()を実行したい java getFragmentManager().beginTransaction().remove(this).commit(); で出来た 追記 backstack がある場合は以下の方がいいでしょう java getFragmentManager().popBackStack(); from: https://qiita.com/petitviolet/items/9a8302d1f08fbde1fc65

    Ansibleでローカルのディレクトリをリモートにコピーする

    2014-09-27QiitaAnsible
    まとめAnsibleでローカルのファイル/ディレクトリをリモートに持っていくため
    まとめ Ansible でローカルのファイル/ディレクトリをリモートに持っていくためには synchronizeではなくcopyモジュールを使えば良い synchronizeとcopy [ansible directory copy - Google 検索](https://www.google.co.jp/search?q=ansible+directory+copy)すると、copyとsynchronizeの 2 つのコマンドが出てくる![kobito.1411812903.512220.png](https://static.petitviolet

    Flaskでloggingの設定を外部ファイルから読み込む

    2014-09-23QiitaPythonFlask
    Flaskで普通にloggingをする場合、Flaskloggingexampl
    Flask で普通に logging をする場合、[Flask logging example](https://gist.github.com/ibeex/3257877)のように、 py:title=app.py app = Flask(__name__) app.logger.debug("test message") のようにすれば簡単に出来る。 しかし、loggingの外部ファイルから設定を読み込むfileConfig py:title=fileConfig import logging.config logging.config.fileConf

    Androidでcwac-cameraを使って写真撮影する

    2014-08-26QiitaAndroid
    ざっくり概要-commonsguy/cwac-cameraというカメラ用のライブ
    ざっくり概要 - [commonsguy/cwac-camera](https://github.com/commonsguy/cwac-camera)というカメラ用のライブラリを使う - Android で写真を撮る - 動作設定をする - 起動・撮影・保存する - 撮影した写真をあとで使う - イベントバスの[Otto](http://square.github.io/otto/)を使う カメラの動作設定 基本的には [cwac-camera/SimpleCameraHost.java](https://github.com/commonsguy/cwac-camera/b

    PHPのTestでheader関数によるエラーを回避する

    2014-07-17QiitaPHP
    まとめheader関数を使っている関数などをテストする際には、テストを走らせる前
    まとめ header関数を使っている関数などをテストする際には、テストを走らせる前に ob_start()と書きましょう 問題 PHP でテストしようとして、何故か[SimpleTest - Unit Testing for PHP](http://simpletest.sourceforge.net/)を利用した テストを実行するとheader()によるエラーが出た > E_WARNING: Cannot modify header information - headers already sent by (output started at ... よく

    vimのインストール

    2014-07-04QiitaVim
    内容-Mac -homebrewを使ったインストール-CentOS -ソースから
    内容 - Mac - homebrew を使ったインストール - CentOS - ソースからコンパイルしてインストール ドキュメント ここ読み込んだら幸せになれそう http://vim-jp.org/vimdoc-ja/ Mac に homebrew でインストール sh brew install vim --with-features=huge --enable-multibyte --enable-pythoninterp=dynamic --enable-cscope --enable-fontset --disable-gui --without

    PHPでPDOを使ってAND検索(OR検索)を実装する

    2014-06-16QiitaPHPPDO
    概要-日本語で検索-GETパラメータをキーワードとして検索-PDO使ってMySQ
    概要 - 日本語で検索 - GET パラメータをキーワードとして検索 - PDO 使って MySQL に接続し、プレースホルダを使って SQL を構築する - 可変長な AND(OR)検索 ポイント 日本語対策 - mb_internal_encoding('UTF-8');をファイルの先頭に書く - 今回は特に関係ないっぽいですが、とりあえず書いてます - PDO作成の際にutf8を指定する - MySQL の設定を変更する - こうなってたら動いた >mysql> show variables like 'character_

    zshでの自作関数と、それに対する補完関数を実装する

    2014-05-30QiitaZsh
    やりたいこと-zshでオリジナルな関数を実装したい-自作関数にも補完を効くように
    やりたいこと - zsh でオリジナルな関数を実装したい - 自作関数にも補完を効くようにしたい - ファイル一覧を表示させたい - オプションも付けたい 参考 - [zsh の補完関数の自作導入編](https://gist.github.com/mitukiii/4954559) 自作関数 rmを~/.Trash/にmvするだけのコマンド(もらいもの)に置き換えており、rmfは/bin/rm/に置き換えている 以前は zsh function rmf() { for file in $* /bin/rm $file }

    sqlalchemyのテーブル定義tips

    2014-05-28QiitaPythonsqlalchemy
    tips-データベースエンジンの指定-複数カラムに対するユニーク制約-外部キー制
    tips - データベースエンジンの指定 - 複数カラムに対するユニーク制約 - 外部キー制約 - NULL を許さない - unsigned int(MySQL) - 随時追加? バージョンは 0.9.4 です データベースエンジンの指定 __table_args__で指定出来る python __table_args__ = {'mysql_engine': 'InnoDB'} ユニーク制約 単一カラムへは簡単だが、複数カラムにユニーク制約を貼るには sqlalchemy.schema.UniqueConstraintを使用する必

    Scala - パターンマッチにおけるアットマーク(@)

    2014-05-23QiitaScala
    参照http://stackoverflow.com/questions/451
    参照 http://stackoverflow.com/questions/4513380/scala-match-help 問題 こんなコードがある scala def flatMapSublists[A,B](ls: List[A])(f: (List[A]) => List[B]): List[B] = ls match { case Nil => Nil case sublist@(_ :: tail) => f(sublist) ::: flatMapSublists(tail)(f) } ん?sublist

    Gitbucketの導入からgit pushまで

    2014-05-13QiitaGitGitBucket
    要約-GithubクローンのGitbucketの導入-ssh経由でGitbuck
    要約 - Github クローンの[Gitbucket](https://github.com/takezoe/gitbucket)の導入 - ssh 経由で Gitbucket を利用する流れ Gitbucket の導入 1. ダウンロード Zsh wget https://github.com/takezoe/gitbucket/releases/download/1.13/gitbucket.war 1. openjdkのインストール Zsh sudo yum install openjdk-7-jre 1. t

    lftpでファイル転送

    2014-05-07Qiitashell
    sftpだとTAB補完が効かないので不便だったでもsshでファイル転送したかった
    sftp だと TAB 補完が効かないので不便だった でも ssh でファイル転送したかった 使い方 sh brew install lftp sftp hoge@example.com lftp sftp://hoge@example.com これだけで補完の効く sftp になる sftp だとllsだったのが!lsになったり、少しだけ違う getだとワイルドカードが展開できないのでmgetを使う mgetで上書きを許可するにはset xfer:clobber onと入力すれば OK Ctrl-rでインクリメンタルサーチ出来たり

    パッケージを作成し、PyPIに登録したメモ

    2014-04-21QiitaPython
    Pythonでパッケージを作って、PyPIに登録した時の作業メモなお、今回はコマ
    Python でパッケージを作って、[PyPI](https://pypi.python.org/pypi)に登録した時の作業メモ なお、今回はコマンドラインツールを作りました PyPI に登録することによってpipでインストール出来るようになります ディレクトリ構成 ├── README.md ├── requirements.txt ├── setup.py └── src ├── __init__.py └── hoge.py ファイル詳細 - requirements.txt、src/**init**.py

    Javaでクローラを実装する

    2014-04-10QiitaJava
    なにかライブラリが無いかと思ってcrawler4jに行き着きました。使用準備ht
    なにかライブラリが無いかと思って[crawler4j](http://code.google.com/p/crawler4j/)に行き着きました。 使用準備 http://code.google.com/p/crawler4j/ のサイドバーにある[Downloads]から crawler4j-3.5.zip と crawler4j-3.5-dependencies.zip をダウンロードする。 html のパースには jsoup を使うので、[ここ](http://jsoup.org/download)からダウンロードしておく。 eclipse だと[ビルドパスの構成]>[ライ

    PythonからGoogleのAPIを利用してAndroidへPUSH通知する

    2014-03-08QiitaPythonAndroid
    GoogleのAPIを用いてAndroid端末へのPUSHとステータスバーへの通
    Google の API を用いて Android 端末への PUSH とステータスバーへの通知の表示メモ クライアント(Android) Android で PUSH 通知をするための準備は[http://dev.classmethod.jp/smartphone/android/gcm/](http://dev.classmethod.jp/smartphone/android/gcm/)に書いてあります。 本当に参考になりました。 ここからは上のリンクからの変更点と追加点についてです。 - Google Developers Console での手順が多少変わっているので

    アラームの作り方

    2014-03-06QiitaAndroid
    これが正しい方法かどうかわかりませんが、アラームとして機能したのでメモAndro
    これが正しい方法かどうかわかりませんが、アラームとして機能したのでメモ Android でアラームを鳴らすためには、 1. アラーム時に起動するサービスを PendingIntent を使って指定する 1. 指定されたタイミングで起動したサービスから sendBroadcast を利用してレシーバーを起こす 1. 起こされたレシーバーからアラーム時に起動する Activity を Intent によって指定、起動 というプロセスでいけるようです。 めんどくさいですが。 サービスとレシーバーを利用するためには権限が必要なため、Manifest に記載する 必要な部分のみ書いています。

    論文のための句読点変換スクリプト

    2014-02-15Qiitased
    sh:paper!/usr/local/bin/zshfind.-name'*
    sh:title=paper !/usr/local/bin/zsh find . -name '*.tex' -print0 | xargs -0 sed -i '' -e 's/、/,/g' find . -name '*.tex' -print0 | xargs -0 sed -i '' -e 's/。/./g' そして zsh chmod +x paper sudo mv paper /usr/local/bin これでどこでも zsh paper とコマンドを打てば句読点が論文用になります! from: https://qii

    pipで既にインストールされているパッケージをuser環境(非su)でアップデートする

    2014-01-31QiitaPython
    既にインストールされているパッケージをアップデートしたいが、sudo権限がなく、
    既にインストールされているパッケージをアップデートしたいが、sudo 権限がなく、 -I や--user だけでは permission エラーや ez_setup.py がない等で出来なかった。 手順 手元にダウンロードして解凍し、解凍後のディレクトリから pip で user 環境にインストールする zsh ./tmpにtar.gzをダウンロードする pip install [package] -I --user -d ./tmp tar zxvf ./tmp/[package].tar.gz pip install -e ./tmp/package --user

    外部キー貼り直し手順メモ

    2014-01-29QiitaMySQL
    userテーブルとarticleテーブルがあり、articleテーブルにはuse
    user テーブルと article テーブルがあり、article テーブルには user_id という user.id を参照する外部キーを持っている。 そして、article.user_id に on (delete|update) cascade を付け加えたかった テーブルの構造および外部キーの名前を確認する mysql mysql> show create table user \G *************************** 1. row *************************** Table: user Create Ta

    SQLAlchemyとmultiprocessingを使う

    2014-01-17QiitaPython
    Pythonの便利なマルチプロセスライブラリであるmultiprocessing
    Python の便利なマルチプロセスライブラリである multiprocessing と SQLAlchemy を組み合わせて使用するサンプル プロセス間のデータのやり取りは Queue で行い、DB には SQLALchemy の session を使ってアクセスする py from multiprocessing import (Process, Queue) from sqlalchemy import (create_engine, MetaData) from sqlalchemy.ext.declarative import declarative_base from s

    networkxでグラフを描く

    2014-01-16QiitaPython
    pythonのnetworkxを使ってグラフを作ってみたのでメモ py:make
    = python の networkx を使ってグラフを作ってみたのでメモ py:title=make_graph.py -*- encoding:utf-8 -*- import networkx import pylab from matplotlib import font_manager from itertools import combinations from random import randint ノードをkey、エッジをはるノードのlistをvalueとするdict vector = {} persons = [u"田中", u"鈴木", u"山田

    argparseの使い方とoptparseとの違い

    2014-01-16QiitaPython
    以前、OptParserの使い方として記事を書いたが、どうやらargparse.
    以前、[OptParser の使い方](http://qiita.com/petitviolet/items/c2ba174a153bbdc5ad22)として記事を書いたが、どうやら argparse.ArgumentParser の方がなういらしい なので argparse.ArgumentParser の使い方のメモ py -*- coding:utf-8 -*- from optparse import OptionParser from argparse import ArgumentParser if __name__ == '__main__': """

    Scipyでの疎行列の扱い

    2013-09-25QiitaPython
    pythonで疎な文書ベクトルの類似度や距離を計算をするメモScipyで疎行列を
    python で疎な文書ベクトルの類似度や距離を計算をするメモ Scipy で疎行列を使う際の基本的な操作について 書いたのが昔なので、どっか間違ってるかも py:title=行列の計算 import scipy.sparse as sp import numpy as np a = sp.lil_matrix((1, 10000)) 1*10000の疎行列が作成される b = sp.lil_matrix((1, 10000)) a.shape => (1, 10000) for i in xrange(a.shape[1]): r = np.random.ran

    OptParserの使い方

    2013-09-25QiitaPython
    py!/usr/bin/envpython-*-coding:utf-8-*-
    py !/usr/bin/env python -*- coding:utf-8 -*- from optparse import OptionParser if __name__ == '__main__': """ コマンドエラー時に表示する文字列 """ usage = u'%prog [Args] [Options]\nDetailed options -h or --help' version = 0.1 parser = OptionParser(usage=usage, version=version) """ tes