<?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: Gautam Sawhney</title>
    <description>The latest articles on DEV Community by Gautam Sawhney (@gautamsawhney).</description>
    <link>https://dev.to/gautamsawhney</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%2F188820%2F6c974ed9-7d43-4c02-8c3a-d3c9b082e960.png</url>
      <title>DEV Community: Gautam Sawhney</title>
      <link>https://dev.to/gautamsawhney</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gautamsawhney"/>
    <language>en</language>
    <item>
      <title>Integrating with Google Calendar in a Rails app - The Right Way</title>
      <dc:creator>Gautam Sawhney</dc:creator>
      <pubDate>Tue, 26 May 2020 11:19:35 +0000</pubDate>
      <link>https://dev.to/gautamsawhney/integrating-with-google-calendar-in-a-rails-app-the-right-way-alo</link>
      <guid>https://dev.to/gautamsawhney/integrating-with-google-calendar-in-a-rails-app-the-right-way-alo</guid>
      <description>&lt;p&gt;Part 1 of this series - &lt;a href="https://dev.to/gautamsawhney/how-to-not-integrate-google-calendar-with-your-product-45pi"&gt;How NOT to integrate Google Calendar with your product&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;u&gt; Prerequisite &lt;/u&gt;
&lt;/h3&gt;

&lt;p&gt;1) If using rails then use the gem &lt;code&gt;google-api-client&lt;/code&gt;&lt;br&gt;
2) I am considering here that you already have the &lt;code&gt;access_token&lt;/code&gt; of the user. I will write a different blog to explain how to get that.&lt;/p&gt;
&lt;h3&gt;
  
  
  1) Do full initial synch of events
&lt;/h3&gt;

&lt;p&gt;It has the following steps - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetch a new &lt;code&gt;access_token&lt;/code&gt; if the token has expired.&lt;/li&gt;
&lt;li&gt;Create the service authorization object which will be used for fetching the events.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ref code for &lt;code&gt;service authorization&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_service_auth&lt;/span&gt;
  &lt;span class="c1"&gt;#create service auth&lt;/span&gt;
  &lt;span class="vi"&gt;@service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Google&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Apis&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;CalendarV3&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;CalendarService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;
  &lt;span class="vi"&gt;@service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authorization&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;google_secret&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_authorization&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;expired?&lt;/span&gt;

  &lt;span class="n"&gt;new_access_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authorization&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;refresh!&lt;/span&gt; &lt;span class="c1"&gt;#refresh access_token&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Fetching all calendar events(past, present and future).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The full sync is the original request for all the resources of the collection you want to synchronize.&lt;/li&gt;
&lt;li&gt;In the response to the list operation, you will find a field called nextSyncToken representing a sync token. You'll need to store the value of nextSyncToken. If the result set is too large and the response gets paginated, then the nextSyncToken field is present only on the very last page.&lt;/li&gt;
&lt;li&gt;Depending on what your use case is, it will be better to perform this job as a background task.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developers.google.com/calendar/v3/reference/events/list"&gt;Events: list API&lt;/a&gt; is used for this. The gem provides an easier method called &lt;code&gt;list_events&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ref code for &lt;code&gt;syncing events&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_events&lt;/span&gt;
    &lt;span class="vi"&gt;@events_arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="vi"&gt;@events_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list_events&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'primary'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;single_events: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;max_results: &lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="vi"&gt;@sync_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@events_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next_sync_token&lt;/span&gt;
    &lt;span class="vi"&gt;@page_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@events_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next_page_token&lt;/span&gt;
    &lt;span class="vi"&gt;@events_arr&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="vi"&gt;@events_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="vi"&gt;@sync_token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;blank?&lt;/span&gt;
      &lt;span class="vi"&gt;@events_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list_events&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'primary'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;single_events: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;max_results: &lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;page_token: &lt;/span&gt;&lt;span class="vi"&gt;@page_token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="vi"&gt;@sync_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@events_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next_sync_token&lt;/span&gt;
      &lt;span class="vi"&gt;@page_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@events_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next_page_token&lt;/span&gt;
      &lt;span class="vi"&gt;@events_arr&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="vi"&gt;@events_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  2) Create a webhook to receive push notifications
&lt;/h3&gt;

