万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

  • ・資産運用おすすめ
    10万円は1000円くらい利益
    資産運用ブログ アセマネ
    • ・寄付お願いします
      YENTEN:YYzNPzdsZWqr5THWAdMrKDj7GT8ietDc2W
      BitZenny:ZfpUbVya8MWQkjjGJMjA7P9pPkqaLnwPWH
      c0ban:8KG95GXdEquNpPW8xJAJf7nn5kbimQ5wj1
      Skycoin:KMqcn7x8REwwzMHPi9fV9fbNwdofYAWKRo

    carとcdrはなんの略?Lisp

    CAR and CDR - Wikipedia

    car (short for "Contents of the Address part of Register number"),
    cdr ("Contents of the Decrement part of Register number"),
    cpr ("Contents of the Prefix part of Register number"), and
    ctr ("Contents of the Tag part of Register number"),

    色んなバリエーションあるのね。 command - Explanation of CAR, CDR, CADAR, etc - Stack Overflow

    CommonLispのWebサーバ Wookieを使う

    Documentation | Wookie

    まずこれが必須みたい。

    libuvのインストール

    brew install --HEAD libuv

    libuvを入れずにWookieをインストール時のエラー

    * (ql:quickload :wookie)
    To load "wookie":
      Load 1 ASDF system:
        wookie
    ; Loading "wookie"
    ..
    debugger invoked on a LOAD-FOREIGN-LIBRARY-ERROR in thread
    #<THREAD "main thread" RUNNING {1001F1EAB3}>:
      Unable to load any of the alternatives:
       ("libuv.dylib")

    になってしまうからね。

    Wookieのインストール

    (ql:quickload :wookie)

    MastodonでのVagrant起動

    vagrant up
    
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Checking if box 'ubuntu/trusty64' is up to date...
    ==> default: [vagrant-hostsupdater] Checking for host entries
    ==> default: [vagrant-hostsupdater]   found entry for: 192.168.42.42 mastodon.dev
    ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
    ==> default: flag to force provisioning. Provisioners marked to run always will still run.
    ==> default: Running provisioner: shell...
        default: Running: inline script
    ==> default: /tmp/vagrant-shell: line 4: rails: command not found
    The SSH command responded with a non-zero exit status. Vagrant
    assumes that this means the command failed. The output for this command
    should be in the log above. Please read the output to determine what
    went wrong.

    Railsがない?手動で入れたw

    vagrant ssh

    で入り、

    vagrant@mastodon:~$ gem install rails
    The SSH command responded with a non-zero exit status. Vagrant

    このヘンテコなメッセージは、vagrantsshで入った状態で

    vagrant@mastodon:~$ rm -rf /etc/udev/rules.d/70-persistent-net.rules
    vagrant@mastodon:~$ rm -rf /etc/udev/rules.d/70-persistent-cd.rules

    してexitして抜けてvagrant reloadする。

    ==> default: /home/vagrant/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/spec_set.rb:87:in `block in materialize'
    ==> default: :
    ==> default: Could not find actionview-5.0.2 in any of the sources
    ==> default:  (
    ==> default: Bundler::GemNotFound
    ==> default: )

    って・・・

    vagrant@mastodon:~$ gem install actionview

    してもだめ。

    仕方ないのでvagrant sshで入って、

    mastodon/Vagrantfile at master · tootsuite/mastodon · GitHub

    ここにあるVagrantfileにある以下のコマンドを行った。

    # Install gems and node modules
    gem install bundler
    bundle install
    yarn install

    このあとホストマシンで、vagrant upした。

    以下でエラー出る・・。

    /vagrant/app/views/about/show.html.haml

    f:id:shinriyo:20170430171339p:plain

    Django 1.11でのタグ使用時に勝手にエスケープされてしまう

    今までこのように買いていた。

    @register.simple_tag
    def calc_rate(star):
        """
        星を計算する(評価者一覧の方)
        :param star: 星の数の数字
        """
        html = """
            <p>
        """
        star = '<span class="glyphicon glyphicon-star"></span>' * star
        html += star
        html += """
            </p>
        """
        return html
    

    しかし、いざtemplateで

                    <div class="ratings">
                        {% calc_rate item.star %}
                    </div>

    のように使用するときにHTMLのタグ自体がそのまま表示されてしまう。

    https://docs.djangoproject.com/en/1.11/howto/custom-template-tags/

    おそらくエスケープを勝手にされていた?ので。 from django.utils.safestring import mark_safeをインポートし、 最後のreturnにて

        return mark_safe(html)
    

    したら大丈夫になった。