Skip to content

Instantly share code, notes, and snippets.

@DouglasAllen
DouglasAllen / some_ruby_code.rb
Created March 3, 2012 13:53
Example of my challenge from readme @ myfirstapp
# Calculate current Julian Cycle
=begin
=end
# Approximate Solar Noon
=begin
=end
# Solar Mean Anomaly
=begin
=end
# Equation of Center
@DouglasAllen
DouglasAllen / otf_myotf01.ck
Created March 7, 2012 00:12
A modified example chuck script.
// terminal-2%> chuck + otf_01.ck
// (anytime later)
// terminal-2%> chuck + otf_02.ck
// (etc...)
//--------------------------------------|
// synchronize to period
.5::second => dur T;
T - (now % T) => now;
@DouglasAllen
DouglasAllen / p017leapyearmtd.rb
Created March 8, 2012 05:42
A simple example for using Date#leap?
# ruby p017leapyearmtd.rb
input_year = 1895
puts "The start year = #{input_year}"
require 'date'
year = input_year
while (year < 1910) do
date = Date.new(year)
@DouglasAllen
DouglasAllen / bdvar.rb
Created March 10, 2012 20:01
BigDecimal quick
# The majority of this code is taken right out of the BigDecimal class proof
# from http://www.ruby-doc.org/stdlib-1.9.3/
=begin
Decimal arithmetic is also useful for general
calculation, because it provides the correct
answers people expect-whereas normal binary
floating point arithmetic often introduces
subtle errors because of the conversion between
@DouglasAllen
DouglasAllen / rise_set.rb
Last active July 11, 2017 12:59
A sunrise, transit and equation of time using the wikipedia formula a bit simplified and in Ruby.
```code
# Usage
# Set your time zone offset at the line tz =....
# Mine is -5 hours use 5.5 if you're on a half hour offset.
# The latitude and longitude arguments are my coordinates.
# Yours are most likely different.
# If you are west of Greenwich meridian then use longitude negative.
# If you are south of the equator then use latitude negative.
@DouglasAllen
DouglasAllen / test_ajd.rb
Created March 16, 2012 01:18
A few solutions for Date#ajd not yielding rationals for display.
require 'date'
time = Time.now.utc
puts time
year = time.year
month = time.month
day = time.day
puts DateTime.new(year, month, day).ajd * 1.0
puts DateTime.new(year, month, day).ajd / 1.0
@DouglasAllen
DouglasAllen / try_RubySunrise_gem.rb
Created April 6, 2012 15:37
Ruby program to try the RubySunrise gem
require 'solareventcalculator'
timezone = "America/Chicago"
latitude = 41.9474
longitude = -88.74467
today = Time.now.utc
date = "#{today.year}-#{today.month}-#{today.day}"
date = Date.parse(date)
puts
puts "Timezone = #{timezone}"
@DouglasAllen
DouglasAllen / sidereal_clock.rb
Created April 14, 2012 05:25
Need Sidereal Time? My modified good-clock.rb for shoes
#
# Shoes Clock by Thomas Bell
# posted to the Shoes mailing list on 04 Dec 2007
#
# use http://www.celnav.de/longterm.htm to check it. Just pick a time enough ahead
# note GMST for that time then watch your clock.
require 'bigdecimal'
require 'date'
@DouglasAllen
DouglasAllen / shoes_clock.rb
Created April 17, 2012 17:49
The good_clock.rb shoes sample with a little tweak or two.
#
# Shoes Clock by Thomas Bell
# posted to the Shoes mailing list on 04 Dec 2007
#
require 'bigdecimal'
require 'date'
Shoes.app :height => 350, :width => 250, :title => "Sidereal Clock (GMST)" do
@radius, @centerx, @centery = 90, width / 2, height / 2
animate(24) do
@timenow = Time.now.utc
@DouglasAllen
DouglasAllen / Block_Redirection.rb
Created April 19, 2012 03:49
Trying to understand what http://shoesrb.com/manual/Rules.html is saying? Me too.
Shoes.app :title => "Block Redirection" do
stack do
para "First"
para "Second"
para "Third"
end
class Messenger
def initialize(stack)
@stack = stack