Skip to content

Instantly share code, notes, and snippets.

View motchang's full-sized avatar
👺
hmmmmmm

Kouji OKAMOTO motchang

👺
hmmmmmm
View GitHub Profile
@motchang
motchang / docker-bash-completion.md
Last active September 28, 2022 19:18 — forked from rkuzsma/docker-bash-completion.md
How to configure Bash Completion on Mac for Docker and Docker-Compose

How to configure Bash Completion on Mac for Docker and Docker-Compose

Copied from the official Docker-for-mac documentation (thanks Brett for the updated doc pointer):

Install shell completion

Docker Desktop for Mac comes with scripts to enable completion for the docker, docker-machine, and docker-compose commands. The completion scripts may be found inside Docker.app, in the Contents/Resources/etc/ directory and can be installed both in Bash and Zsh.

Bash

Bash has built-in support for completion To activate completion for Docker commands, these files need to be copied or symlinked to your bash_completion.d/ directory. For example, if you installed bash via Homebrew:

@motchang
motchang / 00_version.txt
Last active August 12, 2021 10:46
String#include? ってそんなに遅いものかね? https://techracho.bpsinc.jp/hachi8833/2019_10_18/82048
$ ruby -v
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin19]
public class Main implements HtwMessageReceiver {
private static HuntTheWumpusgame;
private static inthitPoints=10;
private static final List<String> caverns = new ArrayList<>();
private static final String[] environments = new String[] {
"bright",
"humid",
"dry",
"creepy",
"ugly",
@motchang
motchang / main.rs
Created June 20, 2020 07:33
3-6-1 E2077
use std::{time, thread};
fn main() {
let n1 = 1200;
let n2 = 1000;
// spawn で子スレッドを立ち上げ、子スレッドで重い処理を実行する
// 変数 child がスレッドへのハンドルに束縛される
// let child = thread::spawn(move || {
// // 重い処理を実行する
@motchang
motchang / E0277.ja.md
Last active May 27, 2020 00:27
機械翻訳

You tried to use a type which doesn't implement some trait in a place which expected that trait.

何らかの trait を実装していない型を、その trait を期待していた場所で使おうとしました

Erroneous code example:

// here we declare the Foo trait with a bar method
// ここで Foo trait を bar メソッドと共に宣言しています
@motchang
motchang / bm.rb
Last active June 20, 2019 12:42
big set
require 'set'
require 'benchmark'
Benchmark.bm 10 do |r|
limit = 65535*1000
r.report "to_a" do
(1..limit).to_a
end
r.report "to_set" do
(1..limit).to_set
@motchang
motchang / personal_motchang.json
Created September 14, 2018 05:30
左 Option を単体で押した時に英数キーにする
{
"title": "Personal rules @motchang",
"rules": [
{
"description": "左 Option を単体で押した時に英数キーにする",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "left_option",
;;; package --- Summary
;;; Commentary:
;;; Code:
(when (require 'helm-config nil t)
(helm-mode 1)
(global-set-key (kbd "M-x") #'helm-M-x)
(global-set-key (kbd "C-x r b") #'helm-filtered-bookmarks)
(global-set-key (kbd "C-x C-f") #'helm-find-files)
(global-set-key (kbd "C-x b") #'helm-mini)
class Micropost < ApplicationRecord
belongs_to :user
before_save { self.in_reply_to = reply_user }
default_scope -> { order(created_at: :desc) }
mount_uploader :picture, PictureUploader
validates :user_id, presence: true
validates :content, presence: true, length: { maximum: 140 }
validate :picture_size
scope :including_replies, ->(user) { where("user_id = ? OR (user_id IN (SELECT followed_id FROM relationships WHERE follower_id = ?) AND (in_reply_to = ? OR in_reply_to LIKE ?))", user.id, user.id, "", "%@#{user.id}\-#{user.name.sub(/\s/,'-').downcase}%" ) }
#
# USAGE1:
# User.find(1).deepcache.friends.count.fetch
#
# 上記のような呼び出しをすると以下のキーで Redis に問い合わせてなければキャッシュします。
# get deepcache:User:1:friends.count
#
# USAGE2:
# Category.deepcache.co_cats.where(slug: URI.encode(request_manager.params['slug'] || '')).limit(1).to_a.fetch
#