This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- psql -f create_db.sql postgres | |
| CREATE DATABASE hogehoge; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "yancya/php_sandbox", | |
| "authors": [ | |
| { | |
| "name": "yancya", | |
| "email": "yancya@upec.jp" | |
| } | |
| ], | |
| "require": { | |
| "mthaml/mthaml": "*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ROOMS = ['a', 'b'] | |
| rooms_order = ROOMS.map.with_index { |r, i| "WHEN '#{r}' THEN #{i} " }.join.yield_self { |s| "CASE room #{s} END"} | |
| Topic.where(room: ROOMS).order(rooms_order) | |
| #=> SELECT "topics".* FROM "topics" WHERE "topics"."room" IN ('a', 'b') ORDER BY CASE room WHEN 'a' THEN 0 WHEN 'b' THEN 1 END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ROOMS = ['a', 'b'] | |
| rooms_table = ROOMS.map.with_index { |r, i| "('#{r}',#{i})" }.join(',').yield_self { |s| "(VALUES#{s}) as rooms(room, room_order)" } | |
| Topic.joins("join #{rooms_table} using(room)").order(:room_order) | |
| #=> SELECT "topics".* FROM "topics" join (VALUES('a',0),('b',1)) as rooms(room, room_order) using(room) ORDER BY "room_order" ASC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'pg' | |
| require 'tapp' | |
| def main(str) | |
| line_segments = str.split('/').flat_map { |sq| | |
| left, top, right, bottom = sq.chars.map { |i36| i36.to_i(36) } | |
| [ # ax ay bx by | |
| [left, top, right, top ], # top segment | |
| [right, top, right, bottom], # right segment | |
| [left, bottom, right, bottom], # bottom segment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TEMP TABLE "employees" ( | |
| "emp_code" text, | |
| "name" text, | |
| "valid_from" timestamp | |
| ); | |
| INSERT INTO "employees" VALUES | |
| ('001', 'Jane', '2019-01-10'), | |
| ('001', 'Tom', '2019-01-15'), | |
| ('001', 'Kevin', '2019-01-20'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // IE11 では、これらを書いておかないと | |
| // 'ready page:load' のフックが動かない事がある | |
| // 理由はわからない...... | |
| $(document).on('page:fetch', function() {}); | |
| $(document).on('page:restore', function() {}); | |
| $(document).on('page:change', function() {}); | |
| $(document).on('ready page:load', function() { | |
| // 目当ての処理 | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Array | |
| def +@ | |
| false | |
| end | |
| end | |
| class TrueClass | |
| def +(o) | |
| to_s + o.join(',') | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM ruby | |
| RUN apt-get update && apt-get install -y libpoppler-dev | |
| WORKDIR /var/app | |
| COPY Gemfile . | |
| RUN bundle # こける | |
| # `RUN gem install poppler && bundle` だと成功する |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create temp table hoge(id integer, name text); | |
| with hoge_candidate(id, name) AS (values(1, 'hoge')) | |
| , inserted_hoge AS ( | |
| insert into hoge | |
| select hoge_candidate.* | |
| from hoge right outer join hoge_candidate using(id) | |
| where hoge.id is null returning *) | |
| select * from inserted_hoge |