I am trying to make a scheduled task where cron job executes after every 15 minutes, but I am confused about seconds.
I have made the following cron: ("* 0/15 * * * *") . Is it same as
("0 0/15 * * * *") [Note the second part here]. I mean in online I have seen examples where seconds is replaced by 0, but other fields with *. So my question is, if I replace seconds field with *, then is it same as with 0 ?
Related
I have the following file with Markdown markup:
* [B](B)
* b
* c
* [C](C)
* [A](a)
* a
I try to sort it and get the following result:
* [A](a)
* a
* [B](B)
* b
* c
* [C](C)
It is necessary to sort only the main levels, and sub-levels must follow the main levels, i.e., stay at the levels where they were. The first thing that comes to mind is of course :sort; but unfortunately this will also sort the sub-levels. We will get:
* a
* b
* c
* [A](a)
* [B](B)
* [C](C)
Are there any tricks or plugins for this kind of sorting? Thx!
The usual approach for this class of problems is to inline each block, then sort them, and then "de-inline" them back to their original state.
First step: inline each block.
We do this by replacing each EOL followed by SPACE-SPACE-STAR with some fancy symbol unlikely to be found in our document:
:%s/\n\( \*\)/§\1
Which gives us the following:
* [B](B)§ * b§ * c
* [C](C)
* [A](a)§ * a
Second step: sort the buffer.
We simply use :help :sort:
:sort
to obtain this:
* [A](a)§ * a
* [B](B)§ * b§ * c
* [C](C)
Third step: revert each "block" to its initial state.
We do this by reverting the substitution above with another, much simpler, one:
:%s/§/\r
which gives us the desired outcome:
* [A](a)
* a
* [B](B)
* b
* c
* [C](C)
A couple of notes:
The exact pattern to use in the first substitution depends on the exact structure of your document. That part is, IMO, too highly contextual to be generalisable.
§ is just an example, use whatever symbol you want.
I am gathering data on a device, and after every second, I update a count and log it. I am now processing it, and am new to python, so I had a question as to whether it was possible to convert a numbered array [0,1,2,3,4,...1091,1092,1093,...] into a timestamp [00:00:01, 00:00:02, 00:00:03, 00:00:04, ... 00:18:11, 00:18:12, 00:18:13,...] for example.
If you could please lead me in the right direction, that would be very much appreciated!
p.s. In the future, I will be logging the data as a timestamp, but for now, I have 5 hours' worth of data that needs to be processed!
import datetime as dt
timestamp=[0,1,2,3,4,5,1092,1093]
print([dt.timedelta(seconds=ts) for ts in timestamp])
Happy Coding
If all you have is seconds, then you can just do simple arithmetic to convert them to minutes and hours:
inp = [0, 1, 2, 3, 4, 1091, 1092, 1093]
outp = [f'{secs // 3600:02}:{(secs // 60) % 60:02}:{secs % 60:02}' for secs in inp]
print(outp)
# ['00:00:00', '00:00:01', '00:00:02', '00:00:03', '00:00:04', '00:18:11', '00:18:12', '00:18:13']
Here, I use a list comprehension and, for each secs in the input, create a format string:
hours is secs // 3600 (that's integer floor division), because one hour is 3600 seconds
Minutes is (secs // 60) % 60 (this incorporates the modulo operator, which displays the remainder of secs // 60 after dividing it by 60 again). One minute is 60 seconds, but more than 60 minutes would be an hour, so we need to make sure to 'roll over' the counter every 60 minutes (which is what the mod is for).
Seconds is, of course, secs % 60, because a minute has 60 seconds and we want the counter to roll over.
The format string starts with f', and anything inside {} is an instruction to evaluate whatever's inside it, and insert that into the string. The syntax is {expression:format}, where display is an optional instruction for how to format the data (i.e. not just printing it out). And format can get complicated (look up a python f-string tutorial if you're curious about the specifics), but suffice it to say that in this case we use 02, which means that we want the output to be two characters in length, and padded with zeroes in case it's less than that.
I am trying create a plot(angle of incidence vs. time). Time is set between hour of sunrise to hour of sunrise (6:37:00 AM - 6:39:00 PM). I have to find angle of incidence for each minute interval starting from sunrise to sunset. The only issue is I don't have the faintest clue how to convert time into a number.
Angle of incidence depends on hour angle (Angle_hour). This is dependent on the time. Time before noon is given a negative value, and time after noon is positive. For example, at 6:37 am, the Hours would equal -6.62. On the other hand, 6:39 PM would equal 6.65. I am trying to have a for loop calculate the different values within the time frame.
for k = 1:6
Hours = k;
Angle_Hour(k) = 15 * Hours;
Angle_Incidence(k) = acos((sin(Angle_Declination) * sin (Angle_Latitude) * cos(Angle_Slope)) - (sin(Angle_Declination) * cos(Angle_Latitude) * sin(Angle_Slope) * cos(Angle_SurfaceAzimuth)) + (cos(Angle_Declination) * cos(Angle_Latitude) * cos(Angle_Slope) * cos(Angle_Hour(k))) + (cos(Angle_Declination) * sin(Angle_Latitude) * sin(Angle_Slope) * cos(Angle_SurfaceAzimuth) * cos(Angle_Hour(k))) + (cos(Angle_Declination) * sin(Angle_Slope) * sin(Angle_SurfaceAzimuth) * sin(Angle_Hour(k)))) ;
end
If in your program the time in a day is a variable of type datetime, then you can either use datenum to turn the date to a number, or you can use the functions: hour, minute, second to extract the hours, minutes and seconds, and then calculate the angle using them.
So for example, you can have something like this:
function angle = Angle_Hour(k)
hours = hour(k) + minute(k)/60 + second(k)/3600
angle = % some expression/function of time in hours
end
syncClockTime :: TimeZone -> UTCTime -> Pico -> Pico
syncClockTime zone time secondTo = do
let (TimeOfDay hour minute secondFrom) = localTimeOfDay $ utcToLocalTime zone time
if secondTo > secondFrom then
secondTo - secondFrom
else
60 + secondTo - secondFrom
I have a couple of questions related to the above code
is there a way to directly extract the seconds secondFrom from the UTCTime without converting it to local time and without specifying a time zone? (if yes: how? if no: why?)
How to actually make the running thread/task to asynchronously sleep for the above found number of seconds?
Question 2 is simple: you can make your Haskell process sleep for a specified number of microseconds using delay.
If I understand your Question 1, you want to be able to specify, say 30 seconds, and wait until the next time the system clock is 30 seconds past the minute. So if you call your function at 13:23:27 it will wait 3 seconds until 13:23:30, but if you called it at 13:23:33 then it will wait 57 seconds until 13:24:30.
That is a matter of doing arithmetic on the number of seconds. I would suggest you take the current Posix time using getPOSIXTime. This returns a NominalDiffTime, which is an instance of Real and RealFrac, so normal arithmetic works fine. The code you want is:
t <- getPOSIXTime
let secs = t - fromIntegral (floor (t/60) * 60)
Once you have the number of seconds past the minute you can figure out how long to wait until your target time.
Just interested in the shortened version of the following for the minutes interval:
5,15,25,35,45,55
8,18,28,38,48,58
I know they essentially the same, just a different ending digit.
Thanks.
The definition in the initial question is as short as it can be made.
This should do the trick:
5,15,25,35,45,55 * * * * yourcommand
8,18,28,38,48,58 * * * * yourcommand
Just put 8,18,28,38,48,58 etc in the 'minutes' field.
Ie:
8,18,28,38,48,58 * * * * /path/to/command