Skip to content

Instantly share code, notes, and snippets.

@adi89
adi89 / bellman.rb
Created November 20, 2018 19:07
bellman
VERTICIES = ["S","A", "B", "C", "D", "E"]
complete = false
MEMO = {
S: 0,
A: Float::INFINITY,
B: Float::INFINITY,
C: Float::INFINITY,
D: Float::INFINITY,
E: Float::INFINITY
@adi89
adi89 / sieve
Last active September 25, 2018 15:28
sieve
def sieve(n, p = 2, prime_list = [2], list_of_n = nil)
list_of_n ||= (2..n).to_a
list_of_n -= list_of_n.select {|i| i % p == 0 }
min = list_of_n.min
if min && (min > p) && (list_of_n.count > 1)
p = min
list_of_n.shift
prime_list.push(p)
{"masterDetails"=>{"indexSize"=>"242.2 MB", "indexPath"=>"/data/www/apps/platform-solr/solr/data/providers/index/, "isMaster"=>"true", "isSlave"=>"false", "indexVersion"=>1526657964636, "generation"=>108, "master"=>{"confFiles"=>"schema.xml,stopwords_en.txt,synonyms_en.txt,autocommit.xml,types.xml", "replicateAfter"=>["commit", "startup"], "replicationEnabled"=>"true", "replicableVersion"=>1526657964636, "replicableGeneration"=>108}}, "masterUrl"=>"", "pollInterval"=>"00:00:60", "nextExecutionAt"=>"Fri May 18 12:01:38 EDT 2018", "indexReplicatedAt"=>"Fri May 18 11:39:51 EDT 2018", "indexReplicatedAtList"=>["Fri May 18 11:39:51 EDT 2018", "Fri May 18 10:56:54 EDT 2018"], "timesIndexReplicated"=>"2", "lastCycleBytesDownloaded"=>"253961271", "previousCycleTimeInSeconds"=>"13", "currentDate"=>"Fri May 18 12:01:27 EDT 2018", "isPollingDisabled"=>"false", "isReplicating"=>"false"}
HTTParty.get("https://<endpt>/solr/#/providers/replication?command=details").parsed_response
=> "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n\n<!--\nLicensed to the Apache Software Foundation (ASF) under one or more\ncontributor license agreements. See the NOTICE file distributed with\nthis work for additional information regarding copyright ownership.\nThe ASF licenses this file to You under the Apache License, Version 2.0\n(the \"License\"); you may not use this file except in compliance with\nthe License. You may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n-->\n\n<head>\n \n <title>Solr Admin</ti
@adi89
adi89 / avg.rb
Last active August 29, 2015 14:11
#avg highest and lowest. take the highest and lowest out of array.
require 'pry-debugger'
require 'benchmark'
def special_avg(array)
array.sort!
array = remove_outliers(array)
val = array.reduce(:+) / (array.length)
return val
end
@adi89
adi89 / findConsecutiveRuns
Created November 25, 2014 07:17
Given an array of unsorted positive ints, write a function that finds runs of 3 consecutive numbers (ascending or descending) and returns the indices where such runs begin. If no such runs are found, return an empty array.
# jotted this quick
def consecutive(array)
index_collection = []
array.each_with_index do |integer, index|
if consecutive_forwards(array, integer, index) || consecutive_backwards(array, integer, index)
index_collection.push(index)
end
end
index_collection