Skip to content

Instantly share code, notes, and snippets.

View blurredbits's full-sized avatar

Mark Morris blurredbits

View GitHub Profile
@blurredbits
blurredbits / Roman Numeral
Created March 13, 2014 02:01
Roman Numeral Generator - J. Weirich edition.
puts "Please enter a number you would like to convert to a roman numeral"
num = gets.chomp.to_i
def to_roman(num)
results = ""
digits = [
[1000, "M"],
[900, "CM"],
[500, "D"],
@blurredbits
blurredbits / guessing_game
Created March 13, 2014 02:55
Guessing Game
puts "Let's play a guessing game. "
puts "I'll pick a number from 1 to 20. You try to guess it."
puts "Please enter a number: "
answer = 1 + rand(19)
number_of_guesses = 0
begin
guess = gets.chomp.to_i
if guess < answer
@blurredbits
blurredbits / student.js
Created January 3, 2015 04:10
JS Group Week #1
validate('first_name', 'email', 'dream', 'password', 'password_confirm', function(value) {
if (this.is_empty(value)) {
return "Cannot be empty";
}
return true;
})
validate('form', function(elements) {
if (elements['first_name'].value == elements['last_name'].value) {

Keybase proof

I hereby claim:

  • I am blurredbits on github.
  • I am blurredbits (https://keybase.io/blurredbits) on keybase.
  • I have a public key whose fingerprint is E089 8BC5 353D 1E11 4AFB DF15 AE8B 21F9 6723 91E2

To claim this, I am signing this object:

@blurredbits
blurredbits / producer.rb
Created June 30, 2015 18:28
Kafka Producer Example
#!/usr/bin/env ruby
require 'poseidon'
producer = Poseidon::Producer.new(["localhost:9092"], "test_producer")
loop do
messages = []
messages << Poseidon::MessageToSend.new("metrics", "timestamp: #{Time.now.to_i}, metric: #{rand(10..30)}")
producer.send_messages(messages)
@blurredbits
blurredbits / mongo_consumer.rb
Last active August 29, 2015 14:24
Kafka Mongo Consumer
#!/usr/bin/env ruby
require 'poseidon'
require 'mongo'
Mongo::Logger.logger.level = Logger::WARN
db = Mongo::Client.new(['127.0.0.1:27017'], database: 'metrics')
consumer = Poseidon::PartitionConsumer.new("mongo_consumer", "localhost", 9092, "metrics", 0, :earliest_offset)
@blurredbits
blurredbits / docker_commands
Last active August 29, 2015 14:24
Kafka Docker Commands
docker run -d \
--name zookeeper \
--publish 2181:2181 \
jplock/zookeeper:3.4.6
docker run -d \
--name kafka \
--link zookeeper:zookeeper \
--publish 9092:9092 --publish 7203:7203 \
--env EXPOSED_HOST=127.0.0.1 --env ZOOKEEPER_IP=127.0.0.1 \
@blurredbits
blurredbits / statsd_timer_example.rb
Created July 31, 2015 18:13
Sample for code for StatsD Timer
require 'statsd-ruby'
statsd = Statsd.new('localhost', 8125)
# Single call to statsd timer.
statsd.time("timer_data") do
timer_data = 1 + Random.rand(6)
puts timer_data
sleep timer_data
end
@blurredbits
blurredbits / gist:4106586
Created November 18, 2012 18:07 — forked from padolsey/gist:527683
JavaScript: Detect IE
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@blurredbits
blurredbits / zoo.js
Last active December 18, 2015 11:09 — forked from dbc-challenges/zoo.js
Didn't get this one - not working.
//------------------------------------------------------------------------------------------------------------------
// YOUR CODE: Create your Zoo "object literal" and Animal "constructor" and "prototypes" here.
//------------------------------------------------------------------------------------------------------------------
Zoo = {
init: function(animals) {
Zoo = new Array(animals);
}
};