ruby
1000æªæºã®ããç´ æ°ãã¤åææ°ãã®æ大å¤ãåºåãã
CodeEvalinput 3 5 10 2 7 15output 1 2 F 4 B F 7 8 F B 1 F 3 F 5 F B F 9 F 11 F 13 FB 15
3å¹´ãããåã«ãã¼ã«ã«ã§ä½¿ãããã«ä½ã£ãRailsã¢ããªãåãããã¨ãã¦ãbundle installããããsqlite3-rubyã ãã¤ã³ã¹ãã¼ã«ã§ããªããè¦è¦ããããã¨ã©ã¼ã gem install sqlite3-ruby Building native extensions. This could take a while... ERROR: Errâ¦
RubyWarrior - Blocè±èªã ãã©ã¡ãã£ã¨è¦ãã°ä½ããããã¯ãããããã¨æããåã«é²ãã ããå¾ãã«æ»ã£ãããæµã«æ»æãããããã¡ã¼ã¸ããã£ããå復ããããããã°ã©ãã³ã°ãã¦ãããã¢ã®æµãåãã¦ãããå¼ç¢ã使ãæµããããããã¨ãã¨ã¯ã³ãã³ãã©ã¤ã³â¦
ééã£ã¦pythonã§str.split(//)ã¨ãæ¸ãã¦ãã¾ã£ããsplit(//)ã§ã§ããã®ã¯rubyã ã£ããruby str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" str.split(//) => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"â¦
import hmac import hashlib secret_key = "secret_key" message = 'message' print hmac.new(secret_key, message, hashlib.sha256).hexdigest() # => ebb8d2ee5dcad6e9d6fc0b606811f9f03036bdd419a364d1a1ce1afa1bea61fd require 'openssl' secret_key = 'â¦
railsã®2.3.8ãå¿ è¦ã«ãªã£ãã®ã§ã¤ã³ã¹ãã¼ã«ãããæè¿rubyãå ¨ç¶ããã£ã¦ãªãã®ã§å¿ãã¦ãã¾ã£ã¦ãããã©ã-vã§ãã¼ã¸ã§ã³æå®ãããã§ããã gem install rails -v 2.3.8 rdocã¨ãriã¨ãã¤ã³ã¹ãã¼ã«ããã¦é ãã--no-rdoc --no-riãã¤ããã°å ¥ããªããã â¦
python # coding=utf-8 import hashlib text = "ä»»æã®æåå" #print hashlib.sha224(text).hexdigest() print hashlib.sha256(text).hexdigest() print hashlib.sha384(text).hexdigest() print hashlib.sha512(text).hexdigest() ruby # -*- encoding: utâ¦
kickstrapã®jsããªãã¨ãªãèªãã§ãããããªã®è¦ã¤ãã¾ããã // IE compatibility fallbacks, turned on when needed. // Thanks to http://stackoverflow.com/questions/2790001/fixing-javascript-array-functions-in-internet-explorer-indexof-foreach-â¦
rubyã§ã¯Numeric#to_sã«åºæ°nã渡ãã¨né²æ°ã§ã®æåå表ç¾ãè¿ãã¦ããã¾ãã1000000ã2ã36é²æ°ã§åºåããã³ã¼ãruby (2 .. 36).each do |e| p 10000000.to_s(e) end # => "100110001001011010000000" # => "200211001102101" # => "212021122000" # => "10â¦
base64ã¨ã¯ Base64ã¯ããã¼ã¿ã64種é¡ã®å°åå¯è½ãªè±æ°åã®ã¿ãç¨ãã¦ããã以å¤ã®æåãæ±ããã¨ã®åºæ¥ãªãéä¿¡ç°å¢ã«ã¦ãã«ããã¤ãæåããã¤ããªãã¼ã¿ãæ±ãããã®ã¨ã³ã³ã¼ãæ¹å¼ã§ããã http://ja.wikipedia.org/wiki/Base64 ç»åãã¨ã³ã³ã¼ãããæâ¦
uuidã¨ã¯ UUIDï¼Universally Unique Identifierï¼ã¨ã¯ãDistributed Computing Environment (DCE)ã®ä¸é¨ã¨ãã¦Open Software Foundation (OSF)ãæ¨æºåãããä¸æã«èå¥ããããã®èå¥åã§ãããUUIDã¯ãåæ£ã·ã¹ãã ä¸ã§ã©ãããçµ±å¶ãåããã¨ããä¸æã«ç¹â¦
python s = "1" print s.zfill(3) # => 001 ruby s = "1" p s.rjust(3, '0') # => 001 javascript sliceã使ã£ã¦ var s = "1" ("000" + s).slice(-3) # => 001
åå¨ã¯ç¥ã£ã¦ãããã©ããã¾ã使ããã¨ããªãã£ãã ããä»æ¥ã¯ä½¿ãããã¨æãã±ã¼ã¹ã«ééããã®ã§ã使ãæ¹ãã¡ã¢ãã¦ããè¤æ°ã®ã·ã¼ã±ã³ã¹ã«ä¸¦è¡ãã¦åæã«ã¢ã¯ã»ã¹ããforã«ã¼ããæ¸ãã®ã«ä¾¿å©ã python # coding=utf-8 seq1 = [1,2,3,4,5] seq2 = ['a','â¦
SHA-1ã¨ã¯ èªè¨¼ããã¸ã¿ã«ç½²åãªã©ã«ä½¿ãããããã·ã¥é¢æ°(è¦ç´é¢æ°)ã®ã²ã¨ã¤ã2ã®64ä¹ããã以ä¸ã®åæãã160ãããã®ãããã·ã¥å¤ããçæããéä¿¡çµè·¯ã®ä¸¡ç«¯ã§æ¯è¼ãããã¨ã§ãéä¿¡éä¸ã§åæãæ¹ããããã¦ããªãããæ¤åºãããã¨ãã§ãããè¨ç®æ¹æ³ã«â¦
python from datetime import datetime s = "2012-06-11 12:20:36" d = datetime.strptime(s, "%Y-%m-%d %H:%M:%S") print d # => 2012-06-11 12:20:36 ruby require 'date' s = "2012-06-11 12:20:36" d = DateTime.strptime(s, "%Y-%m-%d %H:%M:%S") printâ¦
便å©ã¹ã¯ãªãããgistã«å ¬éããã¦ããã§ãåºæ¬çã«ä½¿ã£ã¦ã¿ãã ããªãã§ãããããã¤ãæ°ã¥ããç¹ããã£ãã®ã§ã¡ã¢ãã¦ããã¾ãã https://gist.github.com/2129714 rackãä½æãããsshã§ãã°ã¤ã³ãã¦ãrailsã¤ã³ã¹ãã¼ã«ãã¦rails newãã¾ã gem install â¦
ã¡ãã»ãè¨äºãç®ã«ããrackhubãã¡ãã£ã¨è©¦ãã¦ã¿ã¾ãããhttp://rackhub.net/ ããããã¼ã¸ã®ãä»ããå§ãã!ããã¿ã³ãæ¼ãã¦ãã¦ã¼ã¶ã¼ç»é²ç»é¢ã«é·ç§»ãã¾ã ã¦ã¼ã¶ã¼åãã¡ã¼ã«ã¢ãã¬ã¹ããã¹ã¯ã¼ããå ¥åããç»é²ãã¿ã³ãæ¼ãã¾ãã ã¦ã¼ã¶ã¼ç»é²ãå®â¦
pythonã®è¾æ¸ã«ã¯setdefaultã¨ãã便å©ãªã¡ã½ããããã£ã¦ããã¼ã«å¯¾ããå¤ããªãã¨ãã®ããã©ã«ãå¤ã渡ããã¨ãã§ãã data = [('japan', 'tokyo'), ('uk', 'london'), ('japan', 'osaka')] h = {} for country, city in data: h.setdefault(country, []).â¦
rubyã§æåã®å ¥åãã§ãã¯ã¨ãã´ãã§ã´ãã§ãã£ã¦ãã®ã§ã¡ã¢ # ruby # æåãã¦ãã³ã¼ãã®ã³ã¼ããã¤ã³ãã« 'ã'.unpack('U').first # => 12354 # 16é²æ° 12354.to_s(16) # => "3042" # ã¦ãã³ã¼ãã®ã³ã¼ããã¤ã³ããæåã« [0x3042].pack('U') # => "ã" ã¤â¦
æ®æ®µfold-dwim.elçµç±ã§hideshow.elã使ã£ã¦ã¾ãã ã§ãå æ¥ã²ãã³ãã«rubyã³ã¼ããèªãã§ã¦æ°ã¥ãããã§ãããruby-modeã§ã®ãã©ã¼ã«ãã£ã³ã°ã¯å¯¾å¿ãã¦ããªãã®ã§å¹ãã¾ããã ã¡ãã£ã¨èª¿ã¹ãã¨ããã以ä¸ã®æ å ±ãè¦ã¤ãã¾ããElisp/hideshow.el http://wwâ¦
ruby FileTest.directory?('/Applications') # => true FileTest.directory?('/Application') # => false python import os os.path.isdir('/Applications') # => True os.path.isdir('/Application') # => False
ã¡ã¿ããã°ã©ãã³ã°Rubyã§åçãããã·ã¨ãããã®ãç´¹ä»ããã¦ãã¾ãã©ã®ã¡ã½ããã«ãå½ã¦ã¯ã¾ããªãã¡ãã»ã¼ã¸ãä»ã®ãªãã¸ã§ã¯ãã«å§è²ãããã¨ãããã®ã§ãä¸è¨ã¯ã¡ã¿ããã°ã©ãã³ã°Rubyã§ç´¹ä»ããã¦ãããµã³ãã«ã³ã¼ãã¨ã»ã¼åããã®ã§ã class MyDynamiâ¦
åçãã£ã¹ããã åçãã£ã¹ãããã¯ããå®è¡æã«å¼ã³åºãã¡ã½ããã決ããããã¨ãæãã¾ãã rubyã§ã¯sendã«ãã£ã¦åçãã£ã¹ããããã§ãã¾ã method_to_call = :upcase obj = "abc" obj.send(method_to_call) # => "ABC" pythonã§ã¯ã¡ã½ããããªãã¸ã§â¦
ã¡ãã£ã¨åã¾ã§ã¯rubyã§ãæè¿ã¯pythonã§ä»äºããã¦ããã®ã§ãrubyã§ãã£ã¦ããã¢ã¬ãpythonã ã¨ã©ããããã ãï¼ã¨æããã¨ããã¾ã«ããã¾ãã éã«pythonæ¸ãã¦ã¦ãããããrubyã§(ry ã¨ã ã§ãã¤ã³ã¹ã¿ã³ã¹å¤æ°ã®æä½ã§ããã pythonã§ã¯ãããããå®ç¾©ãâ¦
ã¡ãã£ã¨åã¾ã§ã¯rubyã§ãæè¿ã¯pythonã§ä»äºããã¦ããã®ã§ãrubyã§ãã£ã¦ããã¢ã¬ãpythonã ã¨ã©ããããã ãï¼ã¨æããã¨ããã¾ã«ããã¾ãã ã§ãã¯ã©ã¹ã¸ã®ã¤ã³ã¹ã¿ã³ã¹ã¡ã½ãã追å ã§ããã rubyã§ã¯ãªã¼ãã³ã¯ã©ã¹ã«ãã£ã¦ãã¤ã³ã¹ã¿ã³ã¹ã¡ã½ããã追â¦
python from datetime import datetime, timedelta today = datetime.today() today + timedelta(minutes=1) # => 1åå¾ today + timedelta(hours=1) # => 1æéå¾ today + timedelta(days=1) # => 1æ¥å¾ ruby require 'date' today = DateTime.now() today â¦
rubyã«ã°ããæ £ãã¦ããã®ã§ãpythonã®è¾æ¸ããå¤ãåå¾ãããã¨ãã¦ããã¼ããªãå ´åã«Errorã«ãªããã¨ã«ãã¡ãã£ã¨ã ãã¨ã¾ã©ãã¾ããã ãã£ãããªã®ã§ããã·ã¥/è¾æ¸ã®æ±ãæ¹ã®ã¡ã¢ãæ®ãã¦ããã¾ãã python my_dict = {"a": 1, "b": 2} # å¤ã®åå¾ prinâ¦
module Foo module PreExtension def method p " pre " super end end module Base def method p " base " end end module PostExtension def method super p " post " end end include Base include PostExtension include PreExtension end class Bar inclâ¦