<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Chamara Abeysekara</title>
    <description>The latest articles on DEV Community by Chamara Abeysekara (@cha_m_ra).</description>
    <link>https://dev.to/cha_m_ra</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F63405%2F3699a921-155b-4d29-bb5d-57886e355306.jpg</url>
      <title>DEV Community: Chamara Abeysekara</title>
      <link>https://dev.to/cha_m_ra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cha_m_ra"/>
    <language>en</language>
    <item>
      <title>How I build an announcement notifier app</title>
      <dc:creator>Chamara Abeysekara</dc:creator>
      <pubDate>Tue, 02 Feb 2021 13:19:06 +0000</pubDate>
      <link>https://dev.to/cha_m_ra/how-i-build-an-announcement-notifier-app-1kf2</link>
      <guid>https://dev.to/cha_m_ra/how-i-build-an-announcement-notifier-app-1kf2</guid>
      <description>&lt;p&gt;This is how I automate my mundane task of check for any announcements daily. This  app track any announcements regarding my degree program. With the ongoing situation there are announcements that I need to be informed about so, what I do is visit &lt;a href="http://www.bit.lk/" rel="noopener noreferrer"&gt;bit.lk&lt;/a&gt; daily and check if there's anything new. Because with COVID-19 they might just cancel the exams 🙊! Checking whether there’s any new updates to me, is very boring and why bother doing it yourself when you can get a machine to do it for you? Also, I like automating stuff! This to me, is a great opportunity to use web scraping, cloud function and FCM. &lt;/p&gt;

&lt;p&gt;I decided to use &lt;a href="https://pptr.dev/" rel="noopener noreferrer"&gt;Puppeteer&lt;/a&gt; for web scraping, &lt;a href="https://firebase.google.com/" rel="noopener noreferrer"&gt;Firebase&lt;/a&gt; cloud functions to trigger the web crawler, Firebase Cloud messaging to push notifications to my mobile and a React app to show the announcements. It looks something like this,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwiy8yp71k9d40wvazbqc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwiy8yp71k9d40wvazbqc.jpg" alt="infrastructure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The application start with cloud function that trigger four times a day which uses Puppeteer to crawl into the web page and get me those 🔔 new announcement which get posted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;crawler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;runWith&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;timeoutSeconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1GB&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nx"&gt;pubsub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0 */6 * * *&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;onRun&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When using Puppeteer make sure use add &lt;code&gt;args: ['--no-sandbox']&lt;/code&gt; into launch options save you lots of time thinking why the function is failing for no reason whatsoever 😁. And also the function need more memory and increase of the timeout. Firebase function &lt;a href="https://firebase.google.com/docs/functions/schedule-functions" rel="noopener noreferrer"&gt;scheduler&lt;/a&gt; use both Unix Crontab and App Engine syntax when passing the time I went with Unix Crontab and I used &lt;a href="https://crontab.guru/" rel="noopener noreferrer"&gt;crontab guru&lt;/a&gt; to get the syntax for run it every 6 hours.&lt;/p&gt;

&lt;p&gt;Then I save any new announcement to the Firestore while I do that I, a function is listening to new announcement adding. It triggers the function to push notification to saved devices.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onAnnouncementCreate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firestore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;document&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;announcements/{announcementsId}&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;snap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;broadcastNotification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;snap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;announcementsId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The purpose of the React app is very simple it shows announcements that I have captured and allow a user to subscribe to push notification. Users can subscribe by clicking the bell icon 🔔 in the top right corner; yes I know! It is not that obvious, but I can't think of anywhere else. I have animated it just to bring attention to it though 😉.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk5s194m481hpiyhmzkn4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk5s194m481hpiyhmzkn4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s how I build an announcement notifier app, just using a few components that is available in Firebase. &lt;/p&gt;

&lt;p&gt;check it out - &lt;a href="https://bit-notify.web.app/" rel="noopener noreferrer"&gt;https://bit-notify.web.app/&lt;/a&gt;&lt;br&gt;
github - &lt;a href="https://github.com/chamra/bit-notify" rel="noopener noreferrer"&gt;https://github.com/chamra/bit-notify&lt;/a&gt;&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>react</category>
      <category>pushnotification</category>
      <category>puppeteer</category>
    </item>
    <item>
      <title>LaraCRUDJS</title>
      <dc:creator>Chamara Abeysekara</dc:creator>
      <pubDate>Sun, 17 Mar 2019 09:19:47 +0000</pubDate>
      <link>https://dev.to/cha_m_ra/laracrudjs-33n4</link>
      <guid>https://dev.to/cha_m_ra/laracrudjs-33n4</guid>
      <description>&lt;p&gt;So for the post, I thought I write about something that I developed a few months back. This a JavaScript library I have written to manage CRUD functions.&lt;/p&gt;

&lt;p&gt;You can find it no GitHub &lt;a href="https://github.com/chamra/laraCRUDJS"&gt;https://github.com/chamra/laraCRUDJS&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Once you downloaded the zip you can place &lt;code&gt;laraCRUD.js&lt;/code&gt; file in your assets folder and reference it in your &lt;code&gt;app.balde.php&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;script src="{{ assets('js/laraCRUD.js') }}"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;after that, it's all a matter of time you create an object from &lt;code&gt;CRUD&lt;/code&gt; class&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const crud = new CRUD()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;you can override all defaults from the constuctor. default is,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{&lt;br&gt;
//form element id&lt;br&gt;
 this.form = "formData"; &lt;br&gt;
//modal id that include the form&lt;br&gt;
 this.modal = "#formModal"; &lt;br&gt;
//form submit buttom id&lt;br&gt;
 this.submitButton = "#btnSubmit"; &lt;br&gt;
//propertie for datatables&lt;br&gt;
 this.datatables = ""; &lt;br&gt;
//resource url&lt;br&gt;
 this.url = ""; &lt;br&gt;
//unable page refresh afer a form a submit&lt;br&gt;
 this.refreshPage = false; &lt;br&gt;
//current status of the form to be update or create&lt;br&gt;
 this.update = false;&lt;br&gt;
//csrf token&lt;br&gt;
 this.token = document.head.querySelector('meta[name="csrf-token"]'); &lt;br&gt;
//selected items auto increment id&lt;br&gt;
 this.id = 0; &lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;calling the method &lt;code&gt;initCRUDFunctions()&lt;/code&gt; on &lt;code&gt;crud&lt;/code&gt; will in initiate basic crud function you need for the instance. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;crud.initCRUDFunctions()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;for example - &lt;a href="https://github.com/chamra/laraCRUDJS/blob/master/example/main.js"&gt;https://github.com/chamra/laraCRUDJS/blob/master/example/main.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Help is always welcome, so fork me ✌!&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>javascript</category>
      <category>crud</category>
      <category>jquery</category>
    </item>
  </channel>
</rss>
