_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3
values | text stringlengths 66 10.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q2200 | QuartzTorrent.Reactor.withReadFiber | train | def withReadFiber(ioInfo)
if ioInfo.readFiber.nil? || ! ioInfo.readFiber.alive?
ioInfo.readFiber = Fiber.new do |ioInfo|
yield ioInfo.readFiberIoFacade
end
end
# Allow handler to read some data.
# This call will return either if:
# 1. the handler needs mo... | ruby | {
"resource": ""
} |
q2201 | QuartzTorrent.PeerManager.manageConnections | train | def manageConnections(classifiedPeers)
n = classifiedPeers.handshakingPeers.size + classifiedPeers.establishedPeers.size
if n < @targetActivePeerCount
result = classifiedPeers.disconnectedPeers.shuffle.first(@targetActivePeerCount - n)
@logger.debug "There are #{n} peers connected or in han... | ruby | {
"resource": ""
} |
q2202 | QuartzTorrent.PeerManager.selectOptimisticPeer | train | def selectOptimisticPeer(classifiedPeers)
# "at any one time there is a single peer which is unchoked regardless of its upload rate (if interested, it counts as one of the four allowed downloaders). Which peer is optimistically
# unchoked rotates every 30 seconds. Newly connected peers are three times as l... | ruby | {
"resource": ""
} |
q2203 | Rapidoc.ControllerExtractor.extract_blocks | train | def extract_blocks( lines )
init_doc_lines = lines.each_index.select{ |i| lines[i].include? "=begin" }
end_doc_lines = lines.each_index.select{ |i| lines[i].include? "=end" }
blocks = init_doc_lines.each_index.map do |i|
{ :init => init_doc_lines[i], :end => end_doc_lines[i] }
end
e... | ruby | {
"resource": ""
} |
q2204 | DoSnapshot.Command.create_snapshot | train | def create_snapshot(droplet) # rubocop:disable MethodLength,Metrics/AbcSize
fail_if_shutdown(droplet)
logger.info "Start creating snapshot for droplet id: #{droplet.id} name: #{droplet.name}."
today = DateTime.now
name = "#{droplet.name}_#{today.strftime('%Y_%m_%d')}"
# ... | ruby | {
"resource": ""
} |
q2205 | DoSnapshot.Command.dispatch_droplets | train | def dispatch_droplets
droplets.each do |droplet|
id = droplet.id.to_s
next if exclude.include? id
next unless only.empty? || only.include?(id)
prepare_droplet id, droplet.name
end
end | ruby | {
"resource": ""
} |
q2206 | DoSnapshot.Command.prepare_droplet | train | def prepare_droplet(id, name)
logger.debug "Droplet id: #{id} name: #{name}\n"
droplet = api.droplet id
return unless droplet
logger.info "Preparing droplet id: #{droplet.id} name: #{droplet.name} to take snapshot."
return if too_much_snapshots?(droplet)
processed_droplet_ids << dro... | ruby | {
"resource": ""
} |
q2207 | DoSnapshot.Command.cleanup_snapshots | train | def cleanup_snapshots(droplet, size) # rubocop:disable Metrics/AbcSize
return unless size > keep
warning_size(droplet.id, droplet.name, size)
logger.debug "Cleaning up snapshots for droplet id: #{droplet.id} name: #{droplet.name}."
api.cleanup_snapshots(droplet, size - keep - 1)
rescue =>... | ruby | {
"resource": ""
} |
q2208 | Twilio.AvailablePhoneNumbers.search | train | def search(opts={})
iso_country_code = opts[:iso_country_code] || 'US'
resource = opts.delete(:resource)
params = {
:AreaCode => opts[:area_code],
:InPostalCode => opts[:postal_code],
:InRegion => opts[:in_region],
:Contains => opts[:contains],
:NearLatLong => ... | ruby | {
"resource": ""
} |
q2209 | QuartzTorrent.PeerClientHandler.addTrackerClient | train | def addTrackerClient(infoHash, info, trackerclient)
raise "There is already a tracker registered for torrent #{QuartzTorrent.bytesToHex(infoHash)}" if @torrentData.has_key? infoHash
torrentData = TorrentData.new(infoHash, info, trackerclient)
trackerclient.alarms = torrentData.alarms
@torrentDat... | ruby | {
"resource": ""
} |
q2210 | QuartzTorrent.PeerClientHandler.removeTorrent | train | def removeTorrent(infoHash, deleteFiles = false)
# Can't do this right now, since it could be in use by an event handler. Use an immediate, non-recurring timer instead.
@logger.info "#{QuartzTorrent.bytesToHex(infoHash)}: Scheduling immediate timer to remove torrent. #{deleteFiles ? "Will" : "Wont"} delete ... | ruby | {
"resource": ""
} |
q2211 | QuartzTorrent.PeerClientHandler.setDownloadRateLimit | train | def setDownloadRateLimit(infoHash, bytesPerSecond)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to set download rate limit for a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
if bytesPerSecond
if ! torrentData.downRa... | ruby | {
"resource": ""
} |
q2212 | QuartzTorrent.PeerClientHandler.setUploadRateLimit | train | def setUploadRateLimit(infoHash, bytesPerSecond)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to set upload rate limit for a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
if bytesPerSecond
if ! torrentData.upRateLimit... | ruby | {
"resource": ""
} |
q2213 | QuartzTorrent.PeerClientHandler.adjustBytesDownloaded | train | def adjustBytesDownloaded(infoHash, adjustment)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to adjust uploaded bytes for a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
runInReactorThread do
torrentData.bytesDo... | ruby | {
"resource": ""
} |
q2214 | QuartzTorrent.PeerClientHandler.updateDelegateTorrentData | train | def updateDelegateTorrentData(delegate)
return if stopped?
# Use an immediate, non-recurring timer.
semaphore = Semaphore.new
@reactor.scheduleTimer(0, [:update_torrent_data, delegate, semaphore], false, true)
semaphore.wait
result
end | ruby | {
"resource": ""
} |
q2215 | QuartzTorrent.PeerClientHandler.serverInit | train | def serverInit(metadata, addr, port)
# A peer connected to us
# Read handshake message
@logger.warn "Peer connection from #{addr}:#{port}"
begin
msg = PeerHandshake.unserializeExceptPeerIdFrom currentIo
rescue
@logger.warn "Peer failed handshake: #{$!}"
close
... | ruby | {
"resource": ""
} |
q2216 | QuartzTorrent.PeerClientHandler.clientInit | train | def clientInit(peer)
# We connected to a peer
# Send handshake
torrentData = @torrentData[peer.infoHash]
if ! torrentData
@logger.warn "No tracker client found for peer #{peer}. Closing connection."
close
return
end
trackerclient = torrentData.trackerClient
... | ruby | {
"resource": ""
} |
q2217 | QuartzTorrent.PeerClientHandler.recvData | train | def recvData(peer)
msg = nil
@logger.debug "Got data from peer #{peer}"
if peer.state == :handshaking
# Read handshake message
begin
@logger.debug "Reading handshake from #{peer}"
msg = PeerHandshake.unserializeFrom currentIo
rescue
@logger.warn ... | ruby | {
"resource": ""
} |
q2218 | QuartzTorrent.PeerClientHandler.timerExpired | train | def timerExpired(metadata)
if metadata.is_a?(Array) && metadata[0] == :manage_peers
managePeers(metadata[1])
elsif metadata.is_a?(Array) && metadata[0] == :request_blocks
requestBlocks(metadata[1])
elsif metadata.is_a?(Array) && metadata[0] == :check_piece_manager
checkPieceMan... | ruby | {
"resource": ""
} |
q2219 | QuartzTorrent.PeerClientHandler.requestMetadataPieces | train | def requestMetadataPieces(infoHash)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.error "Request metadata pices: torrent data for torrent #{QuartzTorrent.bytesToHex(infoHash)} not found."
return
end
return if torrentData.paused || torrentData.queued
... | ruby | {
"resource": ""
} |
q2220 | QuartzTorrent.PeerClientHandler.withPeersIo | train | def withPeersIo(peer, what = nil)
io = findIoByMetainfo(peer)
if io
yield io
else
s = ""
s = "when #{what}" if what
@logger.warn "Couldn't find the io for peer #{peer} #{what}"
end
end | ruby | {
"resource": ""
} |
q2221 | QuartzTorrent.PeerClientHandler.getPeersFromTracker | train | def getPeersFromTracker(torrentData, infoHash)
addPeer = Proc.new do |trackerPeer|
peer = Peer.new(trackerPeer)
peer.infoHash = infoHash
torrentData.peers.add peer
true
end
classifiedPeers = nil
replaceDisconnectedPeer = Proc.new do |trackerPeer|
classifi... | ruby | {
"resource": ""
} |
q2222 | QuartzTorrent.PeerClientHandler.handleRemoveTorrent | train | def handleRemoveTorrent(infoHash, deleteFiles)
torrentData = @torrentData.delete infoHash
if ! torrentData
@logger.warn "Asked to remove a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
@logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Remov... | ruby | {
"resource": ""
} |
q2223 | QuartzTorrent.PeerClientHandler.handlePause | train | def handlePause(infoHash, value)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to pause a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
return if torrentData.paused == value
torrentData.paused = value
if !value
... | ruby | {
"resource": ""
} |
q2224 | QuartzTorrent.PeerClientHandler.queue | train | def queue(torrentData, mode = :queue)
return if torrentData.queued
# Queue the torrent
if mode == :unshift
@torrentQueue.unshift torrentData
else
@torrentQueue.push torrentData
end
setFrozen torrentData, true if ! torrentData.paused
end | ruby | {
"resource": ""
} |
q2225 | QuartzTorrent.PeerClientHandler.dequeue | train | def dequeue
torrents = @torrentQueue.dequeue(@torrentData.values)
torrents.each do |torrentData|
if torrentData.state == :initializing
initTorrent torrentData
else
setFrozen torrentData, false if ! torrentData.paused
end
end
end | ruby | {
"resource": ""
} |
q2226 | QuartzTorrent.PeerClientHandler.setFrozen | train | def setFrozen(torrent, value)
torrentData = torrent
if ! torrent.is_a?(TorrentData)
torrentData = @torrentData[torrent]
if ! torrentData
@logger.warn "Asked to freeze a non-existent torrent #{QuartzTorrent.bytesToHex(torrent)}"
return
end
end
if value... | ruby | {
"resource": ""
} |
q2227 | QuartzTorrent.PeerClient.addTorrentByMetainfo | train | def addTorrentByMetainfo(metainfo)
raise "addTorrentByMetainfo should be called with a Metainfo object, not #{metainfo.class}" if ! metainfo.is_a?(Metainfo)
trackerclient = TrackerClient.createFromMetainfo(metainfo, false)
addTorrent(trackerclient, metainfo.infoHash, metainfo.info)
end | ruby | {
"resource": ""
} |
q2228 | QuartzTorrent.PeerClient.addTorrentWithoutMetainfo | train | def addTorrentWithoutMetainfo(announceUrl, infoHash, magnet = nil)
raise "addTorrentWithoutMetainfo should be called with a Magnet object, not a #{magnet.class}" if magnet && ! magnet.is_a?(MagnetURI)
trackerclient = TrackerClient.create(announceUrl, infoHash, 0, false)
addTorrent(trackerclient, infoH... | ruby | {
"resource": ""
} |
q2229 | QuartzTorrent.PeerClient.addTorrentByMagnetURI | train | def addTorrentByMagnetURI(magnet)
raise "addTorrentByMagnetURI should be called with a MagnetURI object, not a #{magnet.class}" if ! magnet.is_a?(MagnetURI)
trackerUrl = magnet.trackers
raise "addTorrentByMagnetURI can't handle magnet links that don't have a tracker URL." if !trackerUrl
addTor... | ruby | {
"resource": ""
} |
q2230 | QuartzTorrent.PeerClient.adjustBytesDownloaded | train | def adjustBytesDownloaded(infoHash, adjustment)
return if ! adjustment
raise "Bytes downloaded adjustment must be an Integer, not a #{adjustment.class}" if !adjustment.is_a?(Integer)
@handler.adjustBytesDownloaded(infoHash, adjustment)
end | ruby | {
"resource": ""
} |
q2231 | QuartzTorrent.PeerClient.addTorrent | train | def addTorrent(trackerclient, infoHash, info, magnet = nil)
trackerclient.port = @port
torrentData = @handler.addTrackerClient(infoHash, info, trackerclient)
torrentData.magnet = magnet
trackerclient.dynamicRequestParamsBuilder = Proc.new do
torrentData = @handler.torrentData[infoHash]... | ruby | {
"resource": ""
} |
q2232 | Rapidoc.Config.target_dir | train | def target_dir( f = nil )
if File.exists?( config_file_path )
form_file_name( target_dir_from_config, f )
else
form_file_name( File.join( ::Rails.root.to_s, 'public/docs' ), f )
end
end | ruby | {
"resource": ""
} |
q2233 | Rapidoc.Config.examples_dir | train | def examples_dir( f = nil )
if File.exists?( config_file_path )
form_file_name( examples_dir_from_config_file, f )
else
form_file_name( config_dir( '/examples' ), f )
end
end | ruby | {
"resource": ""
} |
q2234 | Twilio.Verb.say | train | def say(*args)
options = {:voice => 'man', :language => 'en', :loop => 1}
args.each do |arg|
case arg
when String
options[:text_to_speak] = arg
when Hash
options.merge!(arg)
else
raise ArgumentError, 'say expects String or Hash argument'
... | ruby | {
"resource": ""
} |
q2235 | Twilio.Verb.gather | train | def gather(*args, &block)
options = args.shift || {}
output {
if block_given?
@xml.Gather(options) { block.call}
else
@xml.Gather(options)
end
}
end | ruby | {
"resource": ""
} |
q2236 | Twilio.Verb.dial | train | def dial(*args, &block)
number_to_dial = ''
options = {}
args.each do |arg|
case arg
when String
number_to_dial = arg
when Hash
options.merge!(arg)
else
raise ArgumentError, 'dial expects String or Hash argument'
end
end
... | ruby | {
"resource": ""
} |
q2237 | Rapidoc.ResourceDoc.generate_info | train | def generate_info( routes_info )
if routes_info
extractor = get_controller_extractor
@description = extractor.get_resource_info['description'] if extractor
@actions_doc = get_actions_doc( routes_info, extractor )
# template need that description will be an array
@descript... | ruby | {
"resource": ""
} |
q2238 | QuartzTorrent.PieceMapper.findBlock | train | def findBlock(pieceIndex, offset, length)
leftOffset = @pieceSize*pieceIndex + offset
rightOffset = leftOffset + length-1
findPart(leftOffset, rightOffset)
end | ruby | {
"resource": ""
} |
q2239 | QuartzTorrent.PieceIO.writeBlock | train | def writeBlock(pieceIndex, offset, block)
regions = @pieceMapper.findBlock(pieceIndex, offset, block.length)
indexInBlock = 0
regions.each do |region|
# Get the IO for the file with path 'path'. If we are being used in a reactor, this is the IO facade. If we
# are not then this is a re... | ruby | {
"resource": ""
} |
q2240 | QuartzTorrent.PieceIO.readRegions | train | def readRegions(regions)
piece = ""
regions.each do |region|
# Get the IO for the file with path 'path'. If we are being used in a reactor, this is the IO facade. If we
# are not then this is a real IO.
io = @ioManager.get(region.path)
if ! io
# No IO for this file.... | ruby | {
"resource": ""
} |
q2241 | QuartzTorrent.PieceManager.readBlock | train | def readBlock(pieceIndex, offset, length)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :read_block, pieceIndex, offset, length]
@requestsSemaphore.signal
id
end | ruby | {
"resource": ""
} |
q2242 | QuartzTorrent.PieceManager.writeBlock | train | def writeBlock(pieceIndex, offset, block)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :write_block, pieceIndex, offset, block]
@requestsSemaphore.signal
id
end | ruby | {
"resource": ""
} |
q2243 | QuartzTorrent.PieceManager.readPiece | train | def readPiece(pieceIndex)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :read_piece, pieceIndex]
@requestsSemaphore.signal
id
end | ruby | {
"resource": ""
} |
q2244 | QuartzTorrent.PieceManager.checkPieceHash | train | def checkPieceHash(pieceIndex)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :hash_piece, pieceIndex]
@requestsSemaphore.signal
id
end | ruby | {
"resource": ""
} |
q2245 | Halite.Gem.license_header | train | def license_header
IO.readlines(spec_file).take_while { |line| line.strip.empty? || line.strip.start_with?('#') }.join('')
end | ruby | {
"resource": ""
} |
q2246 | Halite.Gem.issues_url | train | def issues_url
if spec.metadata['issues_url']
spec.metadata['issues_url']
elsif spec.homepage =~ /^http(s)?:\/\/(www\.)?github\.com/
spec.homepage.chomp('/') + '/issues'
end
end | ruby | {
"resource": ""
} |
q2247 | Halite.Gem.platforms | train | def platforms
raw_platforms = spec.metadata.fetch('platforms', '').strip
case raw_platforms
when ''
[]
when 'any', 'all', '*'
# Based on `ls lib/fauxhai/platforms | xargs echo`.
%w{aix amazon arch centos chefspec debian dragonfly4 fedora freebsd gentoo
ios_xr ... | ruby | {
"resource": ""
} |
q2248 | Halite.Gem.find_misc_path | train | def find_misc_path(name)
[name, name.upcase, name.downcase].each do |base|
['.md', '', '.txt', '.html'].each do |suffix|
path = File.join(spec.full_gem_path, base+suffix)
return path if File.exist?(path) && Dir.entries(File.dirname(path)).include?(File.basename(path))
end
... | ruby | {
"resource": ""
} |
q2249 | Halite.Gem.dependency_to_spec | train | def dependency_to_spec(dep)
# #to_spec doesn't allow prereleases unless the requirement is
# for a prerelease. Just use the last valid spec if possible.
spec = dep.to_spec || dep.to_specs.last
raise Error.new("Cannot find a gem to satisfy #{dep}") unless spec
spec
rescue ::Gem::LoadErr... | ruby | {
"resource": ""
} |
q2250 | RRD.Base.resize | train | def resize(rra_num, options)
info = self.info
step = info["step"]
rra_step = info["rra[#{rra_num}].pdp_per_row"]
action = options.keys.first.to_s.upcase
delta = (options.values.first / (step * rra_step)).to_i # Force an integer
Wrapper.resize(rrd_file, rra_num.to_s, action, delta.to_... | ruby | {
"resource": ""
} |
q2251 | Berkshelf.GemLocation.install | train | def install
cache_path.rmtree if cache_path.exist?
cache_path.mkpath
Halite.convert(gem_name, cache_path)
validate_cached!(cache_path)
end | ruby | {
"resource": ""
} |
q2252 | QuartzTorrent.PeerHolder.add | train | def add(peer)
raise "Peer must have it's infoHash set." if ! peer.infoHash
# Do not add if peer is already present by address
if @peersByAddr.has_key?(byAddrKey(peer))
@log.debug "Not adding peer #{peer} since it already exists by #{@peersById.has_key?(peer.trackerPeer.id) ? "id" : "addr"}."
... | ruby | {
"resource": ""
} |
q2253 | QuartzTorrent.PeerHolder.idSet | train | def idSet(peer)
@peersById.each do |e|
return if e.eql?(peer)
end
@peersById.pushToList(peer.trackerPeer.id, peer)
end | ruby | {
"resource": ""
} |
q2254 | QuartzTorrent.PeerHolder.delete | train | def delete(peer)
@peersByAddr.delete byAddrKey(peer)
list = @peersByInfoHash[peer.infoHash]
if list
list.collect! do |p|
if !p.eql?(peer)
peer
else
nil
end
end
list.compact!
end
if peer.trackerPeer.id
l... | ruby | {
"resource": ""
} |
q2255 | QuartzTorrent.PeerHolder.to_s | train | def to_s(infoHash = nil)
def makeFlags(peer)
s = "["
s << "c" if peer.amChoked
s << "i" if peer.peerInterested
s << "C" if peer.peerChoked
s << "I" if peer.amInterested
s << "]"
s
end
if infoHash
s = "Peers: \n"
peers = @peer... | ruby | {
"resource": ""
} |
q2256 | QuartzTorrent.MagnetURI.btInfoHash | train | def btInfoHash
result = nil
@params['xt'].each do |topic|
if topic =~ /urn:btih:(.*)/
hash = $1
if hash.length == 40
# Hex-encoded info hash. Convert to binary.
result = [hash].pack "H*"
else
# Base32 encoded
result = Bas... | ruby | {
"resource": ""
} |
q2257 | Rapidoc.ResourcesExtractor.get_routes_doc | train | def get_routes_doc
puts "Executing 'rake routes'..." if trace?
routes_doc = RoutesDoc.new
routes = Dir.chdir( ::Rails.root.to_s ) { `rake routes` }
routes.split("\n").each do |entry|
routes_doc.add_route( entry ) unless entry.match(/URI/)
end
routes_doc
end | ruby | {
"resource": ""
} |
q2258 | Rapidoc.ResourcesExtractor.get_resources | train | def get_resources
routes_doc = get_routes_doc
resources_names = routes_doc.get_resources_names - resources_black_list
resources_names.map do |resource|
puts "Generating #{resource} documentation..." if trace?
ResourceDoc.new( resource, routes_doc.get_actions_route_info( resource ) )
... | ruby | {
"resource": ""
} |
q2259 | Cleanroom.ClassMethods.evaluate_file | train | def evaluate_file(instance, filepath)
absolute_path = File.expand_path(filepath)
file_contents = IO.read(absolute_path)
evaluate(instance, file_contents, absolute_path, 1)
end | ruby | {
"resource": ""
} |
q2260 | Cleanroom.ClassMethods.evaluate | train | def evaluate(instance, *args, &block)
cleanroom.new(instance).instance_eval(*args, &block)
end | ruby | {
"resource": ""
} |
q2261 | Cleanroom.ClassMethods.cleanroom | train | def cleanroom
exposed = exposed_methods.keys
parent = self.name || 'Anonymous'
Class.new(Object) do
class << self
def class_eval
raise Cleanroom::InaccessibleError.new(:class_eval, self)
end
def instance_eval
raise Cleanroom::Inaccessible... | ruby | {
"resource": ""
} |
q2262 | Rapidoc.RoutesDoc.add_resource_route | train | def add_resource_route( method, url, controller_action )
#resource = get_resource_name( url )
resource = controller_action.split('#').first
info = {
resource: resource,
action: controller_action.split('#').last,
method: method,
url: url ,
controller: controller... | ruby | {
"resource": ""
} |
q2263 | Rapidoc.RoutesDoc.get_resource_name | train | def get_resource_name( url )
new_url = url.gsub( '(.:format)', '' )
return $1 if new_url =~ /\/(\w+)\/:id$/ # /users/:id (users)
return $1 if new_url =~ /\/(\w+)\/:id\/edit$/ # /users/:id/edit (users)
return $1 if new_url =~ /^\/(\w+)$/ # /users (users)
return $1 if... | ruby | {
"resource": ""
} |
q2264 | QuartzTorrent.PeerWireMessageSerializer.classForMessage | train | def classForMessage(id, payload)
if @@classForMessage.nil?
@@classForMessage = [Choke, Unchoke, Interested, Uninterested, Have, BitfieldMessage, Request, Piece, Cancel]
@@classForMessage[20] = Extended
end
if @@classForExtendedMessage.nil?
@@classForExtendedMessage = []
... | ruby | {
"resource": ""
} |
q2265 | QuartzTorrent.BlockInfo.getRequest | train | def getRequest
m = Request.new
m.pieceIndex = @pieceIndex
m.blockOffset = @offset
m.blockLength = @length
m
end | ruby | {
"resource": ""
} |
q2266 | QuartzTorrent.BlockState.findRequestableBlocks | train | def findRequestableBlocks(classifiedPeers, numToReturn = nil)
# Have a list of the current pieces we are working on. Each time this method is
# called, check the blocks in the pieces in list order to find the blocks to return
# for requesting. If a piece is completed, remove it from this list. If we ... | ruby | {
"resource": ""
} |
q2267 | QuartzTorrent.BlockState.setBlockRequested | train | def setBlockRequested(blockInfo, bool)
if bool
@requestedBlocks.set blockInfo.blockIndex
else
@requestedBlocks.clear blockInfo.blockIndex
end
end | ruby | {
"resource": ""
} |
q2268 | QuartzTorrent.BlockState.setPieceCompleted | train | def setPieceCompleted(pieceIndex, bool)
eachBlockInPiece(pieceIndex) do |blockIndex|
if bool
@completeBlocks.set blockIndex
else
@completeBlocks.clear blockIndex
end
end
if bool
@completePieces.set pieceIndex
else
@completePieces.clear ... | ruby | {
"resource": ""
} |
q2269 | QuartzTorrent.BlockState.completedLength | train | def completedLength
num = @completeBlocks.countSet
# Last block may be smaller
extra = 0
if @completeBlocks.set?(@completeBlocks.length-1)
num -= 1
extra = @lastBlockLength
end
num*@blockSize + extra
end | ruby | {
"resource": ""
} |
q2270 | QuartzTorrent.BlockState.createBlockinfoByPieceAndBlockIndex | train | def createBlockinfoByPieceAndBlockIndex(pieceIndex, peersWithPiece, blockIndex)
# If this is the very last block, then it might be smaller than the rest.
blockSize = @blockSize
blockSize = @lastBlockLength if blockIndex == @numBlocks-1
offsetWithinPiece = (blockIndex % @blocksPerPiece)*@blockSiz... | ruby | {
"resource": ""
} |
q2271 | QuartzTorrent.BlockState.computePeersHavingPiece | train | def computePeersHavingPiece(classifiedPeers)
# Make a list of each peer having the specified piece
peersHavingPiece = Array.new(@numPieces)
# This first list represents rarity by number if peers having that piece. 1 = rarest.
classifiedPeers.requestablePeers.each do |peer|
@numPieces.tim... | ruby | {
"resource": ""
} |
q2272 | QuartzTorrent.RegionMap.findValue | train | def findValue(value)
if ! @sorted
@map.sort{ |a,b| a[0] <=> b[0] }
@sorted = true
end
@map.binsearch{|x| x[0] >= value}[1]
end | ruby | {
"resource": ""
} |
q2273 | Rapidoc.YamlParser.extract_resource_info | train | def extract_resource_info( lines, blocks, file_name )
blocks ? info = [] : blocks = []
blocks.each.map do |b|
if lines[ b[:init] ].include? "=begin resource"
n_lines = b[:end] - b[:init] - 1
begin
info.push YAML.load( lines[ b[:init] +1, n_lines ].join.gsub(/\ *#/, ''... | ruby | {
"resource": ""
} |
q2274 | Rapidoc.YamlParser.extract_actions_info | train | def extract_actions_info( lines, blocks, file_name )
info = []
blocks = [] unless blocks
blocks.each do |b|
if lines[ b[:init] ].include? "=begin action"
n_lines = b[:end] - b[:init] - 1
begin
info << YAML.load( lines[ b[:init] + 1, n_lines ].join.gsub(/\ *#/,... | ruby | {
"resource": ""
} |
q2275 | Twilio.IncomingPhoneNumber.create | train | def create(opts)
raise "You must set either :PhoneNumber or :AreaCode" if !opts.include?(:AreaCode) && !opts.include?(:PhoneNumber)
Twilio.post("/IncomingPhoneNumbers", :body => opts)
end | ruby | {
"resource": ""
} |
q2276 | QuartzTorrent.MemProfiler.getCounts | train | def getCounts
result = {}
@classes.each do |c|
count = 0
ObjectSpace.each_object(c){ count += 1 }
result[c] = count
end
result
end | ruby | {
"resource": ""
} |
q2277 | I18nDocs.MissingKeysFinder.all_keys | train | def all_keys
I18n.backend.send(:translations).collect do |_check_locale, translations|
collect_keys([], translations).sort
end.flatten.uniq
end | ruby | {
"resource": ""
} |
q2278 | I18nDocs.MissingKeysFinder.key_exists? | train | def key_exists?(key, locale)
I18n.locale = locale
I18n.translate(key, raise: true)
return true
rescue I18n::MissingInterpolationArgument
return true
rescue I18n::MissingTranslationData
return false
end | ruby | {
"resource": ""
} |
q2279 | QuartzTorrent.PeerHandshake.serializeTo | train | def serializeTo(io)
raise "PeerId is not set" if ! @peerId
raise "InfoHash is not set" if ! @infoHash
result = [ProtocolName.length].pack("C")
result << ProtocolName
result << [0,0,0,0,0,0x10,0,0].pack("C8") # Reserved. 0x10 means we support extensions (BEP 10).
result << @infoHash
... | ruby | {
"resource": ""
} |
q2280 | QuartzTorrent.TrackerClient.start | train | def start
@stopped = false
return if @started
@started = true
@worker = Thread.new do
QuartzTorrent.initThread("trackerclient")
@logger.info "Worker thread starting"
@event = :started
trackerInterval = nil
while ! @stopped
begin
respo... | ruby | {
"resource": ""
} |
q2281 | QuartzTorrent.Bitfield.length= | train | def length=(l)
byteLen = 0
byteLen = (l-1)/8+1 if l > 0
raise "Length adjustment would change size of underlying array" if byteLen != byteLength
@length = l
end | ruby | {
"resource": ""
} |
q2282 | QuartzTorrent.Bitfield.set | train | def set(bit)
quotient = bit >> 3
remainder = bit & 0x7
mask = 0x80 >> remainder
raise "Bit #{bit} out of range of bitfield with length #{length}" if quotient >= @data.length
@data[quotient] |= mask
end | ruby | {
"resource": ""
} |
q2283 | QuartzTorrent.Bitfield.clear | train | def clear(bit)
quotient = bit >> 3
remainder = bit & 0x7
mask = ~(0x80 >> remainder)
raise "Bit #{bit} out of range of bitfield with length #{length}" if quotient >= @data.length
@data[quotient] &= mask
end | ruby | {
"resource": ""
} |
q2284 | QuartzTorrent.Bitfield.allSet? | train | def allSet?
# Check all but last byte quickly
(@data.length-1).times do |i|
return false if @data[i] != 0xff
end
# Check last byte slowly
toCheck = @length % 8
toCheck = 8 if toCheck == 0
((@length-toCheck)..(@length-1)).each do |i|
return false if ! set?(i)
... | ruby | {
"resource": ""
} |
q2285 | QuartzTorrent.Bitfield.union | train | def union(bitfield)
raise "That's not a bitfield" if ! bitfield.is_a?(Bitfield)
raise "bitfield lengths must be equal" if ! bitfield.length == length
result = Bitfield.new(length)
(@data.length).times do |i|
result.data[i] = @data[i] | bitfield.data[i]
end
result
end | ruby | {
"resource": ""
} |
q2286 | QuartzTorrent.Bitfield.intersection | train | def intersection(bitfield)
raise "That's not a bitfield" if ! bitfield.is_a?(Bitfield)
raise "bitfield lengths must be equal" if ! bitfield.length == length
newbitfield = Bitfield.new(length)
newbitfield.copyFrom(self)
newbitfield.intersection!(bitfield)
end | ruby | {
"resource": ""
} |
q2287 | QuartzTorrent.Bitfield.intersection! | train | def intersection!(bitfield)
raise "That's not a bitfield" if ! bitfield.is_a?(Bitfield)
raise "bitfield lengths must be equal" if ! bitfield.length == length
(@data.length).times do |i|
@data[i] = @data[i] & bitfield.data[i]
end
self
end | ruby | {
"resource": ""
} |
q2288 | QuartzTorrent.Bitfield.copyFrom | train | def copyFrom(bitfield)
raise "Source bitfield is too small (#{bitfield.length} < #{length})" if bitfield.length < length
(@data.length).times do |i|
@data[i] = bitfield.data[i]
end
end | ruby | {
"resource": ""
} |
q2289 | QuartzTorrent.Bitfield.to_s | train | def to_s(groupsOf = 8)
groupsOf = 8 if groupsOf == 0
s = ""
length.times do |i|
s << (set?(i) ? "1" : "0")
s << " " if i % groupsOf == 0
end
s
end | ruby | {
"resource": ""
} |
q2290 | QuartzTorrent.Peer.updateUploadRate | train | def updateUploadRate(msg)
@uploadRate.update msg.length
if msg.is_a? Piece
@uploadRateDataOnly.update msg.data.length
end
end | ruby | {
"resource": ""
} |
q2291 | QuartzTorrent.Peer.updateDownloadRate | train | def updateDownloadRate(msg)
@downloadRate.update msg.length
if msg.is_a? Piece
@downloadRateDataOnly.update msg.data.length
end
end | ruby | {
"resource": ""
} |
q2292 | Cloudconvert.Conversion.convert | train | def convert(inputformat, outputformat, file_path, callback_url = nil, options = {})
raise "File path cant be blank" if file_path.nil?
@convert_request_url = start_conversion(inputformat, outputformat)
#initiate connection with new response host
initiate_connection(@convert_request_url)
upl... | ruby | {
"resource": ""
} |
q2293 | Cloudconvert.Conversion.converter_options | train | def converter_options(inputformat ="", outputformat = "")
response = @conversion_connection.get "conversiontypes", {:inputformat => inputformat,:outputformat => outputformat }
parse_response(response.body)
end | ruby | {
"resource": ""
} |
q2294 | Cloudconvert.Conversion.build_upload_params | train | def build_upload_params(file_path, outputformat, callback_url = nil, options = {})
upload_params = { :format => outputformat}
upload_params.merge!(:callback => callback(callback_url)) if callback(callback_url).present?
upload_params.merge!(:input => "download",:link => file_path )
upload_params.... | ruby | {
"resource": ""
} |
q2295 | Gravatarify.Helper.gravatar_attrs | train | def gravatar_attrs(email, *params)
url_options = Gravatarify::Utils.merge_gravatar_options(*params)
options = url_options[:html] || {}
options[:src] = gravatar_url(email, false, url_options)
options[:width] = options[:height] = (url_options[:size] || 80) # customize size
{ :alt => '' }... | ruby | {
"resource": ""
} |
q2296 | GemUpdater.GemFile.compute_changes | train | def compute_changes
spec_sets_diff!
old_spec_set.each do |old_gem|
updated_gem = new_spec_set.find { |new_gem| new_gem.name == old_gem.name }
next unless updated_gem && old_gem.version != updated_gem.version
fill_changes(old_gem, updated_gem)
end
end | ruby | {
"resource": ""
} |
q2297 | GemUpdater.GemFile.fill_changes | train | def fill_changes(old_gem, updated_gem)
changes[old_gem.name] = {
versions: {
old: old_gem.version.to_s, new: updated_gem.version.to_s
},
source: updated_gem.source
}
end | ruby | {
"resource": ""
} |
q2298 | BERTRPC.Action.connect_to | train | def connect_to(host, port, timeout = nil)
timeout = timeout && Float(timeout)
addr = Socket.getaddrinfo(host, nil, Socket::AF_INET)
sock = Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0)
sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
if timeout
secs =... | ruby | {
"resource": ""
} |
q2299 | Nexus.Cache.prune_cache | train | def prune_cache(mtime=15)
# get old, unused entries and discard from DB and filesystem
entries = remove_old_items(mtime)
entries.each do |key, entry|
FileUtils.rm_f(entry[:file])
end
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.