Skip to content

Instantly share code, notes, and snippets.

@daisaku
daisaku / cu_hacker_api.rb
Created March 7, 2014 15:40
for cu-hacker api
View:
<a target="_blank" href="<%= model.cuhacker_url %>">Cu-hackerで確認</a>
Model:
def cuhacker_url
url = 'https://cu-hacker.com/calendar?'
stime = Time.parse(self.meeting_date.to_s + ' ' + self.start_time.to_s) - (9*60*60)
stimeutc = stime.strftime("%Y%m%dT%H%M%SZ")
etime = Time.parse(self.meeting_date.to_s + ' ' + self.end_time.to_s) - (9*60*60)
etimeutc = etime.gmtime.strftime("%Y%m%dT%H%M%SZ")
@daisaku
daisaku / senpai.rb
Last active December 30, 2015 08:19
for co-ba program #17
#coding: utf-8
line = 0
count = 0
days = 0
products = Array.new
campaign_prices = Array.new
s = gets.chomp.split(" ")
count = s[0].to_i
days = s[1].to_i
@daisaku
daisaku / table.rb
Last active December 28, 2015 07:19
for co-ba program #15
x = (1..12)
y = (1..12)
print ' '
x.each {|i| print "%-5d" % i }
print "\n "
x.each {|i| print '---- '}
print "\n"
y.each do |j|
@daisaku
daisaku / kaiin.rb
Last active December 27, 2015 14:28
for co-ba program #14 「the 日本的な配慮 プログラミング」 会員を4桁の会員番号で管理している小売店がある。会員の中には,4と9の数字を嫌う人がいるとの理由で,会員番号は,0001,0002,0003,0005,…のように,この二つの数字を使わないように連番で発行している。会員番号を0001から0528まで発行したとき,会員番号を付与した会員数は何人か。 https://www.facebook.com/events/222187167949866/225003994334850/
#coding: utf-8
members = ('0001'..'0528').to_a
members.delete_if{|m| /[49]/ =~ m }
p members.count.to_s + '人'
import scala.testing.Benchmark
import scala.util.Random
object Main extends Benchmark {
def kouyaku(num:Int) {
var i:Int = 0
val listBuffer = new collection.mutable.ListBuffer[Int]
while(i <= num){
val maxnum = 10000
val a = Random.nextInt(maxnum)
val b = Random.nextInt(maxnum)
#coding: utf-8
cipher_text = "qdq-gi.q-a ziatmxxitmdqibtqi-ustbi ri.qmoqrcxi.qbubu zir -ibtqi-qp-qaai ripmymsqkir -ibtqi-qy dmxi ri.cnxuoi rruoumxakir -ibtqiqzmobyqzbkii-q.qmxi -imyqzpyqzbi rixmeaki -puzmzoqai -i-qscxmbu zaimzpir -i btq-iymbbq-a;iz -iatmxximzgi.q-a zinqiuzimzgiemgipuao-uyuzmbqpimsmuzabir -ia. za -uzsiacotiimi.qbubu zj"
@alphabet = "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z: :.:,:-".split(":") #復号用文字列
def decode(cipher, keyword)
@alphabet.each do |letter|
deciphered_text = ''
cipher_position = @alphabet.index(cipher[0].chr) #暗号文字列の1文字目が、復号用文字列の何文字目にあるか
clear_position = @alphabet.index(letter) #復号文字が、復号用文字列の何文字目にあるか
#coding: utf-8
require 'timeout'
def prime_list(n)
return [] if n < 2
return [2] if n == 2
limit = (n ** 0.5).to_i
arr = (1 .. n).step(2).to_a
arr[0] = 2
len = arr.size
#coding: utf-8
require 'open-uri'
require 'nokogiri'
hatena_url = 'http://b.hatena.ne.jp/hotentry.rss'
yahoo_url = 'http://jlp.yahooapis.jp/MAService/V1/parse'
appid = '*****'
doc = Nokogiri.HTML(open(hatena_url))
str = ""
doc.css('item').each do |item|
count = item.css('bookmarkcount').first.content.to_i
#coding: utf-8
class Card
attr_accessor :suit, :num
def initialize(suit, num)
@suit = suit
@num = num
end
def to_s
@num.to_s + "[" + @suit + "]"
end
#coding: utf-8
require 'open-uri'
require 'zip/zip'
require 'csv'
CSVFILE = 'zenkoku.csv'
url = 'http://jusyo.jp/downloads/new/csv/csv_zenkoku.zip'
filename = url.split(/\//).last
open(url) do |source|
open(filename, "w+b") do |o|
o.print source.read