This file contains 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
# Basic key operators to query the JSON objects : | |
# #> : Get the JSON object at that path (if you need to do something fancy) | |
# -> : Get the JSON object at that path (if you don't) | |
# ->> : Get the JSON object at that path as text | |
# {obj, n} : Get the nth item in that object | |
# https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE | |
# Date | |
# date before today |
This file contains 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 "json" | |
struct = { "a" => 1, "b" => 2, "c" => [1, 2, 3], "d" => [{ "e" => 3 }, nil, false, true, [], {}] } | |
source = JSON.dump(struct) | |
tokens = [] | |
index = 0 | |
until source.empty? | |
tokens << |
This file contains 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 "date" | |
class Month | |
include Comparable | |
MONTHS_PER_YEAR = 12 | |
def self.from_date(date) | |
self.from_parts(date.year, date.month) | |
end |
This file contains 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
import sys | |
import os | |
import argparse | |
placeholder = 'Paste mojibake here\nここで文字化けをペースト下さい' | |
default_source_enc = 'sjis' | |
# Open a file in binary mode and overwrite contents | |
# with the text encoded in the given encoding | |
def write_file(filename, encoding, text): |
This file contains 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
###################### | |
# Stage: Builder | |
FROM ruby:2.6.5-alpine as Builder | |
ARG FOLDERS_TO_REMOVE | |
ARG BUNDLE_WITHOUT | |
ARG RAILS_ENV | |
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT} | |
ENV RAILS_ENV ${RAILS_ENV} |
This file contains 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
[{url: "https://emoji.slack-edge.com/T6CU2169Z/100sual/b3a1531ff45f2acd.jpg", name: ":100sual:"} | |
,{url: "https://emoji.slack-edge.com/T6CU2169Z/1_don%2527t_pick_up_the_phone/8dd1f635352780e8.png", name: ":1_don't_pick_up_the_phone:"} | |
,{url: "https://emoji.slack-edge.com/T6CU2169Z/1hokage/9e66cda3a2ecf310.jpg", name: ":1hokage:"} | |
,{url: "https://emoji.slack-edge.com/T6CU2169Z/2_don%2527t_let_him_in/eb898e174fa62821.png", name: ":2_don't_let_him_in:"} | |
,{url: "https://emoji.slack-edge.com/T6CU2169Z/2hokage/63f4935ed5608b8c.gif", name: ":2hokage:"} | |
,{url: "https://emoji.slack-edge.com/T6CU2169Z/3_don%2527t_be_his_friend/68b9721a15ed8aeb.png", name: ":3_don't_be_his_friend:"} | |
,{url: "https://emoji.slack-edge.com/T6CU2169Z/3hokage/765b9b0f9d994981.jpg", name: ":3hokage:"} | |
,{url: "https://emoji.slack-edge.com/T6CU2169Z/4hokage/39a0745cfb994d6c.jpg", name: ":4hokage:"} | |
,{url: "https://emoji.slack-edge.com/T6CU2169Z/5hokage/0e9dcea089de5b8b.jpg", name: ":5hokage:"} | |
,{url: "https://emoji.slack-edge.com/T6CU2169Z/6hokag |
This file contains 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
# rails console | |
ActiveRecord::Base.connection.tables.each do |table| | |
indexes = ActiveRecord::Base.connection.indexes(table) | |
if indexes.length > 0 | |
puts "====> #{table} <====" | |
indexes.each do |index| | |
puts "----> #{index.name}" | |
end | |
puts "====> #{table} <====" |
This file contains 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
# How to run Ecto migrations from IEx console... Examples | |
# preliminaries assumed in the following code, change to fit your environment: | |
alias YourAppName.Repo | |
your_app_name_as_atom = :mpnetwork | |
downto_version = 20170724182558 | |
# Down: | |
Ecto.Migrator.run(Repo, "priv/repo/migrations/", :down, [to: downto_version]) |
This file contains 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
defmodule Box do | |
defmacro __using__(_env) do | |
quote do | |
import Box | |
end | |
end | |
@doc """ | |
Define module with struct and typespec, in single line |
NewerOlder