以前、StructをRubyで実装するというのをやった。 じゃあ次は、ということでEnumとAlgebraic Data Type(ADT)に相当するようなものが欲しいな〜と思ってGemとして作ってみた。 EnumはRuby言語標準としては用意されていないが、RailsにはActiveRecord::Enumというものがあり、カラムをenum的に管理しつつ便利メソッドを山程生やしてくれるものがあるが、そういうのじゃなくてデータ構造としてenum欲しいんだよねという気持ち。 そうなるといわゆるADTみたいなやつ、Scalaでいうところのsealed trait + case class(object)のあれがわりと好きなので欲しくなる。 といっても静的にパターンマッチの網羅性チェックとか出来ているわけでもないしどれくらい嬉しいかは不明。 EnumをEnumとして、ADTをADTとして明示でき
追記 2014/09/21 FlameGraphの出し方を追記しました 追記 2017/08/13 stackprofの原理をまとめました。 spring-mt.hatenablog.com rubykaigi 2014終わりましたね。 スタッフの皆様、本当にお疲れ様でした。 で、3日目のkeynoteを聞いて、stackprofは使いこなせんとあかんものやと思って、早速試してみました。 RubyKaigi 2014 | Ruby 2.1 in Production stackprof Gemfileにgem 'stackprof'って書いて、bundle installすればOKです。 サンプリング sampleスクリプトはこちら sample stackprof で、StackProf.runが入ってる場合と、入ってない場合の実行時間はこんな感じ 入っている場合 % time bund
この記事はRuby on Rails Advent Calendar 2018の7日目です。 はじめに 今回は知らなくても生きていけるけど、知っておいたほうがお得で便利なRailsメソッドを紹介していく。RailsといいつつActiveSupportやんけ squish 冒頭と末尾のホワイトスペースを削除して、連続したホワイトスペースを1つだけになるように整形してくれる。 " hoge \n \t piyo fuga\n".squish => "hoge piyo fuga" try 知ってる人は常識だけど未だに知らない人多い。例えば以下のようにpostに紐づくuserのlogin.idを有れば取得する場合、 post = Post.last post.user.present? && post.user.login.present? && post.user.login.id 以下のよう
This Ruby style guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. A style guide that reflects real-world usage gets used, while a style guide that holds to an ideal that has been rejected by the people it is supposed to help risks not getting used at all - no matter how good it is. The guide is separated
All slide content and descriptions are owned by their creators.
IoT技術部の5回目は「音声認識」で命令を聞く「人工知能」に挑戦です。みなさんは、話題の人工知能って手軽にやろうとするとどれくらいできるのだろうって思ったことありませんか? 今回は、Amazon Echoのように、Raspberry Piにつけられたマイクに向かって命令すると、命令を聞くというモノをつくってみようと思います。 今回作った人工知能は、名付けて「トメキチ(留吉)」。名前を考えていてパッと頭に湧いたのが「トメキチ」だった、という単純な理由でこの名前にしましたので深い意味はありません。。。 目標とする動きは、こんな感じです。 1)マイクからの音声を認識する 2)認識した音声に応じてコマンドを実行する 今回は、 「トメキチ 歌ってください」 と話しかけると、トメキチが歌い出すようにしてみます。 あとは、ちょっと会話っぽくするために、話しかけると 「へい!親方!」 と答えてくれるように
Rails 3のgemの管理に使用されるbundlerの使い方を復習します。 Bundlerの現時点の最新安定版のversion 1.2.3を対象とします。Bundlerを使うと何が嬉しいのか? あるgemが開発環境にはインストールされているが、production環境にはインストールされていない、といった問題が無くなる。 プロジェクトに必要なgemをはっきりさせることができる。 Bundlerのインストール %~ gem install bundler システム標準のrubyを使用している場合はsudoが必要な場合があります。rbenvやrvmを使用している場合はgem install bundlerのみでインストールできます。 bundle checkでインストール必要なgemをチェック Gemfileの中に記載されているgemのうち、これからどれをインストールしなければならないか
はじめに Guardというファイル変更を検出して動作するRuby製のツールがあります. Guardは編集して保存するだけで勝手に何かバックでコマンドを走らせることができるツールです. guard/guard · GitHub これをtexのコンパイルなどに使うと非常に便利でしたのでメモしておきます. Guardのインストール gem install guard gem install gurad-shell guard-shellをつかうことでシェル上からGuardを常駐させたり,Guardの設定ファイルを簡単に生成できるようになります. Guardの簡単な使い方 ここではtest.texというファイルを書くことを想定した例で説明していきます. 普通の文章でも構いませんが,ここでは例なので次のような文を書いておきます test.tex \documentclass[a4j]{jarticl
Originally presented at Baruco 2014. Updated for RubyConf Portugal 2014. Video here: https://www.youtube.com/watch?v=fGFM_UrSp70.
ちょっとしたコードの書き方でパフォーマンスが変わることがあります。リーダビリティを重視する向きからすれば小手先のテクニックに映るかも知れないのですが、リーダビリティを維持しながらちゃんとしたパフォーマンスを出すためにも、テクニックを知ることは大事なことだと思うのです。 結構違うもんですなー というわけで、そんなテクニックをまとめたスライドがWriting Fast Ruby。見ていて参考になったのでメモ。 たとえば引数に&blockをとってcallするよりも、yieldの方が5倍速い、とか、 def slow(&block) block.call end def fast yield end mapにブロックを渡すよりも、シンボルを渡す方が20%速い、とか (1..100).map {|i| i.to_s} (1..100).map(&:to_s) mapしてからflattenを呼び出すよ
はじめに dockerでrailsを動かす場合にどうするのが良いかなーと試行錯誤し、構成も落ち着いてきたのでまとめます。 お試しバージョン 一番最初はとりあえずってことで、railsリポジトリ + railsを動作させるコンテナの組み合わせで試してみました。 Dockerfileの内容 FROM base # rubyインストールに必要なパッケージを用意 RUN apt-get update RUN apt-get install -y --force-yes build-essential curl git zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev # rbenv, ruby-buildをインストール RUN git clone https://github.com/sstephen
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く