&lt;p&gt;After a full sync of events, the next step is to setup a Webhook so that google can inform us of the changes that we subscribe for.&lt;br&gt;
For every user that links their calendar to the app, we will create a subscription so that we can be informed whenever there is a change in their calendar.&lt;/p&gt;

&lt;p&gt;It has the following steps - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetch a new &lt;code&gt;access_token&lt;/code&gt; if the token has expired.&lt;/li&gt;
&lt;li&gt;Create the service authorisation object which will be used for fetching the events, exactly same as shown above.&lt;/li&gt;
&lt;li&gt;Set up a Channel - It creates a channel with google and specifies the callback URL or the web-hook URL.&lt;/li&gt;
&lt;li&gt;Watch events - After the web-hook is set up, we need to specify what events we want to watch and also need to specify from which calendar.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;setup_channel&lt;/span&gt;
  &lt;span class="vi"&gt;@channel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Google&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Apis&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;CalendarV3&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;address: &lt;/span&gt;&lt;span class="n"&gt;callback_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;id: &lt;/span&gt;&lt;span class="n"&gt;channel_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;type: &lt;/span&gt;&lt;span class="s2"&gt;"web_hook"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;code&gt;callback_url&lt;/code&gt; - It can't be localhost, it has to be a valid &lt;code&gt;https&lt;/code&gt; url. For testing purposes you can use &lt;a href="https://ngrok.com/"&gt;ngrok&lt;/a&gt;.&lt;br&gt;
&lt;code&gt;channel_id&lt;/code&gt; - This is a UUID - &lt;code&gt;SecureRandom.uuid&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;watch_events&lt;/span&gt;
    &lt;span class="n"&gt;time_min&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DateTime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rfc3339&lt;/span&gt;
    &lt;span class="vi"&gt;@webhook&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;watch_event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'primary'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="vi"&gt;@channel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;single_events: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;time_min: &lt;/span&gt;&lt;span class="n"&gt;time_min&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;primary&lt;/code&gt; - refers to the &lt;code&gt;primary&lt;/code&gt; calendar of the user.&lt;br&gt;
&lt;code&gt;single_events&lt;/code&gt; - Setting it to true also gives all events belonging to 1 single recurring event.&lt;/p&gt;

&lt;p&gt;Now, whenever there will be any change in the primary calendar of the user google will hit the registered web-hook for the user.&lt;/p&gt;

&lt;p&gt;In the request Google will pass &lt;code&gt;X-Goog-Resource-ID&lt;/code&gt; and &lt;code&gt;X-Goog-Channel-ID&lt;/code&gt;. We would have to hit the &lt;code&gt;list_events&lt;/code&gt; API again to fetch the changed events data for that user.&lt;/p&gt;

&lt;p&gt;Only difference will be that instead of passing the page token like we did earlier, we would pass the &lt;code&gt;sync_token&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_events&lt;/span&gt;
    &lt;span class="vi"&gt;@events_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list_events&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'primary'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;single_events: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;max_results: &lt;/span&gt;&lt;span class="mi"&gt;2500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;sync_token: &lt;/span&gt;&lt;span class="n"&gt;sync_token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  3) Saving X-Goog-Resource-ID &amp;amp; X-Goog-Channel-ID
&lt;/h3&gt;

&lt;p&gt;When we created the web-hook google will return us with a &lt;code&gt;resource_id&lt;/code&gt;, &lt;code&gt;resource_uri&lt;/code&gt;, &lt;code&gt;id&lt;/code&gt;(that we created). We need to save all this data so that we can get to know for which user the events have changed.&lt;br&gt;
Also the channel expires in around 1 week so we need to keep creating new web-hooks before it expires.&lt;/p&gt;

&lt;h3&gt;
  
  
  4) Deleting the events with status &lt;code&gt;cancelled&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This is the flow that took me some time to understand. So what happens when a user changes the time of their event or has the user changed a single event or all the events in a recurring event. What google does is that &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if the user changes a single event, then google keeps the &lt;code&gt;calendar_id&lt;/code&gt; as same.&lt;/li&gt;
&lt;li&gt;if the user changes a recurring event and selects &lt;code&gt;all&lt;/code&gt; or &lt;code&gt;following events&lt;/code&gt; as option then the &lt;code&gt;calendar_id&lt;/code&gt; changes for all the events. Hence, in this case we need to delete the old events and add new events in our system. So, this is a check that you will have to add when saving the calendar events in your system.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it - It's quite messy if you are trying to figure it out from scratch and I hope this article will help you all.&lt;/p&gt;

