Skip to content

Instantly share code, notes, and snippets.

require 'gruff'
require 'csv'
ndx = []
tv_data = []
radio_data = []
newspaper_data = []
sales_data = []
CSV.foreach('../data/Advertising.csv', :headers => true) do |row|
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
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|
def gcd ab, cd
return ab if cd == 0
r = ab % cd
gcd cd, r
end
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
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")
<!--
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>
puts "Hello, world!"
# encoding: utf-8
require 'spec_helper'
describe "Test JSON response" do
before :all do
host = http://localhost:3000
@url = "api/v1/foobar"
headers = {
@astronomy88
astronomy88 / stack.rb
Last active February 11, 2016 06:39
Implementing a Stack class using an Array
class Stack
attr_reader :length, :stack
def initialize(size=1)
@stack = Array.new(size)
@length = 0
end
def is_empty?