Skip to content

Instantly share code, notes, and snippets.

View gouf's full-sized avatar
😇
I don't know how my life work with.

Go Furuya gouf

😇
I don't know how my life work with.
View GitHub Profile
@gouf
gouf / SearchInEvernote.scpt
Created June 30, 2019 08:52
クリップボードにコピーされた値で Evernote のノートを検索する
# Alfred Workflow から利用することを想定
# ユーザ指定の検索キーワードがクリップボードにコピーされていることを期待
# NOTE: すでにアプリケーションが起動している必要がある
tell application "Evernote"
activate
delay 0.2
# キーストロークをシステムイベントとして送信
# NOTE: 適宜 delay を入れないと操作が速すぎて 受け付けてもらえない
@gouf
gouf / SearchWordsInSlack.scpt
Created March 11, 2019 22:44
Slack の検索窓を呼び出して与えられた引数で検索 (AppleScript)
on run argv # TIPS: {"arg1", "arg2"...} と複数設定できる
if (count of argv) > 0 then
set searchWord to argv
else
set searchWord to "test_keystroke"
end if
# NOTE: すでにアプリケーションが起動している必要がある
tell application "Slack"
@gouf
gouf / UpdateSlackStatus.scpt
Created January 3, 2019 15:02
AppleScript: Slack のステータス メッセージを変更する。アイコンは muscle 固定でそれに変更
property statusMessageAs : ""
on run argv # TIPS: {"arg1", "arg2"...} と複数設定できる
if (count of argv) > 0 then
set statusMessageAs to argv
else
set statusMessageAs to "AppleScriptIsFun"
end if
@gouf
gouf / SwitchSlackChannel.scpt
Created January 3, 2019 12:39
AppleScript: 与えられた引数をもとに Slack アプリのチャンネル表示を切り替える
property channelName : ""
on run argv # TIPS: {"arg1", "arg2"...} と複数設定できる
if (count of argv) > 0 then
set channelName to argv
else
set channelName to "my_home_channel"
end if
@gouf
gouf / faker.rb
Created December 29, 2018 13:26
Faker で適当な JSON データの生成
# frozen_string_literal: true
require 'faker'
require 'json'
result =
Array.new(100).map do |i|
gender = %w[Male Female].sample
first_name, last_name =
if gender.eql?('Male')
@gouf
gouf / params_to_sql_fragment.rb
Created December 27, 2018 02:11
key / value な形式で送られてきた値を Model#where で検索できる形式に変換する
# 次のコードで登場する User モデルの各定数には Hash で値が代入されている + コントローラやビューで <form/> の値として使われている
# eg. FROZEN_FRUITS = {'0' => 'Apple', '1' => 'Banana'}.freeze
# values にはUser モデルの定数に定義された value 側の値が代入されている
# eg. ['Apple', 'Banana']
# 呼び出し元はループ処理でこのメソッドを呼び出して、最終的に 条件群、パラメータ群の配列に纏めている
# コントローラ内で分解された params 内の Hash から Model#where で検索できる値のペアを生成する
def params_to_sql_fragment(field, values)
@gouf
gouf / call_class_name_by_string.rb
Created December 20, 2018 11:17
メモ。 singularize, constantize + send で処理を共通化できるかもしれない
# 哀しみのドットつなぎテーブル名・カラム名が View か Controller か、どこからかやってくる
def search(table_and_column, search_values)
# table_and_column : 'member_types.name'
# search_values : %w[foo, bar]
result =
case table_and_column
# New code
when 'member_types.name' #, 'other_attr.name', 'some_attr.name'
model_name =
@gouf
gouf / regex_test.js
Created December 9, 2018 06:43
某ページの表記方法を改変
// Ref:
// * [Mocha - the fun, simple, flexible JavaScript test framework](https://mochajs.org/)
// * [Chai](https://www.chaijs.com/)
// Run commands as bellow:
// yarn install
// yarn run mocha --watch
var expect = require('chai').expect
@gouf
gouf / scraper.rb
Created December 8, 2018 17:23
処理順序がだいじなコードに yield_self を適用する (Ruby 2.5)
# Ref: https://github.com/gouf/scholar_ps/blob/7b4b4bbe79197cbb2683af9cae95ada7e5418c46/ScholarPs/scraper/scraper.rb#L14
def process!
html =
@watir.yield_self(&method(:login!))
.yield_self(&method(:loan_id_confirm!))
.yield_self(&method(:findout_loan_detail!))
.yield_self(&:html)
detail_page = Nokogiri::HTML(html)
@gouf
gouf / wishlist_whole_price.js
Created December 8, 2018 16:56
Amazon の欲しいものリストから総額を取得 (簡易版)
(new Intl.NumberFormat('ja-JP', {
style: 'currency',
currency: 'JPY'
})).format(
Array.from(document.querySelectorAll('span.a-price-whole').values())
.map(function(v) { return v.innerText })
.map(function(v) { return parseInt(v.split(',').join('')) })
.reduce(function(ret, v) { return ret + v })
)