Skip to content

Instantly share code, notes, and snippets.

@gongo
Created August 28, 2012 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gongo/3498362 to your computer and use it in GitHub Desktop.
Save gongo/3498362 to your computer and use it in GitHub Desktop.
ジョージアシールを入力してもらって、web.rb と同じディレクトリにある serial.txt にどんどん追記していく

ジョージアポイントシール集めたい

シール貰うの飽きた

gongo/gpkure に移りました

サーバ起動

$ bundle install --path vendor/bundle
$ bundle exec ruby web.rb -e production

登録

$ curl -d 'serial=1234567812345678' host:port
thanks!!

$ curl -d 'serial=invalid_16_digits_number' host:port
invalid serial number...
source :rubygems
gem 'sinatra'
gem 'thin'
gem 'haml'
gem 'shotgun', :group => 'development'
#!/bin/bash
#
# 16桁の乱数字列を100個作って登録
#
for i in `seq 1 100`
do
serial=`for d in \`seq 1 4\` ; do printf "%04d" $((RANDOM % 10000)) ; done`
curl -d "serial=${serial}" localhost:9393
echo $serial
done
# -*- coding: utf-8 -*-
require 'sinatra'
require 'haml'
LOCKFILE = "#{File.dirname(__FILE__)}/app.lock"
LOCKSTART = "lockfile -1 -r -1 -l 10 #{LOCKFILE}"
LOCKEND = "rm -f #{LOCKFILE}"
SERIAL_FILE = "#{File.dirname(__FILE__)}/serial.txt"
get '/' do
set :haml, :format => :html5
count = `cat "#{SERIAL_FILE}" | wc -l`
@msg = $?.exitstatus == 0 ? "#{count}" : 'None'
@uri = "#{request.host}:#{request.port}"
haml :index
end
post '/' do
serial = params[:serial]
if /^(\d{16})$/ =~ serial
%x{ #{LOCKSTART} && echo #{serial} | cat #{SERIAL_FILE} - | sort -uo #{SERIAL_FILE} && #{LOCKEND} }
"thanks!!\n"
else
"invalid serial number...\n"
end
end
__END__
@@ index
!!!
%html
%body
%p
Please input gerogia serial number.
%br
eg. curl -d 'serial=1234567812345678' #{@uri}
%p
Stock number of serial = #{@msg}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment