Skip to content

Instantly share code, notes, and snippets.

View shoyan's full-sized avatar

Shohei Yamasaki shoyan

View GitHub Profile
@shoyan
shoyan / instagram-basic-display-api-sample.php
Created February 5, 2023 08:01
InstagramのBASIC Display APIを使ったサンプルコード
<?php
// インスタグラムのAPI情報
define('TOKEN', 'YOUR_ACCESS_TOKEN');
define('MEDIA_URL', 'https://graph.instagram.com/me/media?fields=id,caption,permalink,media_type,media_url,username&access_token=%s');
// 取得する件数
define('LENGTH', 10);
// インスタグラムからデータを取得
$response = json_decode(file_get_contents(sprintf(MEDIA_URL, TOKEN)), true);
// 表示する件数に切り取る
@shoyan
shoyan / wait_process.sh
Last active August 28, 2023 15:03
別プロセスの結果を取得するシェルスクリプトのサンプル
#!/bin/bash
command1() {
echo "executing commnad1"
sleep 3
}
command2() {
echo "executing commnad2"
sleep 3
@shoyan
shoyan / 8hour45min.ruby
Last active October 16, 2018 00:56
今から8時間45分後を計算する
# 時刻を加算するにはRationalを足す。
# 1分後はRational(1, 24*60)
# 8時間45分は525分なのでRational(525, 24*60)を加算すればよい
DateTime.now + Rational(525,24*60)
@shoyan
shoyan / chat_postmessage_sample.rb
Created October 28, 2016 06:48
chat.postMessage sample for Slack
require "faraday"
username = 'your name'
channel = 'your channel'
slack_token = 'your slack token'
icon_url = 'your icon url'
body = {
username: username,
channel: channel,
@shoyan
shoyan / wordpress.sh
Created August 18, 2016 06:14
WordPressのアーカイブを作成するスクリプト
#!/bin/bash
#
# WordPressのアーカイブを作成するスクリプトです。
# 指定されたWordPressのバージョンにSiteGuardプラグインをいれて、アーカイブを作成します。
#
# Usage:
# ./wordpress.sh version
#
# Example:
# ./wordpress.sh 4.1.1
@shoyan
shoyan / entropy
Last active June 30, 2016 02:03
エントロピーを計算するツール
#!/usr/bin/env ruby
# Usage
# ./entropy file
# echo "aaaaaaaabbbbbbbbbcc" | ./entropy
require 'optparse'
options = {}
@shoyan
shoyan / entropy.rb
Created June 24, 2016 09:19
雑なエントロピーの計算
str="abccddeeeeffffgggggggghhhhhhhh"
def entropy(str)
count = str.size
list={}
list.default=0
str.split("").each {|c| list[c]+=1}
sum = 0
list.each do |key, val|
@shoyan
shoyan / word_count.rb
Created March 22, 2016 09:38
単語数の出現回数をカウントする
text =<<TEXT
The example above works as intended because the five instances of the (anonymous) inner function refer to five different instances of variable j. Note that it does not work as intended if you replace let by var or if you remove the variable j and simply use the variable i in the inner function.
TEXT
result = {}
result.default = 0
text.split(" ").map { |a| a.gsub(/\.$/, '').gsub(/\(|\)/, '').downcase }.sort.each { |b| result[b.to_sym]+=1 }
p result.sort {|(k1, v1), (k2, v2)| v2 <=> v1 }
@shoyan
shoyan / Dockerfile
Created March 9, 2016 06:38
Dockerfile to build php5.2.
FROM ubuntu
MAINTAINER shoyan
USER root
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get -y install build-essential
RUN apt-get -y install libxml2-dev
RUN apt-get -y install wget
@shoyan
shoyan / email_validator_spec.rb
Created January 15, 2015 09:13
test of EmailValidator.
require 'spec_helper'
describe "EmailValidator" do
before do
@validator = EmailValidator.new({:attributes => {email: ''}})
@mock = double("Foo")
allow(@mock).to receive(:errors).and_return([])
allow(@mock.errors).to receive(:[]).and_return({})
allow(@mock.errors[]).to receive(:<<)