Skip to content

Instantly share code, notes, and snippets.

@tuwukee
tuwukee / strategy_sample.rb
Last active March 9, 2020 20:17
Sample strategy
module Template
class JsonInputStrategy < Template::InputStrategy
def parse_request_input
begin
JSON.parse(request_input)
rescue JSON::ParserError
{}
end
end
module Users
class AnnouncementsQuery
attr_accessor :used
def initialize(user)
@user = user
end
def unread
active
DO $$
DECLARE
v_ts TIMESTAMP;
v_repeat CONSTANT INT := 10000;
rec RECORD;
BEGIN
-- Repeat the whole benchmark several times to avoid warmup penalty
FOR i IN 1..5 LOOP
v_ts := clock_timestamp();
@tuwukee
tuwukee / sql
Created December 11, 2019 15:27
test.sql
SELECT DISTINCT result.request_json->>'target' as target,
result.request_json->>'return_to' as return_to
FROM (
SELECT "request_params"::json as request_json
FROM "histories"
WHERE (created_at > '2018-12-05 00:00:00') AND
(created_at < '2019-01-05 00:00:00')
) as result
WHERE (
version: '3'
services:
db:
image: postgres:10.5-alpine
ports:
- 5432:5432
volumes:
- ./tmp/postgres_data:/var/lib/postgresql/data
web:
build:
FROM ruby:2.6.5-slim-stretch
RUN apt-get update && apt-get install -y \
curl \
build-essential \
libpq-dev &&\
curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y nodejs yarn
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "2.6.5"
gem "bootsnap", require: false
gem "pg", ">= 0.18", "< 2.0"
gem "puma", "~> 3.11"
gem "rails", "~> 6.0.0"
// Within the Application_Start() event handler in the Global.asax.cs
ControllerBuilder.Current.SetControllerFactory(new DependencyControllerFactory());
ObjectFactory.Initialize(registry => registry
.ForRequestedType<IContactRepository>()
.TheDefaultIsConcreteType<ContactManagerLinqRepository>());
// The repository class which is passed through DI to the controller
@tuwukee
tuwukee / dip_1.rb
Last active November 28, 2018 19:56
class UsersController < ApplicationController
# ...
before_action :auth_user
# ...
def show
@user = User.find(params[:id])
@customers_portals = UserCustomersPortalsQuery.new(@user).all
end
describe AuthService do
# ...
before { allow_any_instance_of(Dnsruby::Resolver).to receive(:query).and_return(message) }
# ...
before { allow(AuthService).to receive(:sso_url).and_return(sso_auth_url) }
# ...
end