Skip to content

Instantly share code, notes, and snippets.

View jacoyutorius's full-sized avatar
🏠
Working from home

jacoyutorius jacoyutorius

🏠
Working from home
View GitHub Profile
@jacoyutorius
jacoyutorius / oauth1_0a_header.rb
Last active December 30, 2022 06:39
OAuth1.0a認証用ヘッダーを生成する
require 'openssl'
require 'cgi'
require 'base64'
# see https://developer.twitter.com/ja/docs/authentication/oauth-1-0a/creating-a-signature
module Oauth1_0a
class Authorization
attr_accessor :http_method, :url, :consumer_key, :consumer_secret, :token, :token_secret, :nonce, :timestamp
def initialize(http_method:, url:, consumer_key:, consumer_secret:, token:, token_secret:)
@jacoyutorius
jacoyutorius / akaden.rb
Created October 4, 2021 11:48
Akadenのクラス設計(駅名をメソッドにするパターン)
module Akaden
module Station
STATIONS = %w(shin_hamamatsu daiichi_dori kamijima).freeze
end
class Info
class << self
include Station
STATIONS.each do |station|
@jacoyutorius
jacoyutorius / akaden.rb
Last active October 4, 2021 01:58
Akadenのクラス設計(駅名をクラスにするパターン)
module Akaden
STATIONS = %w(DaiichiDori Kamijima)
module InfoLoadable
def do_info
"#{station} info!"
end
end
module TimetableLoadable
@jacoyutorius
jacoyutorius / duplicate_file_cleaner.rb
Last active December 1, 2020 13:59
連番が振られた同じファイルを抽出するRubyスクリプト
require 'fileutils'
class DuplicateFileCleaner
class << self
def run(dir: '', extname: 'txt', dryrun: false)
self.new(extname, dryrun).cleanup(dir)
end
end
def initialize(extname, dryrun)
@jacoyutorius
jacoyutorius / Dockerfile
Last active October 19, 2019 05:03
Vue on docker
FROM node:10.16.3-alpine
WORKDIR /app
RUN apk update && \
npm install -g npm @vue/cli
@jacoyutorius
jacoyutorius / template.yml
Created April 13, 2019 16:21
CloudFormation for S3Bucket and IAMUser
AWSTemplateFormatVersion: 2010-09-09
Description: ---
create IAM user only access S3 bucket
# validate
- aws cloudformation validate-template --template-body file://template.yml
# crete stack
- aws cloudformation create-stack --stack-name S3IAMUser --template-body file://template.yml --capabilities CAPABILITY_NAMED_IAM
@jacoyutorius
jacoyutorius / override.rb
Last active January 24, 2019 15:25
Array#override
require 'test/unit'
# Array#override
#
# [0, 0, 0, 0, 0].override(['a', 'b'])
# => ['a', 'b', 0, 0, 0]
#
# [0, 0, 0, 0, 0].override(['a', 'b'], 2)
# => [0, 0, 'a', 'b', 0]
import Ember from 'ember';
export default Ember.Controller.extend({
appName: "App Name",
params: [],
// paramsより後に定義すると、値が正しく判定されない
isFiltered: Ember.computed.or('params', 'appName'),
});
@jacoyutorius
jacoyutorius / awslambda_index.js
Last active October 22, 2018 13:19
AWS Lambda demo
const AWS = require('aws-sdk');
const dynamoDb = new AWS.DynamoDB.DocumentClient({
region: "ap-northeast-1"
});
// exports.handler = (event, context, callback) => {
// const data = {
// name: "yuto",
// email: "jacoyutorius@gmail.com",
@jacoyutorius
jacoyutorius / lifegame.rb
Created June 27, 2018 11:11
Rubyでライフゲーム
def main
lifegame = Lifegame.new(width: 100)
generation = 0
loop do
# puts "Generation: #{generation} ---------------------------"
lifegame.draw
sleep 0.025
generation += 1
end