Skip to content

Instantly share code, notes, and snippets.

@hiroara
hiroara / analysis.rb
Last active Nov 17, 2020
Analyze Redis data usage
View analysis.rb
#!/usr/bin/env ruby
require 'csv'
class Level
attr_reader :key, :parent, :bytesize, :total_bytesize, :children
def initialize parent, key, bytesize = 0
@parent = parent
@key = key
View export-docker-volume.sh
#!/bin/bash
IMAGE=${IMAGE:-alpine:3.7}
TARGET_VOLUME=$1
if [ -z ${TARGET_VOLUME} ]; then
echo "Usage $0 <volume name>"
exit 1
fi
@hiroara
hiroara / 三重県.json
Last active Feb 6, 2020
Japan Prefectures Geojson
View 三重県.json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hiroara
hiroara / encode.rb
Last active Aug 29, 2015
Encode/Decode string using encodemaniax
View encode.rb
#!/usr/bin/env ruby
require 'uri'
require 'net/http'
require 'cgi'
require 'nokogiri'
EM_URL = URI.parse('http://encodemaniax.com')
def build_query data, charset='utf-8'
@hiroara
hiroara / watchyo.rb
Created May 2, 2015
Watching Process and send YO
View watchyo.rb
target_pid = ARGV[0].to_i
target_yo_user = ARGV[1].upcase
threshold_cpu = (ARGV[2] || 50).to_i
sampling_times = (ARGV[3] || 3).to_i
sleep_sec = (ARGV[4] || 1).to_i
puts "watching #{target_pid}..."
puts " - Target YO User: #{target_yo_user}"
puts " - Threshold of CPU Usage: #{threshold_cpu}%"
puts " - Sampling times: #{sampling_times}"
puts " - Sleep Seconds: #{sleep_sec}s"
@hiroara
hiroara / naottaYO.sh
Last active Aug 29, 2015
YOで復活通知
View naottaYO.sh
yo="curl -X POST -d username=$USERNAME -d api_token=$APITOKEN https://api.justyo.co/yo/"
until nslookup rubygems.org && nslookup bb-m.rubygems.org && $yo; do echo "fail..."; sleep 1; done
@hiroara
hiroara / benchmark.rb
Created May 29, 2014
Rspec Benchmarking script. Put this file under `spec/supports/` and execute `BENCHMARK=1 rake spec`.
View benchmark.rb
RSpec.configure do |config|
next unless ENV['BENCHMARK'] == '1'
benchmarks = []
metadata_keys = %i[ file_path line_number described_class ]
info_keys = %i[ type ] + metadata_keys + %i[ full_description ]
log_file = Rails.root.join('log', 'rspec_benchmark.csv')
config.before(:suite) do
CSV.open(log_file, "wb") do |csv|
csv << info_keys + %i[ utime stime cutime cstime real]
end
@hiroara
hiroara / capturable.rb
Last active Dec 26, 2015
Rubyのメソッド実行をキャプチャしてツリー構造で返すモジュール
View capturable.rb
module Capturable
EXCLUDE_METHODS = [:class, :send, :respond_to?, :capture_methods, :__send__, :__id__]
def self.included(base)
base.class_eval do
def self.capture_methods options={}
method_list = options[:method_list]
exclude_methods = options[:exclude_methods] || []
exclude_regexp = options[:exclude_regexp] || /\A_/
source_root = case options[:source_root]
@hiroara
hiroara / alloy.jmk
Created May 25, 2013
CoffeeScript+Jade+Jasmine環境でAlloyによる開発をするためのコンパイルスクリプト。
View alloy.jmk
task("pre:compile", function(event,logger) {
var wrench = require("wrench"),
fs = require("fs"),
jade = require("jade"),
view_root = event.dir.views,
path = require("path"),
coffee = require("coffee-script");
event.alloyConfig.xml = [];
event.alloyConfig.coffee = { home: [], resources: [] };
@hiroara
hiroara / 2013-01-28-example-post.markdown
Last active May 10, 2016
OctopressからQiitaへ記事を自動投稿するプラグインです。基本的にJekyllプラグインなのでJekyll単体でも使えるかもしれません(動作未確認)。 Octopressでこのプラグインを使うには、Gemfileに`gem 'qiita'`を追加して、pluginsフォルダ以下にqiita_post_generator.rbを配備してください。 あと、`_config.yml`に`qiita_token: abcdefghijklmnopqrstuvwxyz`の形式でQiita用のトークンを書いておきます。 rake generate の際に 2013-01-28-example-post.markdown のように qiita 属性 published: true が指定し…
View 2013-01-28-example-post.markdown

layout: post title: "Qiita APIで自動投稿" date: 2013-01-23 23:41 comments: true published: true qiita: tags: - name: ruby versions: