Skip to content

Instantly share code, notes, and snippets.

View danhealy's full-sized avatar

Dan Healy danhealy

View GitHub Profile
@danhealy
danhealy / serializable.rb
Last active May 10, 2021 22:36
Automatically serialize a DragonRuby GTK class based on ivars
# Throw this file into your app folder, like app/lib/serializable.rb
#
# In your main.rb or wherever you require files:
# require 'app/lib/serializable.rb'
#
# In each class you want to automatically serialize:
# class Foo
# include Serializable
# ...
# end
@danhealy
danhealy / 00_log_parser_example_readme.md
Last active January 2, 2019 18:05
Given a log file, find the top consecutive visiting patterns

Code Sample - Log Parsing

I created this code sample in December, 2018 for an interview. The task is to parse a log file containing the following format:

<#>, C<#>, P<#>

Where the first number is a "timestamp," the second is a Client/Customer ID #, and the third is a Page #. The entry represents a customer visiting a specific page at a specific time.

It's assumed that the log file contains timestamps in ascending order.

@danhealy
danhealy / average_array_remove_outliers.rb
Last active January 2, 2019 17:17
Average of an array, and removing outliers
# Initialize an array of 50 random integers. If you know ahead of time that the
# elements will be unique, use Set class instead for performance improvements
array = Array.new(50) do rand(100) end
# Ruby 2.4 and later has the Array#sum method which could also be implemented as
# a simple #inject call in earlier versions, it's also mixed in with Rails
avg = array.sum / array.length.to_f # to_f required for float precision
# Removing the min and max of the array by sorting. This particular method
@danhealy
danhealy / genesis_public_key
Last active March 3, 2018 00:52
genesis_public_key
04714a3cc0a7adb56767f592a79c5c74b83e8ed6f4cf26831a5c5f0d07b54ac28d7fe519dd3350894abc4b29d57eb60a8b3609aac96e095ba384d556bfa7d22377;TheCrow1213
@danhealy
danhealy / gist:308e7d0b3906741cf50661a1f2d4a825
Last active October 6, 2016 06:11
rubymotion motion-game create sprite from image data
diff --git a/src/sprite.cpp b/src/sprite.cpp
index 450e5f4..f3320c8 100644
--- a/src/sprite.cpp
+++ b/src/sprite.cpp
@@ -54,6 +54,25 @@ sprite_new(VALUE rcv, SEL sel, VALUE name)
return rb_class_wrap_new((void *)sprite, rcv);
}
+/// @method #create_with_image(data, len)
+/// Creates a sprite from +data+ stream buffer image data and +len+ length
@danhealy
danhealy / gist:92c8b236c1c53a18c535
Last active May 22, 2018 18:20
Parallel DynamoDB Scan
batch_size = 100 # Items per request
parallel_requests = 4
total_items_to_request = 4000
iterations = (total_items_to_request / (parallel_requests * batch_size)) # => 10
parallel_requests.times do |seg|
Process.fork do
c = AWS::DynamoDB::Client.new(
:access_key_id => "...",
@danhealy
danhealy / gist:7133303
Created October 24, 2013 08:29
Count duplicate lines in a git repo
#!/usr/bin/env ruby
class Array
def sum
inject(0.0) { |result, el| result + el }
end
def mean
sum / size
end
@danhealy
danhealy / Gemfile
Created December 31, 2011 23:26
Error with Goliath & BarrierAroundware
source :rubygems
gem "eventmachine", ">= 1.0.0.beta.3"
gem 'goliath', :git => 'git://github.com/postrank-labs/goliath.git'
gem 'em-synchrony', :git => 'git://github.com/igrigorik/em-synchrony.git'
ruby-1.9.2-p290@sandbox @/sandbox [11:58:10] :) $ ab -n 100 -c 1 http://goliath-demo.herokuapp.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking goliath-demo.herokuapp.com (be patient).....done
Server Software: PostRank
Server Hostname: goliath-demo.herokuapp.com
@danhealy
danhealy / OpenFeintExtension.h
Created July 5, 2011 00:51
OpenFeint Rhodes Extension
// platform/iphone/OpenFeintExtension.h
#import "OpenFeint.h"
#import "OFAchievement.h"
#import "OFAchievementService.h"