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 / notify_to_slack.sh
Last active March 16, 2017 13:45
Notify command execution result to Slack (Incoming Webhooks)
#!/bin/sh
WORK_DIR="/where/to/work/directory"
cd $WORK_DIR || exit # In crontab, it may needs moving into work directory from default directory (home directory)
LS_FILES="$(ls -l file*)" # Wants notify this result
notifyToSlack() {
# In crontab, make sure to the curl command (or other commands) is full path.
/usr/bin/curl -X POST -H 'Content-type: application/json' \
@gouf
gouf / parent_directory_file.php
Created January 23, 2017 12:27
一つ上のディレクトリのファイルを、絶対パスとして表示
<?php
echo realpath(dirname(__DIR__ . '/../')) . '/foo.php';
echo "\n";
@gouf
gouf / json_parse.rb
Created January 15, 2017 05:45
Code School のユーザ情報をリクエストしてJSON 形式で取得
require 'open-uri'
require 'json'
require 'pp'
user_name = 'gouf'
uri = URI.parse("https://www.codeschool.com/users/#{user_name}.json")
pp json = JSON.parse(uri.open.read)
=begin
pp completed_course_links =
@gouf
gouf / note.md
Last active January 15, 2017 03:27
実行に時間がかかる(無限ループするかもしれない)プログラムの実行時間を制限する

ToDo

Set timeout to process runs.

TL;DR

Just install coreutils, and use timeout command.

coreutils をインストールして、 gtimeout (Mac) を使用する

@gouf
gouf / nico.rb
Last active January 10, 2017 16:45
Niconico にログインしてニコレポ マイリストの情報から動画タイトル・リンクを取得する
require 'mechanize'
module MechanizeScraper
class NicoVideo
TOP_PAGE = 'http://www.nicovideo.jp/'.freeze
LOGIN_PAGE = 'https://account.nicovideo.jp/login'.freeze
MY_PAGE = 'http://www.nicovideo.jp/my/top'.freeze
def initialize(email_or_tel, password)
@mechanize = Mechanize.new
@gouf
gouf / app.js
Created December 31, 2016 10:05
Vue.js 入力された年数から、創立何年目かを表示させる
'use strict';
var app = new Vue({
el: '#app',
data: {
ESTABLISHMENT_YEAR: 1882,
inputYear: null,
MESSAGE: 'ここに創立経過年数が表示されます'
},
computed: {
@gouf
gouf / aws_kms_client.rb
Last active January 3, 2017 08:52
AWS KMS サービスを利用して、秘密にしたいデータをコードの中で扱えるようにする
require 'aws-sdk'
# Please set your own key id
# Ref: https://console.aws.amazon.com/iam/home?region=ap-northeast-1#/encryptionKeys/ap-northeast-1
key_id = 'arn:aws:kms:ap-northeast-1:000000000000:key/00000000-0000-0000-0000-000000000000' # note: keep secret key_id, export to environment variable
kms = Aws::KMS::Client.new(
region: 'ap-northeast-1'
)
@gouf
gouf / guessNumber.swift
Last active December 5, 2016 08:25
Swift で数あてゲーム
import Foundation
class GuessNumber {
lazy var correctNumber: Int = self.randomNumber()
var answerNumber: Int = 0
var answerCount: Int = 1
init() {
// Initialize and start game
printGameGuide()
@gouf
gouf / Main.java
Last active November 22, 2016 07:33
同クラスの各インスタンスから、共通であるインスタンスメソッドを呼び出して、特定の結果を得る
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
import myClass.MyClass;
class Main {
public static void main(String []args) {
// 特定のクラスのインスタンスを想定
@gouf
gouf / ekidata_jp.rb
Created November 7, 2016 10:30
駅データ.jp (www.ekidata.jp) で配布されているデータをいい感じにHash に合成する
require 'csv'
require 'pp' # pretty print
module EkidataJp;end
module EkidataJp::Exception;end
class EkidataJp::Exception::NoPresentStationCsvHeader < StandardError
def message
'Please specify some of EkidataJp::CombineStationNameAndPref#station_csv_headers'