[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Any Muslims around?

Kyrre Nygård

8/14/2007 11:50:00 AM

Just wondering if any Muslims have gotten around to making a Ruby script
that like plays a sound or something when it's time for prayer.

Thanks,
Kyrre Nygård

6 Answers

Ronald Fischer

8/14/2007 12:16:00 PM

0

> Just wondering if any Muslims have gotten around to making a
> Ruby script
> that like plays a sound or something when it's time for prayer.

I guess time for prayer is at certain times per day? You could
get the current time with Time.now, then sleep the appropriate
time to the next prayer, and then wake up and to whatever you
would like to do.

Ronald

John Mettraux

8/14/2007 1:29:00 PM

0

On 8/14/07, Ronald Fischer <ronald.fischer@venyon.com> wrote:
> > Just wondering if any Muslims have gotten around to making a
> > Ruby script
> > that like plays a sound or something when it's time for prayer.
>
> I guess time for prayer is at certain times per day? You could
> get the current time with Time.now, then sleep the appropriate
> time to the next prayer, and then wake up and to whatever you
> would like to do.

Hi,

you could also have a look at :

http://openwferu.rubyforge.org/sche...


to install it :

sudo gem install openwferu-scheduler


then write a program that looks like :

---8<---

require 'rubygems'
require 'openwfe/util/scheduler'

include OpenWFE

scheduler = Scheduler.new
scheduler.start

scheduler.schedule("0 6 * * *") do
puts "time for the morning prayer"
end
scheduler.schedule("0 12 * * *") do
puts "time for the noon prayer"
end

# or

scheduler.schedule("0 6,8,12,16,18 * * *") do
puts "bismillah..."
end
--->8---

The scheduler follows the "cron" convention
(http://www.google.com/search?q=man%205...)

Maybe you're better off with a ruby program triggered by the cron in
your system (if it's a Unix / MacOSX one).


Best regards,

--
John Mettraux -///- http://jmettraux.o...

Ken Bloom

8/14/2007 2:32:00 PM

0

On Tue, 14 Aug 2007 20:50:02 +0900, Kyrre Nygård wrote:

> Just wondering if any Muslims have gotten around to making a Ruby script
> that like plays a sound or something when it's time for prayer.
>
> Thanks,
> Kyrre Nygård

Would this help? I use it as part of a suite of scripts for computing
times that Orthodox Jews use to compute times for prayer. The algorithm
comes from the US Naval Observatory's Almanac for Computers.

--Ken



require 'date'
require 'mathn'

#methods stolen from ruby-doc.org
class Date
def to_datetime() DateTime.new0(self.class.jd_to_ajd(jd, 0, 0), @of,
@sg) end
def to_date() self end
def to_time() Time.local(year, mon, mday) end
end
class DateTime
def to_date() Date.new0(self.class.jd_to_ajd(jd, 0, 0), 0, @sg) end
def to_datetime() self end
def to_time
d = new_offset(0)
d.instance_eval do
Time.utc(year, mon, mday, hour, min, sec,
(sec_fraction * 86400000000).to_i)
end.
getlocal
end
end

#end stolen

def dms(degrees,minutes,seconds)
degrees+minutes/60+seconds/60/60
end

module Sunrise
include Math
class Location
attr_accessor :latitude, :longitude, :offset
def initialize(latitude,longitude)
@latitude,@longitude=latitude,longitude
end
end

def toRad(degrees)
degrees*PI/180
end

def toDeg(radians)
radians*180/PI
end

def sun_rise_set(which,date,location,zenith)
#step 1: first calculate the day of the year
n=date.yday

#step 2: convert the longitude to hour value and calculate an
approximate time
lngHour=location.longitude/15
t=n+ ((6-lngHour)/24) if which==:sunrise
t=n+ ((18-lngHour)/24) if which==:sunset

#step 3: calculate the sun's mean anomaly
m=(0.9856 * t) - 3.289

#step 4: calculate the sun's true longitude
l= (m+(1.1916 * sin(toRad(m))) + (0.020 * sin(toRad(2*m))) +
282.634) % 360

#step 5a: calculate the sun's right ascension
ra = toDeg(atan(0.91764 * tan(toRad(l)))) % 360
###step 5b: right ascension value needs to be in the same quadrant
as L
lquadrant = (l/90).floor*90
raquadrant = (ra/90).floor*90
ra=ra+(lquadrant-raquadrant)

#step 5c: right ascension value needs to be converted into hours
ra/=15

#step 6: calculate the sun's declination
sinDec = 0.39782 * sin(toRad(l))
cosDec = cos(asin(sinDec))
#step 7a: calculate the sun's local hour angle
cosH = (cos(toRad(zenith)) - (sinDec * sin(toRad
(location.latitude)))) / (cosDec * cos(toRad(location.latitude)))

return nil if (not (-1..1).include? cosH)

#step 7b: finish calculating H and convert into hours
h = (360 - toDeg(acos(cosH)))/15 if which==:sunrise
h = (toDeg(acos(cosH)))/15 if which==:sunset
#step 8: calculate local mean time
t = h + ra - (0.06571 * t) - 6.622
t %=24
#step 9: convert to UTC
return date.to_datetime+(t - lngHour)/24
end

private :sun_rise_set

def sunrise(date,location,zenith=90.8333)
sun_rise_set :sunrise,date,location,zenith
end
def sunset(date,location,zenith=90.8333)
sun_rise_set :sunset,date,location,zenith
end
end


--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...

Kyrre Nygård

8/15/2007 9:27:00 PM

0

Thanks a lot Ken, and the same to you guys, Ronald and John.

I'll report back to base once I got something.

All the best,
Kyrre Nygård

Ken Bloom wrote:
> On Tue, 14 Aug 2007 20:50:02 +0900, Kyrre Nygård wrote:
>
>
>> Just wondering if any Muslims have gotten around to making a Ruby script
>> that like plays a sound or something when it's time for prayer.
>>
>> Thanks,
>> Kyrre Nygård
>>
>
> Would this help? I use it as part of a suite of scripts for computing
> times that Orthodox Jews use to compute times for prayer. The algorithm
> comes from the US Naval Observatory's Almanac for Computers.
>
> --Ken
>
>
>
> require 'date'
> require 'mathn'
>
> #methods stolen from ruby-doc.org
> class Date
> def to_datetime() DateTime.new0(self.class.jd_to_ajd(jd, 0, 0), @of,
> @sg) end
> def to_date() self end
> def to_time() Time.local(year, mon, mday) end
> end
> class DateTime
> def to_date() Date.new0(self.class.jd_to_ajd(jd, 0, 0), 0, @sg) end
> def to_datetime() self end
> def to_time
> d = new_offset(0)
> d.instance_eval do
> Time.utc(year, mon, mday, hour, min, sec,
> (sec_fraction * 86400000000).to_i)
> end.
> getlocal
> end
> end
>
> #end stolen
>
> def dms(degrees,minutes,seconds)
> degrees+minutes/60+seconds/60/60
> end
>
> module Sunrise
> include Math
> class Location
> attr_accessor :latitude, :longitude, :offset
> def initialize(latitude,longitude)
> @latitude,@longitude=latitude,longitude
> end
> end
>
> def toRad(degrees)
> degrees*PI/180
> end
>
> def toDeg(radians)
> radians*180/PI
> end
>
> def sun_rise_set(which,date,location,zenith)
> #step 1: first calculate the day of the year
> n=date.yday
>
> #step 2: convert the longitude to hour value and calculate an
> approximate time
> lngHour=location.longitude/15
> t=n+ ((6-lngHour)/24) if which==:sunrise
> t=n+ ((18-lngHour)/24) if which==:sunset
>
> #step 3: calculate the sun's mean anomaly
> m=(0.9856 * t) - 3.289
>
> #step 4: calculate the sun's true longitude
> l= (m+(1.1916 * sin(toRad(m))) + (0.020 * sin(toRad(2*m))) +
> 282.634) % 360
>
> #step 5a: calculate the sun's right ascension
> ra = toDeg(atan(0.91764 * tan(toRad(l)))) % 360
> ###step 5b: right ascension value needs to be in the same quadrant
> as L
> lquadrant = (l/90).floor*90
> raquadrant = (ra/90).floor*90
> ra=ra+(lquadrant-raquadrant)
>
> #step 5c: right ascension value needs to be converted into hours
> ra/=15
>
> #step 6: calculate the sun's declination
> sinDec = 0.39782 * sin(toRad(l))
> cosDec = cos(asin(sinDec))
> #step 7a: calculate the sun's local hour angle
> cosH = (cos(toRad(zenith)) - (sinDec * sin(toRad
> (location.latitude)))) / (cosDec * cos(toRad(location.latitude)))
>
> return nil if (not (-1..1).include? cosH)
>
> #step 7b: finish calculating H and convert into hours
> h = (360 - toDeg(acos(cosH)))/15 if which==:sunrise
> h = (toDeg(acos(cosH)))/15 if which==:sunset
> #step 8: calculate local mean time
> t = h + ra - (0.06571 * t) - 6.622
> t %=24
> #step 9: convert to UTC
> return date.to_datetime+(t - lngHour)/24
> end
>
> private :sun_rise_set
>
> def sunrise(date,location,zenith=90.8333)
> sun_rise_set :sunrise,date,location,zenith
> end
> def sunset(date,location,zenith=90.8333)
> sun_rise_set :sunset,date,location,zenith
> end
> end
>
>
>


Ronald Fischer

8/16/2007 8:08:00 AM

0

> Some awesome suggestions here, but I think it's a bit more complex
> considering how times vary from location to location.

But you have the timezone for each location, right? If you use the
DateTime
class for calculating times, you can convert between time zones using
the
new_offset method, if you know the offset of the respective time zone to
UTC.

If you only know the *name* of the time zone, there is a hack on how
to do it using the Time class, described in the "Ruby Cookbook" (which I

would recommend buying anyway). This hack works if your operating system

honours the TZ environment variable. You switch temporarily to this zone

(by changing TZ), get the local time there, and switch back to your own
zone. You then have the time diff to your zone, and you can always get
the time UTC time by calling Time#gmtime.

Ronald
--
Ronald Fischer <ronald.fischer@venyon.com>
Phone: +49-89-452133-162

Ken Bloom

8/16/2007 2:38:00 PM

0

On Thu, 16 Aug 2007 17:07:43 +0900, Ronald Fischer wrote:

>> Some awesome suggestions here, but I think it's a bit more complex
>> considering how times vary from location to location.
>
> But you have the timezone for each location, right? If you use the
> DateTime class for calculating times, you can convert between time
> zones using the new_offset method, if you know the offset of the
> respective time zone to UTC.
>
> If you only know the *name* of the time zone, there is a hack on how to
> do it using the Time class, described in the "Ruby Cookbook" (which I
> would recommend buying anyway). This hack works if your operating system
> honours the TZ environment variable. You switch temporarily to this zone
> (by changing TZ), get the local time there, and switch back to your own
> zone. You then have the time diff to your zone, and you can always get
> the time UTC time by calling Time#gmtime.
>
> Ronald

I prefer the tzfile gem for dealing with timezones.

--Ken

--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...