&lt;p&gt;If you face any issue, connect with me on twitter and I will be more than happy to help.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Beautiful Pointers</title>
      <dc:creator>Gautam Sawhney</dc:creator>
      <pubDate>Fri, 08 May 2020 13:51:55 +0000</pubDate>
      <link>https://dev.to/gautamsawhney/beautiful-pointers-12eh</link>
      <guid>https://dev.to/gautamsawhney/beautiful-pointers-12eh</guid>
      <description>&lt;h3&gt;
  
  
  Basics
&lt;/h3&gt;

&lt;p&gt;Pointers are an amazing. C allows the programmer to reference the location of objects and the contents of those location using &lt;code&gt;pointers&lt;/code&gt;. A pointer is like any other data type in &lt;code&gt;C&lt;/code&gt;. The value of a pointer is a memory location, similar to how the value of an integer is a number. Let's see an example&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int money = 10
pntr_money = &amp;amp;money

pntr_money - is an integer pointer which would hold the address of money which is &amp;amp;money.
*pntr_money - points to the value in the variable money which is 10.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  More details
&lt;/h3&gt;

&lt;p&gt;Consider &lt;code&gt;pntr_money&lt;/code&gt; is a pointer to an integer as shown above. Then &lt;code&gt;pntr_money + 1&lt;/code&gt; is a pointer to an integer immediately following the integer &lt;code&gt;*pntr_money&lt;/code&gt; in memory, and &lt;code&gt;pntr_money - 1&lt;/code&gt; is the pointer to an integer immediately preceding &lt;code&gt;*pntr_money&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let us consider a machine which uses byte addressing, an integer requires 4 bytes and the value of pntr_money is 100(that is, pntr_money points to the integer *pntr_money at location 100).&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pntr_money = 100
pntr_money - 1 = 96
pntr_money + 1 = 104
pntr_money + 2 = 108

*(pntr_money - 1) = Contents of the 4 bytes 96, 97, 98 and 99 interpreted as an integer.
*(pntr_money + 1) = Contents of the 4 bytes 104, 105, 106 and 107.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Another thing to remember is the difference between &lt;code&gt;*pntr_money + 1&lt;/code&gt; and &lt;code&gt;*(pntr_money + 1)&lt;/code&gt;&lt;/p&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*pntr_money + 1 - This will increase the value in pntr_money by 1&lt;br&gt;
*(pntr_money + 1) - This will point to the value at the address which is (pntr_money + 1)&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Example&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;Pointers play a prominent rule in passing parameters to functions. Most parameters passed to a function are by value but if we wish to modify the value of the passed parameter we must pass the address of the parameter which is what pointers help with.&lt;/p&gt;

&lt;p&gt;Here is an example to understand better -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IenjU4Pg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ly8cn0axyh7ng3fdlex7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IenjU4Pg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ly8cn0axyh7ng3fdlex7.png" alt="Program"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Line 2 prints &lt;code&gt;5&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Line 3 invokes &lt;code&gt;funct&lt;/code&gt; and the value passed is the pointer value &lt;code&gt;&amp;amp;x&lt;/code&gt;.This is the address of &lt;code&gt;x&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The parameter of &lt;code&gt;funct&lt;/code&gt; is &lt;code&gt;py&lt;/code&gt; of type &lt;code&gt;int *&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Line 7 increments the integer at location &lt;code&gt;py&lt;/code&gt;, however the value of &lt;code&gt;py&lt;/code&gt; which is &lt;code&gt;&amp;amp;x&lt;/code&gt; remains the same. Thus &lt;code&gt;py&lt;/code&gt; points to the integer &lt;code&gt;x&lt;/code&gt; so that when &lt;code&gt;*py&lt;/code&gt; is incremented, x is incremented.&lt;/li&gt;
&lt;li&gt;Line 8 prints &lt;code&gt;6&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Line 4 also prints &lt;code&gt;6&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hence, Pointers are the mechanism used in C to allow a called function to modify variables in a calling function.&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>todayilearned</category>
      <category>c</category>
    </item>
    <item>
      <title>Caret(^) symbol in Ruby &amp; Ruby on Rails</title>
      <dc:creator>Gautam Sawhney</dc:creator>
      <pubDate>Wed, 18 Mar 2020 10:26:32 +0000</pubDate>
      <link>https://dev.to/gautamsawhney/caret-symbol-in-rails-265n</link>
      <guid>https://dev.to/gautamsawhney/caret-symbol-in-rails-265n</guid>
      <description>&lt;p&gt;&lt;code&gt;^&lt;/code&gt; symbol has multiple uses in &lt;code&gt;ROR&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  1- As a &lt;a href="https://en.wikipedia.org/wiki/Bitwise_operation#XOR"&gt;bitwise XOR Operator&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;For each bit in the binary representation of the operands, a bitwise XOR will get a 1 bit if one of the corresponding bits in the operands is 1, but not both, otherwise, the XOR will get a 0 bit. Here's an example:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5     = 101
