Skip to content

Instantly share code, notes, and snippets.

View yancya's full-sized avatar
๐Ÿ’ญ
๐Ÿ˜‚

Shinta Koyanagi yancya

๐Ÿ’ญ
๐Ÿ˜‚
View GitHub Profile
@yancya
yancya / composer.json
Last active June 26, 2020 13:45
่ฌŽใฎ HAML ใƒฉใ‚คใƒ–ใƒฉใƒชใ‚’ไฝฟใ†ๆ–นๆณ•
{
"name": "yancya/php_sandbox",
"authors": [
{
"name": "yancya",
"email": "[email protected]"
}
],
"require": {
"mthaml/mthaml": "*"
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
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
@yancya
yancya / yhpg_e32_2.rb
Created April 9, 2019 04:49
http://nabetani.sakura.ne.jp/hena/orde32rects/ ใธใฎ yancya ใฎ่งฃ็ญ”
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
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');
class Array
def +@
false
end
end
class TrueClass
def +(o)
to_s + o.join(',')
end
@yancya
yancya / Dockerfile
Created June 18, 2018 11:58
bundle install ๆ™‚ใซ rake ใŒ่ฆ‹ใคใ‹ใ‚‰ใชใใฆใ‚ณใ‚ฑใ‚‹ไพ‹
FROM ruby
RUN apt-get update && apt-get install -y libpoppler-dev
WORKDIR /var/app
COPY Gemfile .
RUN bundle # ใ“ใ‘ใ‚‹
# `RUN gem install poppler && bundle` ใ ใจๆˆๅŠŸใ™ใ‚‹
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
require 'open-uri'
require 'nokogiri'
require 'date'
CALENDAR_ID = 'mem79137'
today = Date.today
0.upto(5) do |n|
month = today.next_month(n)