Skip to content

Instantly share code, notes, and snippets.

@TakuyaHarayama
TakuyaHarayama / Dockerfile
Last active March 19, 2019 09:01
Simple docker for rails
FROM ruby:2.5.0
ENV LANG C.UTF-8
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /app_name
WORKDIR /app_name
ADD Gemfile /app_name/Gemfile
ADD Gemfile.lock /app_name/Gemfile.lock
RUN bundle install
@TakuyaHarayama
TakuyaHarayama / Upload.vue
Created January 11, 2019 01:13
vueファイルアップロード
<template>
<div>
<input type="file" multiple accept="image/jpeg" @change="detectFiles($event.target.files)">
<div class="progress-bar" :style="{ width: progressUpload + '%'}">{{ progressUpload }}%</div>
<img v-bind:src="image"/>
</div>
</template>
<script>
import firebase from 'firebase'
@TakuyaHarayama
TakuyaHarayama / active_storage.rb
Created October 12, 2018 11:36
Add acl and cache_control to ActiveStorage gcs
# config/initializers/active_storage.rb
Rails.application.config.to_prepare do
# Provides the class-level DSL for declaring that an Active Record model has attached blobs.
ActiveStorage::Attached::Macros.module_eval do
def has_one_attached(name, dependent: :purge_later, acl: :private)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
@active_storage_attached_#{name} ||= ActiveStorage::Attached::One.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"}, acl: "#{acl}")
end
def #{name}=(attachable)
@TakuyaHarayama
TakuyaHarayama / config.yml
Last active July 2, 2018 03:15
CircleCIからS3にホスティングする設定ファイル。YOUR-PROJECTにはプロジェクト名を入れてください。事前にS3のbucketを作成して、CircleCIにアップロード用のIAMのキーやS3のホスティングの設定しておく必要があります。
version: 2
workspace_root: &workspace_root
~/YOUR-PROJECT/docs
defaults: &defaults
docker:
- image: circleci/node:8
working_directory: *workspace_root
class GraphqlController < ActionController::Base
include Knock::Authenticable
before_action :authenticate
def execute
# snip...
context = {
# Query context - +current_user+ is available when authenticated:
current_user: current_user,
class GraphqlController < ActionController::Base
include Knock::Authenticable
before_action :authenticate
def execute
# snip...
context = {
# Query context - +current_user+ is available when authenticated:
current_user: current_user,
@TakuyaHarayama
TakuyaHarayama / table-add-col.js
Created May 9, 2018 06:58
ヘッダー付きtableのカラムを増やすjQuery
// ヘッダー付きtableのカラムを増やすjQuery
$('table').find('tr').each(function(){
if ($('table').index(this)) {
$(this).find('th:last-child').after('<th>new column added</th>');
}
$(this).find('td:last-child').after('<td>new cell added</td>');
});
@TakuyaHarayama
TakuyaHarayama / zipcode_on_stores.rb
Last active February 19, 2018 05:47
特にデザイン的な制限がなければ普通にカラム追加してattr_*使わないほうがコードがシンプルになると思いました。
# attr_writer使う場合 attr_*があいまいな人 https://qiita.com/Rudiments/items/c2c5251bcf49dfd7ce7a
# 想定される状況:DBには郵便番号は1カラムで保存されているが、表示するときに2つにしたい
# == Schema Information
#
# Table name: stores
#
# id :integer not null, primary key
# name :string(191) not null
# zip_code :string(191) not null
(function(window, $) {
//'use strict';
var Device = function() {
var u = window.navigator.userAgent.toLowerCase();
return {
isTablet: (u.indexOf("windows") != -1 && u.indexOf("touch") != -1) || u.indexOf("ipad") != -1 || (u.indexOf("android") != -1 && u.indexOf("mobile") == -1) || (u.indexOf("firefox") != -1 && u.indexOf("tablet") != -1) || u.indexOf("kindle") != -1 || u.indexOf("silk") != -1 || u.indexOf("playbook") != -1,
isMobile: (u.indexOf("windows") != -1 && u.indexOf("phone") != -1) || u.indexOf("iphone") != -1 || u.indexOf("ipod") != -1 || (u.indexOf("android") != -1 && u.indexOf("mobile") != -1) || (u.indexOf("firefox") != -1 && u.indexOf("mobile") != -1) || u.indexOf("blackberry") != -1
};
};
@TakuyaHarayama
TakuyaHarayama / .circle.yml
Created September 14, 2017 02:53
RailsのCircleCI設定サンプル
machine:
timezone:
Asia/Tokyo
ruby:
version:
2.3.1
hosts:
hogehoge.local: 127.0.0.1
fugafuga.local: 127.0.0.1
dependencies: