<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by sahith srivyshnav on Medium]]></title>
        <description><![CDATA[Stories by sahith srivyshnav on Medium]]></description>
        <link>https://medium.com/@xeeno?source=rss-a76640df7a6b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-KC62wNukTnqikHQ6_nbLA.jpeg</url>
            <title>Stories by sahith srivyshnav on Medium</title>
            <link>https://medium.com/@xeeno?source=rss-a76640df7a6b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 10:38:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@xeeno/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Airflow Scheduling with Quartz Cron Expression]]></title>
            <link>https://medium.com/@xeeno/airflow-scheduling-with-quartz-cron-expression-7cedd0094eff?source=rss-a76640df7a6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cedd0094eff</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[apache-airflow]]></category>
            <category><![CDATA[cron-expression]]></category>
            <dc:creator><![CDATA[sahith srivyshnav]]></dc:creator>
            <pubDate>Sun, 21 Sep 2025 15:54:19 GMT</pubDate>
            <atom:updated>2025-09-21T15:58:43.666Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Extend Apache Airflow to support Quartz cron expressions. Level up your scheduling with advanced timetables, seconds, years, last weekdays, and more.</blockquote><p>Airflow is amazing for orchestrating workflows… but its <strong>default cron support is limited</strong>. It only understands UNIX cron, which works for basic “every day” or “every hour” jobs. But real-world business schedules often demand more.</p><p>Think about cases like:</p><ul><li>“Run on the last weekday of the month.”</li><li>“Trigger on the second Monday of every month.”</li><li>“Fire every 10 seconds.”</li></ul><p>UNIX cron can’t handle these. But <strong>Quartz cron</strong> can.</p><p>The challenge? Airflow doesn’t support Quartz out of the box. The solution? A <strong>custom timetable</strong> that plugs Quartz into Airflow.</p><p>Reference: <a href="https://airflow.apache.org/docs/apache-airflow/stable/authoring-and-scheduling/timetable.html">Timetables — Airflow Authoring &amp; Scheduling</a></p><h3>Why Quartz Is a Big Deal:</h3><p>Quartz extends UNIX cron with <strong>two extra fields</strong> and several new tokens:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*eCO2Q8kRF3I2YXLTojJcJg.png" /></figure><p>Examples:</p><ul><li>0 0 12 LW * ? → Noon on the last weekday of the month.</li><li>0 15 10 ? * MON-FRI → 10:15 AM every weekday.</li><li>0 0 0 ? * MON#2 → Midnight on the second Monday of the month.</li></ul><p>This is the precision enterprises love.</p><h3>QuartzTimetable in Action</h3><p>Here is the full Code: <a href="https://gist.github.com/xeen0/5c0cbda63f329526e00fd2917f542379">QuartzTimetable gist</a><br> <em>let’s go through the major steps and methods that bring it to life.</em></p><h3>Friendly Summaries in the UI:</h3><pre>from cron_descriptor import get_description<br><br>@property<br>def summary(self): return self.cron_expression<br><br>@property<br>def description(self): return get_description(self.cron_expression)</pre><p>Airflow now shows:<br> <strong>“At 10:15 AM, Monday through Friday”</strong><br> instead of 0 15 10 ? * MON-FRI.</p><h3>Manual Runs → infer_manual_data_interval:</h3><p>Quartz fires at an <em>instant</em>. Airflow, however, requires every run to cover a <strong>data interval</strong>.</p><pre>def infer_manual_data_interval(self, run_after):<br>    anchor = run_after.in_timezone(self.tz)<br>    return DataInterval(start=anchor, end=anchor.add(seconds=1))</pre><p>The trick: wrap the instant in a <strong>1-second interval</strong>.<br> That’s how we bridge Airflow’s interval model with Quartz’s event-based triggers.</p><h3>Dropping &amp; Resetting the Anchor ⚓:</h3><p>In next_dagrun_info, everything starts with the anchor. Imagine a ship traveling from port to port. Wherever the ship last stopped, the anchor is dropped — that’s our last successful DAG run.</p><ul><li>If the DAG has ran before, the anchor lies at that last finishing point.</li><li>If it has never run, the anchor drops right where the ship currently is: <strong>Date.now()</strong>.</li></ul><p>When the scheduler wakes up, it looks at where the anchor is resting and begins searching for the next valid stop.</p><p>Sometimes though, the anchor is stuck in the past. That’s where catchup comes into play:</p><pre>if not restriction.catchup and anchor &lt; now:<br>  anchor = now</pre><p>This line is like the crew pulling the anchor up from old waters and dropping it back down at the ship’s current position.</p><ul><li>With <strong>catchup enabled</strong>, the anchor stays behind, and the ship carefully revisits every port it missed along the way (Airflow backfills all past runs).</li><li>With <strong>catchup disabled</strong>, the anchor is reset to today, and the ship ignores the past, sailing forward only to future ports.</li></ul><p>Once the anchor is set, _next_valid_start(anchor) takes over — scanning ahead on the cron map until it finds the next safe harbor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*-N81SwkJdfgHCbcd_bWmTQ.png" /></figure><h3>Serialize / Deserialize:</h3><p>Airflow stores DAG definitions in its database.<br> These methods make sure our timetable can be saved and reloaded later.</p><p>Without them, every restart would “forget” the timetable.</p><h3>The Engine Room → _next_valid_start:</h3><p>Once the anchor is set, the timetable knows where the ship is currently docked. From there, _next_valid_start is the navigator that looks at the <strong>cron map</strong> and plots the next exact stop.</p><h4>1. Break the cron expression into fields</h4><p>Quartz cron expressions are split into <strong>7 fields</strong>:</p><pre>second   minute   hour   day-of-month   month   day-of-week   year</pre><p>If you only supply 6 (like a normal UNIX cron), the <strong>year</strong> slot is filled with *</p><p>Think of this as a <strong>cron grid</strong>:</p><ul><li>Seconds = the smallest tick marks.</li><li>Minutes = slightly larger blocks.</li><li>Hours = whole sections of the day.</li><li>Days and months = coastlines on the map.</li><li>Year = the wide ocean around it all.</li></ul><h4>2. Interpret the rules</h4><p>Each field can define valid paths:</p><ul><li>* or ? → any value.</li><li>1,15,30 → specific docks.</li><li>9-17 → a continuous stretch.</li><li>*/5 → every 5th slot.</li><li>JAN, MON-FRI → named markers.</li><li>Special Quartz tokens: L, LW, MON#2, 5L.</li></ul><h4>3. Mark candidate days</h4><p>Day-of-month and day-of-week interact:</p><ul><li>If both are * → all days.</li><li>If one is restricted → follow it.</li><li>If both are restricted → take the overlap.</li></ul><h4>4. Search forward from the anchor</h4><p>The search starts <strong>one second after the anchor</strong> — the ship never sails backwards.</p><p>The algorithm then drills down:<br> Year → Month → Day → Hour → Minute → Second.</p><p>At each level, invalid values are skipped until a valid combination is found.</p><h4>5. Stop at the first safe harbor</h4><p>The first match is chosen as the next run. If no match exists within 100 years, the search ends — the horizon safeguard.<br> Example:<br> * 0 0 12 LW * ? → Noon on the last weekday of the month.<br> * Today = Sept 10, 2025 → anchor = Sept 10.<br> * Navigator scans forward → last weekday = Sept 30.<br> * Time = 12:00:00.<br> * Next run = Sept 30, 2025 at noon.</p><h4>6. Why a 1-Second Interval?</h4><p>Airflow expects a “time interval” for every run. Quartz jobs are instant. So the trick is:<br>* Return an interval of [start, start+1 second].<br>* It’s basically a timestamp, but formatted the way Airflow likes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*i1tjE2vulGMHx8hkOokJqQ.png" /></figure><h4>Example DAG</h4><pre>from plugins.quartz_timetable import QuartzTimetable<br>with DAG(<br>    dag_id=&quot;quartz_example&quot;,<br>    timetable=QuartzTimetable(&quot;0 15 10 ? * MON-FRI&quot;),<br>    catchup=False,<br>):</pre><p>This DAG runs every weekday at 10:15 AM, Quartz-style.</p><h3>Packaging as a Plugin:</h3><p>Here’s the structure:</p><pre>| DAGs<br>|   └── dag.py              # Your DAGs live here<br>| utils<br>|   └── quartz_timetable.py # Full QuartzTimetable class (from the gist)<br>| plugins<br>|   └── quartz_plugin.py    # Registers QuartzTimetable as a plugin</pre><p>The plugin file (/plugins/quartz_plugin.py) looks like this:</p><pre>from airflow.plugins_manager import AirflowPlugin<br>from utils.quartz_timetable import QuartzTimetable<br>class QuartzTimetablePlugin(AirflowPlugin):<br>    name = &quot;quartz_timetable_plugin&quot;<br>    timetables = [QuartzTimetable]<br></pre><p>utils/quartz_timetable.py → contains the timetable class.<br>plugins/quartz_plugin.py → registers it with Airflow.</p><p>Airflow auto-discovers plugins at startup.<br>From then on, your DAGs can simply:</p><pre>from plugins.quartz_plugin import QuartzTimetable</pre><p>and start using Quartz scheduling.</p><h3><strong>Quartz vs UNIX Cron in Airflow:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*esJIUH65AJj-Lv2MCfA3xg.png" /></figure><h4>Choosing Between UNIX Cron and QuartzTimetable</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*uT-cUZvOWOcgTrXH6476JQ.png" /></figure><ul><li>Stick with <strong>UNIX cron</strong> if your needs are simple — it’s faster and built-in.</li><li>Choose <strong>QuartzTimetable</strong> if you want seconds, years, “last weekday,” or “nth weekday” rule</li></ul><h3>How We Optimize It:</h3><ul><li><strong>Start from anchor+1s</strong> → We don’t re-scan the entire calendar, only look forward from where we last stopped.</li><li><strong>Short-circuit checks</strong> → As soon as a matching datetime is found, we stop immediately (no unnecessary scanning).</li><li><strong>Range filtering</strong> → Candidate days are pre-computed from DOM and DOW rules, so we don’t brute-force every date.</li><li><strong>100-year horizon cap</strong> → Prevents infinite loops (e.g. “Feb 30”) and ensures the search is bounded.</li><li><strong>Practical performance</strong> → The bottleneck isn’t scheduling but your DAG tasks themselves, so the timetable cost is tiny in the big picture.</li></ul><h3>TL;DR</h3><ul><li><strong>UNIX cron (built-in)</strong> → Fast, efficient, perfect for simple schedules (daily, hourly, etc.).</li><li><strong>QuartzTimetable (custom)</strong> → Adds seconds, year, and advanced tokens (L, LW, #) for complex business rules.</li><li><strong>Performance</strong> → Quartz is slightly heavier but optimized with anchor-based scanning, candidate filtering, and a 100-year horizon cap.</li></ul><p>Use UNIX cron for everyday jobs, and QuartzTimetable when you need enterprise-grade precision.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cedd0094eff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Connect to USB Serial Ports in React Native]]></title>
            <link>https://medium.com/@xeeno/how-to-connect-to-usb-serial-ports-in-react-native-8513e709521?source=rss-a76640df7a6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8513e709521</guid>
            <dc:creator><![CDATA[sahith srivyshnav]]></dc:creator>
            <pubDate>Sun, 30 Apr 2023 16:59:14 GMT</pubDate>
            <atom:updated>2023-04-30T17:05:49.126Z</atom:updated>
            <content:encoded><![CDATA[<h3>Connecting to a Serial Port in React Native: A Step-by-Step Guide</h3><h3>Introduction</h3><p>Serial ports are the common interface used for connecting devices to computers and other systems. They are used in a wide range of applications, from industrial control systems to medical devices. In this tutorial, we will show you how to connect to a serial port in React Native using the react-native-usb-serialport-for-android library.</p><h4>Prerequisites</h4><p>To follow this tutorial, you should have some experience with React Native development and Android development. You should also have a physical device with a USB port that can be used for testing.</p><h3>Step 1: Install the Library</h3><p>The first step is to install the react-native-usb-serialport-for-android library using npm or yarn. You can do this by running the following command in your project directory:</p><pre>npm install react-native-usb-serialport-for-android</pre><p>or</p><pre>yarn add react-native-usb-serialport-for-android</pre><h3>Step 2: Add Permissions</h3><p>Next, you need to add the necessary permissions to your app’s AndroidManifest.xml file. This file is located in your project&#39;s android/app/src/main directory. You should add the following lines inside the &lt;manifest&gt; tag:</p><pre>&lt;uses-permission android:name=&quot;android.permission.USB_PERMISSION&quot; /&gt;<br>&lt;uses-feature android:name=&quot;android.hardware.usb.host&quot; /&gt;</pre><p>These permissions are needed to access the USB port on the device.</p><h3>Step 3: Request Permissions</h3><p>Before you can access the USB port, you need to request permission from the user. You can do this using the react-native-usb-serialport-for-android library&#39;s tryRequestPermission method. For example:</p><pre>import { UsbSerialManager } from &quot;react-native-usb-serialport-for-android&quot;;<br>import { ScrollView, Alert, Button } from &quot;react-native&quot;;<br><br>const SerialPortComponent = () =&gt; {<br>  async function requestUSBPermission() {<br>    try {<br>      const devices = await UsbSerialManager.list();<br>      // check for the available devices<br>      const granted = await UsbSerialManager.tryRequestPermission(devices[0].deviceId);<br>      // Send request for the first available device<br>      if (granted) {<br>        Alert.alert(&#39;USB permission granted&#39;);<br>        // continue with connecting to the USB device<br>      } else {<br>        Alert.alert(&#39;USB permission denied&#39;);<br>      }<br>    } catch (err) {<br>      console.error(err);<br>    }<br>  }<br>  return (<br>    &lt;ScrollView&gt;<br>      &lt;Button onPress={requestUSBPermission} title=&quot;Request USB Permission&quot;/&gt;<br>    &lt;/ScrollView&gt;<br>  )<br>}<br><br>export default SerialPortComponent</pre><p>This will request permission from the user to access the USB port. If permission is granted, you can continue with connecting to the USB device.</p><h3>Step 4: Open a Serial Port</h3><p>Before sending and receiving data, you need to open a serial port using the usbSerialManager object. This object is provided by the react-native-usb-serialport-for-android library and allows you to manage the USB serial connection.</p><p>To open a serial port, you can use the usbSerialManager.open method. This method takes in two parameters:</p><ol><li>deviceId: The USB device ID obtained in Step 3.</li><li>openOption: An object containing the following properties:</li></ol><ul><li>baudRate: The baud rate to use for serial communication.</li><li>parity: The parity setting to use for serial communication.</li><li>dataBits: The number of data bits to use for the serial communication.</li><li>stopBits: The number of stop bits to use for the serial communication.</li></ul><p>The usbSerialManager.open the method returns Promise that resolves to an usbSerial object. This object is used to send and receive data over the serial port.</p><pre><br> async function requestUSBPermission() {<br>  try {<br>    // check for the available devices<br>    const devices = await UsbSerialManager.list();<br>    // Send request for the first available device<br>    const granted = await UsbSerialManager.tryRequestPermission(devices[0].deviceId);<br>    if (granted) {<br>      // open the port for communication<br>      const usbSerialport = await UsbSerialManager.open(devices[0].deviceId, { baudRate: 9600, parity: Parity.None, dataBits: 8, stopBits: 1 });<br>      setUsbSerial(usbSerialport)<br>    } else {<br>      Alert.alert(&#39;USB permission denied&#39;);<br>    }<br>  } catch (err) {<br>    console.error(err);<br>  }<br>}</pre><p>we’re opening the serial port with a baud rate of 9600, no parity, 8 data bits, and 1 stop bit. If the serial port is opened successfully, the console.log statement will be executed. Otherwise, the error will be logged to the console.</p><p>Now that the serial port is open, we can start sending and receiving data. Let’s look at how to do that in the next steps.</p><h3>Step 5: Send Data</h3><p>To send data over the serial port, you can use the usbSerial.send method provided by the usbSerial object obtained in Step 4. This method takes a single parameter, which is a 4 character string containing the data to be sent in hexadecimal format.</p><pre>async function sendData(data) {<br>  if (usbSerial) {<br>    try {<br>      await usbSerial.send(data)<br>    } catch(e) {<br>      console.error(e)<br>    }<br>  }<br>}</pre><p>let’s create two buttons that call the sendData function with different data on press. The sendData function sends the provided data in hexadecimal format over the serial port.</p><pre>return (<br>  &lt;ScrollView&gt;<br>    &lt;Button onPress={() =&gt; sendData(&#39;0001&#39;)} title=&quot;ON&quot;/&gt;<br>    &lt;Button onPress={() =&gt; sendData(&#39;0002&#39;)} title=&quot;OFF&quot;/&gt;<br>  &lt;/ScrollView&gt;<br>)</pre><h3>Arduino setup</h3><p>Here’s how you can read data from the serial port using Arduino</p><ol><li>Open the Arduino IDE and create a new sketch.</li><li>In the setup() function, initialize the serial communication by calling Serial.begin(baudRate), where baudRate is the same value you used in your React Native app.</li><li>In the loop() function, read data from the serial port using the Serial.available() and Serial.read() functions. Here&#39;s an example code snippet:</li></ol><pre>int led = 13; // Pin for the first LED<br><br>void setup() {<br>  // Initialize the serial port<br>  Serial.begin(9600);<br>  <br>  // Set the LED pins as outputs<br>  pinMode(led, OUTPUT);<br>  <br>  // Turn off the LEDs<br>  digitalWrite(led, LOW);<br>  <br>}<br><br>void loop() {<br>  if (Serial.available() &gt; 0) {<br>    // Read the incoming data<br>    int data = Serial.read();<br>    // Toggle the LEDs based on the incoming data<br>    if (data == 0x01) {<br>      digitalWrite(led, HIGH);<br>    }<br>    else if (data == 0x02) {<br>      digitalWrite(led, LOW);<br>    }<br>  }<br>}</pre><h3>Output</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*MEeY5Qd89opqX_JNbaT0nQ.gif" /></figure><h3>Code</h3><p>Complete React-Native component code.</p><pre>import { UsbSerialManager, UsbSerial, Parity } from &quot;react-native-usb-serialport-for-android&quot;;<br>import { ScrollView, Alert, Button } from &quot;react-native&quot;;<br>import { useLayoutEffect, useState } from &quot;react&quot;;<br><br>const SerialPortComponent = () =&gt; {<br>  const [usbSerial, setUsbSerial] = useState(null)<br>  useLayoutEffect(() =&gt; {<br>    initSerialPort()<br>  },[])<br><br>  async function initSerialPort() {<br>    try {<br>      // check for the available devices<br>      const devices = await UsbSerialManager.list();<br>      // Send request for the first available device<br>      const granted = await UsbSerialManager.tryRequestPermission(devices[0].deviceId);<br>      if (granted) {<br>        // open the port for communication<br>        const usbSerialport = await UsbSerialManager.open(devices[0].deviceId, { baudRate: 9600, parity: Parity.None, dataBits: 8, stopBits: 1 });<br>        setUsbSerial(usbSerialport)<br>      } else {<br>        Alert.alert(&#39;USB permission denied&#39;);<br>      }<br>    } catch (err) {<br>      console.error(err);<br>    }<br>  }<br><br>  async function sendData(data) {<br>    if (usbSerial) {<br>      try {<br>        await usbSerial.send(data)<br>      } catch(e) {<br>        console.error(e)<br>      }<br>    }<br>  }<br>  return (<br>    &lt;ScrollView&gt;<br>      &lt;Button onPress={() =&gt; sendData(&#39;0x01&#39;)} title=&quot;ON&quot;/&gt;<br>      &lt;Button onPress={() =&gt; sendData(&#39;0x02&#39;)} title=&quot;OFF&quot;/&gt;<br>    &lt;/ScrollView&gt;<br>  )<br>}<br><br>export default SerialPortComponent</pre><h3><strong>Conclusion</strong></h3><p>In this post, we discussed how to connect to a serial port in React Native using the react-native-usb-serialport-for-android library.</p><p>In addition to the react-native-usb-serialport-for-android library, there are also other libraries available for connecting to USB serial devices in React Native, such as react-native-serialport, react-native-serial-port-api. Make sure to choose the library that suits your needs and requirements.</p><p>I hope this tutorial was helpful for you in connecting to a USB serial port in React Native. If you have any questions or comments, feel free to leave them below.</p><p>Happy coding!</p><h3>References</h3><p><a href="https://bastengao.com/react-native-usb-serialport-for-android/modules.html">https://bastengao.com/react-native-usb-serialport-for-android/modules.html</a></p><p><a href="https://github.com/bastengao/react-native-usb-serialport-for-android/tree/d81161ca1614a50319f10240de8ec0de19341cb8">https://github.com/bastengao/react-native-usb-serialport-for-android/tree/d81161ca1614a50319f10240de8ec0de19341cb8</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8513e709521" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>