6     = 110
5 ^ 6 = 011 = 3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  2- In Rails validation error message
&lt;/h3&gt;

&lt;p&gt;When you want to override the error message without the attribute name, simply prepend the message with &lt;code&gt;^&lt;/code&gt; like&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;validates_numericality_of :identity_id, :message =&amp;gt; "^Person field definition id must be an integer"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;you get &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Person field definition id must be an integer&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;instead of&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Identity Id Person field definition id must be an integer&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How NOT to integrate Google Calendar with your product</title>
      <dc:creator>Gautam Sawhney</dc:creator>
      <pubDate>Tue, 17 Mar 2020 08:25:34 +0000</pubDate>
      <link>https://dev.to/gautamsawhney/how-to-not-integrate-google-calendar-with-your-product-45pi</link>
      <guid>https://dev.to/gautamsawhney/how-to-not-integrate-google-calendar-with-your-product-45pi</guid>
      <description>&lt;p&gt;Google calendar has decent documentation for most of its products and supports most of the libraries, even then, it's confusing enough to take the wrong approach while integrating with google calendar.&lt;/p&gt;

&lt;p&gt;When I set out to build calendar integration for one of my products, I had never thought that it would end up becoming so complicated to do things which I had initially thought to be simple. &lt;/p&gt;

&lt;h3&gt;
  
  
  Product Requirements
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;During Signup/Login ask for permission to view/edit/create the events in their primary google calendar.&lt;/li&gt;
&lt;li&gt;Fetch the calendar events(both recurring and 1 time) and show them to the users so that they can add more details to it(specific to the product).&lt;/li&gt;
&lt;li&gt;Keep in sync with any new events that are created.&lt;/li&gt;
&lt;li&gt;Sync existing events between the product and the calendar.&lt;/li&gt;
&lt;li&gt;Updating the correct recurring events in google calendar for any updates done to them in my product.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Remember that, my product required 2-way sync of events.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Incorrect Approach
&lt;/h3&gt;

&lt;p&gt;During my research, most of the blog posts I read pointed to using the  &lt;a href="https://developers.google.com/calendar/v3/reference/events/list"&gt;Calendar Events List API&lt;/a&gt; and my brain started to work in that direction. I took the following approach which is inefficient and unscalable -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Integrated the Calendar Events List API which got me the event information for all the upcoming events.&lt;/li&gt;
&lt;li&gt;Saved the ones which matched as per the algorithm of the product&lt;/li&gt;
&lt;li&gt;If the user performed any update to these events then update the calendar events accordingly(changes to date/time/description)&lt;/li&gt;
&lt;li&gt;Write a Cron job which runs every 30 minutes to check if any new events were added/existing events changed(biggest blunder) for all the users in the database.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The Correct Approach
&lt;/h3&gt;

&lt;p&gt;Soon, I realised that this was not the most efficient and scalable way to achieve the results I wanted.&lt;br&gt;
I dug deeper into the google documentation to realize that there is a &lt;a href="https://developers.google.com/calendar/v3/sync"&gt;synch API&lt;/a&gt; which helps in incremental synch of data and works as a &lt;a href="https://en.wikipedia.org/wiki/Webhook"&gt;webhook&lt;/a&gt;. This is what made complete sense and would fit my requirements perfectly.&lt;br&gt;
I am going to talk about this approach in a new series. Stay Tuned&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>react</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
