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 / file0.txt
Last active August 29, 2015 14:18
aws cli で iam の group に紐づく user, policy を見る ref: http://qiita.com/motchang/items/aee024fad5e49ce872d1
#!/bin/bash
aws iam list-groups | jq '.Groups[].GroupName' | xargs -I{} echo {} | \
while read g
do
echo ${g} "-------------------------------------------------------------";
aws iam get-group --group-name ${g} | jq '(.Group | {GroupName, Arn}), (.Users[] | {UserName, Arn})'
aws iam list-group-policies --group-name ${g} | jq '.PolicyNames[]' | xargs -I{} echo {} | \
while read p
@motchang
motchang / file0.txt
Created April 14, 2015 02:41
ユーザーの公開鍵の一覧をつくる ref: http://qiita.com/motchang/items/cc1e979a2d1c712bc741
ls -nd /home/* | sort -n -k 3,3 | awk '{ print $NF }' | while read user
do
echo ${user}
cat ${user}/.ssh/authorized_keys
done
@motchang
motchang / file0.txt
Created July 5, 2015 09:45
sakura に入れてるやつの configure オプション ref: http://qiita.com/motchang/items/ea9eb8149dec11e3096a
./configure --prefix=/usr/local/etc/nginx --sbin-path=/usr/local/sbin/nginx --conf-path=/usr/local/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-cc-opt='-O2 -g -m64 -mtune=generic' --with-http_stub_status_module
@motchang
motchang / xvfb.sh
Last active June 17, 2016 07:29
/etc/init.d/xvfb
#!/bin/bash
#
# Xvfb
#
# chkconfig: - 90 30
# description: Xvfb
# Source function library.
. /etc/init.d/functions
lockfile="/var/lock/subsys/xvfb"
@motchang
motchang / crontab
Last active June 17, 2016 07:29
mkswap
5 9 * * * root /sbin/swapoff -a && /root/bin/mkswap.sh
#
# 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
#
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}%" ) }
;;; 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)
@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",
@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