Skip to content

Instantly share code, notes, and snippets.

@yamitake
yamitake / breadcrumbs_helper.rb
Last active April 14, 2025 05:52
breadcrumbs_key for rails view helper
module BreadcrumbsHelper
def breadcrumb_key = @_breadcrumb_key ||= :"#{controller_path.gsub('/', '_')}_#{ACTION_MAP[action_name] || action_name}"
private
ACTION_MAP = {
"create" => "new",
"update" => "show"
}.freeze
end
@yamitake
yamitake / gtm_helper.rb
Last active April 12, 2025 03:23
Rails用Google Tag Manager ViewHelper
module GtmHelper
GTM_SCRIPT = "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':" \
"new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0]," \
"j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=" \
"'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);" \
"})(window,document,'script','dataLayer','%s');".freeze
GTM_IFRAME_URL = "https://www.googletagmanager.com/ns.html?id=%s".freeze
def gtm_key = @gtm_key ||= Rails.application.config_for(:gtm)["key"] || "SET_GTM_KEY"
def render_gtm_head = tag.script(GTM_SCRIPT % gtm_key, escape: false)
@yamitake
yamitake / random_open_issue.sh
Created May 21, 2024 13:36
指定したリポジトリからランダムでIssueを開く
#!/bin/bash
REPO="yapr/taskhub"
temp_file=$(mktemp)
gh issue list --repo "$REPO" --state open > "$temp_file"
random_issue=$(shuf -n 1 "$temp_file")
rm "$temp_file"
issue_number=$(echo "$random_issue" | awk '{print $1}')
gh issue view "$issue_number" --repo "$REPO" --web
@yamitake
yamitake / render_async.coffee
Created February 3, 2020 10:13
ex) = render_async related_products_path(@Product)
$(document).one 'turbolinks:load', ->
if document.documentElement.hasAttribute('data-turbolinks-preview')
return
headers = {}
csrfTokenElement = document.querySelector('meta[name="csrf-token"]')
headers['X-CSRF-Token'] = csrfTokenElement.content if csrfTokenElement
$('div[data-render-async-path]').each (_i, div) ->
$.ajax(
url: $(this).data('render-async-path')
method: 'GET'
@yamitake
yamitake / gretel.rb
Last active February 18, 2020 01:45
# frozen_string_literal: true
module Gretel
module ViewHelpers
delegate :breadcrumbs_json_ld, to: :gretel_renderer
end
class Renderer
# rubocop:disable Rails/OutputSafety
def breadcrumbs_json_ld
@yamitake
yamitake / youtube_monky.svg
Last active October 17, 2018 02:06
youtube 500画面ででた猿のSVG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yamitake
yamitake / git-wip
Last active May 25, 2020 01:31
git wipコマンド
#!/bin/sh
if [ $# -eq 0 ]; then
echo "Usage:"
echo "git wip (branch-name) (issue-number)"
exit 2
fi
issue_number=''
issue_title=''
branch_name=$1
if [ $# -eq 2 ]; then
select#user_time_zone.t1-select name="user[time_zone]"
option data-offset="-39600" value=("International Date Line West") (GMT-11:00) International Date Line West
option data-offset="-39600" value=("Midway Island") (GMT-11:00) Midway Island
option data-offset="-39600" value="Samoa" (GMT-11:00) Samoa
option data-offset="-36000" value="Hawaii" (GMT-10:00) Hawaii
option data-offset="-32400" value="Alaska" (GMT-09:00) Alaska
option data-offset="-28800" value=("Pacific Time (US & Canada)") (GMT-08:00) Pacific Time (US & Canada)
option data-offset="-28800" value="Tijuana" (GMT-08:00) Tijuana
option data-offset="-25200" value=("Mountain Time (US & Canada)") (GMT-07:00) Mountain Time (US & Canada)
option data-offset="-25200" value="Arizona" (GMT-07:00) Arizona
@yamitake
yamitake / turbolink5check.js
Created December 22, 2016 04:48
turbolink5check
$(function(){
// Turbolinksの効いたリンクをクリックした時
$(document).on('turbolinks:click' , function(){
console.log("turbolinks:click");
});
// Turbolinksによる遷移が始まる直前(キャンセル可能)
$(document).on('turbolinks:before-visit', function(){
console.log("Turbolinksによる遷移が始まる直前(キャンセル可能):turbolinks:before-visit");
});