This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'gruff' | |
require 'csv' | |
ndx = [] | |
tv_data = [] | |
radio_data = [] | |
newspaper_data = [] | |
sales_data = [] | |
CSV.foreach('../data/Advertising.csv', :headers => true) do |row| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
end_value = 120 | |
#-- Using mod | |
a = Array(2..end_value) | |
limit = Math.sqrt end_value | |
a.each do |x| | |
a.delete_if do |y| | |
next if y <= x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
end_value = 120 | |
#-- Without using mod | |
b = Array(2..end_value) | |
primes = Array(2..end_value) | |
limit = Math.sqrt end_value | |
b.each do |z| | |
break if z >= limit | |
primes.each do |i| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gcd ab, cd | |
return ab if cd == 0 | |
r = ab % cd | |
gcd cd, r | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binary_search x, low = 0, high = -1 | |
#-- Assume that a is already sorted | |
a = [3, 5, 7, 8, 10, 11, 14, 15, 26, 33, 34, 36, 39, 40, 41, 44, 45, 48, 49] | |
high = a.length - 1 if high == -1 | |
midpoint = (high + low) / 2 | |
if low == midpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kafka import * | |
mykafka = KafkaClient("localhost:9092") | |
producer = SimpleProducer(mykafka) | |
producer.send_messages("test", "mymessage") | |
producer.send_messages("test", "mymessage 2") | |
producer.send_messages("test", "mymessage 3") | |
producer.send_messages("test", "mymessage 4") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Bind the maven-assembly-plugin to the package phase | |
this will create a jar file without the storm dependencies | |
suitable for deployment to a cluster. | |
--> | |
<plugin> | |
<artifactId>maven-assembly-plugin</artifactId> | |
<configuration> | |
<descriptorRefs> | |
<descriptorRef>jar-with-dependencies</descriptorRef> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Hello, world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'spec_helper' | |
describe "Test JSON response" do | |
before :all do | |
host = http://localhost:3000 | |
@url = "api/v1/foobar" | |
headers = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack | |
attr_reader :length, :stack | |
def initialize(size=1) | |
@stack = Array.new(size) | |
@length = 0 | |
end | |
def is_empty? |
OlderNewer