<?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: Darshan J</title>
    <description>The latest articles on DEV Community by Darshan J (@darshan_jayadev).</description>
    <link>https://dev.to/darshan_jayadev</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%2F158243%2F508ca84f-bf01-481e-ba3b-079f1188515e.jpg</url>
      <title>DEV Community: Darshan J</title>
      <link>https://dev.to/darshan_jayadev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/darshan_jayadev"/>
    <language>en</language>
    <item>
      <title>Three ways to Theme a React App</title>
      <dc:creator>Darshan J</dc:creator>
      <pubDate>Fri, 28 Feb 2020 15:30:46 +0000</pubDate>
      <link>https://dev.to/darshan_jayadev/three-ways-to-theme-a-react-app-k01</link>
      <guid>https://dev.to/darshan_jayadev/three-ways-to-theme-a-react-app-k01</guid>
      <description>&lt;p&gt;Whether it might be to let the user toggle between light &amp;amp; dark themes or let them choose one of the many color themes, themes make websites better.&lt;/p&gt;

&lt;p&gt;Here are 3 ways I found to theme a React App:&lt;/p&gt;

&lt;h2&gt;
  
  
  Using CSS Variables
&lt;/h2&gt;

&lt;p&gt;This one is fairly simple and can also enable you to add themes quite easily event after you built your website without considering adding theme. This method isn't event restricted to just React apps, you can even use this method to theme a Vanilla JS app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/juzQrios/odin-restaurant-react"&gt;Github link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@harishv6665_49536/theming-with-react-js-or-any-in-minutes-with-css-variables-11d4ebecdb41"&gt;Theming with React.js or any in minutes with CSS Variables&lt;/a&gt; by &lt;a href="https://medium.com/@harishv6665_49536"&gt;Harish V&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using React Context
&lt;/h2&gt;

&lt;p&gt;This one was hard for me to get it to work. &lt;br&gt;
&lt;a href="https://github.com/juzQrios/odin-weather-app/tree/react-dev"&gt;Here's how I got it to work&lt;/a&gt;&lt;br&gt;
Unfortunately I lost the link to the article I used to learn about this - fortunately I also used &lt;a href="https://reactjs.org/docs/context.html"&gt;React Context docs&lt;/a&gt; while learning it.&lt;br&gt;
I'll update this section as I think I understood this better&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Higher Order Components from other frameworks/libraries
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://styled-components.com/docs/advanced#theming"&gt;Styled Components&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/cssinjs/theming"&gt;CSSinJS Theming&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://material-ui.com/customization/theming/"&gt;Material UI theming&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Tools that I've used for Web Design &amp; Development so far</title>
      <dc:creator>Darshan J</dc:creator>
      <pubDate>Tue, 25 Feb 2020 14:33:14 +0000</pubDate>
      <link>https://dev.to/darshan_jayadev/tools-that-i-ve-used-for-web-design-development-so-far-2b5j</link>
      <guid>https://dev.to/darshan_jayadev/tools-that-i-ve-used-for-web-design-development-so-far-2b5j</guid>
      <description>&lt;p&gt;This is a list of my most used tool/software/websites for Web Design &amp;amp; Development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pen &amp;amp; Paper
&lt;/h2&gt;

&lt;p&gt;Nothing can beat a blank sheet of paper &amp;amp; pen, whatever it might be - design, coding, planning &amp;amp; everything in between.&lt;br&gt;
It is exactly because the page is blank that you can fill it with anything that you want, so next time when you stress over a software/website to choose for a task(like to-do list), ask yourself if you really need it and try using a blank paper/book instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Windows 10
&lt;/h2&gt;

&lt;p&gt;I use Windows 10 and not Linux although I do agree that Linux feels better for most web design/development needs. I use &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/about"&gt;WSL&lt;/a&gt;, which is quite slower than actually running tools on Linux but it gets the job done and also with upcoming &lt;a href="https://devblogs.microsoft.com/commandline/announcing-wsl-2/"&gt;WSL 2&lt;/a&gt; we can expect increased performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://www.microsoft.com/en-in/p/ubuntu/9nblggh4msv6?activetab=pivot:overviewtab"&gt;Ubuntu WSL&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;There are several distros available as wsl, I use this one&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://www.microsoft.com/en-in/p/windows-terminal-preview/9n0dx20hk701#activetab=pivot:overviewtab"&gt;Windows Terminal&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Nothing to say, terminal for using wsl over pre-installed command prompt.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://code.visualstudio.com/"&gt;VS Code&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;You probably use the same.&lt;/p&gt;

&lt;h3&gt;
  
  
  Web Browsers
&lt;/h3&gt;

&lt;p&gt;I use Chrome most of the time and occasionally new Edge and Firefox&lt;/p&gt;

&lt;h3&gt;
  
  
  Photo editing
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.gimp.org/"&gt;GIMP&lt;/a&gt; and &lt;a href="https://inkscape.org/"&gt;Inkscape&lt;/a&gt; to rarely edit photos for web.&lt;/p&gt;

&lt;h3&gt;
  
  
  Taking Notes
&lt;/h3&gt;

&lt;p&gt;Currently I use &lt;a href="https://paper.dropbox.com/"&gt;Dropbox Paper&lt;/a&gt; and thinking of moving to &lt;a href="https://www.onenote.com/"&gt;Onenote&lt;/a&gt; as note organization in it feels like a book.&lt;/p&gt;

&lt;h3&gt;
  
  
  Noise cancellation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://open.spotify.com/"&gt;Spotify&lt;/a&gt; - beware though as songs themselves might distract from the task at hand.&lt;br&gt;
&lt;a href="https://mynoise.net/"&gt;My Noise&lt;/a&gt; - Amazing website for noise cancellation.&lt;/p&gt;

&lt;p&gt;Here's my spotify &lt;a href="https://open.spotify.com/playlist/0xS39eBB3Im9fFFUB3QNzc?si=c9Tpt3x7SiuyBcjXCg51cw"&gt;Music&lt;/a&gt; playlist.&lt;/p&gt;

&lt;h3&gt;
  
  
  Picking Color/Theme for design
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://coolors.co/"&gt;Coolors&lt;/a&gt; that I recently used while designing my first &lt;a href="https://darshanjayadev.netlify.com/"&gt;portfolio webpage&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://color.adobe.com/create/color-wheel/"&gt;Adobe Color&lt;/a&gt; that I have been using for quite some time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other
&lt;/h3&gt;

&lt;p&gt;A lot of Google/Stack overflow/&lt;a href="https://developer.mozilla.org/en-US/"&gt;MDN&lt;/a&gt;/Youtube searches and blog/article reading complete my toolset.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to make API calls in Rails</title>
      <dc:creator>Darshan J</dc:creator>
      <pubDate>Tue, 17 Dec 2019 21:29:37 +0000</pubDate>
      <link>https://dev.to/darshan_jayadev/how-to-make-api-calls-in-rails-26l9</link>
      <guid>https://dev.to/darshan_jayadev/how-to-make-api-calls-in-rails-26l9</guid>
      <description>&lt;p&gt;I'll be using &lt;a href="https://openweathermap.org/"&gt;OpenWeather&lt;/a&gt; API in the below examples.&lt;/p&gt;

&lt;p&gt;Let's get started by creating a new rails app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails new weather-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install &lt;a href="https://lostisland.github.io/faraday/"&gt;Faraday&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Faraday is used to make HTTP requests to API&lt;br&gt;
Add this line to the top of your application's Gemfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem 'faraday'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Execute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bundle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Generate Controller &amp;amp; View for making API requests
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails g controller search index
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Now open &lt;code&gt;/config/routes.rb&lt;/code&gt; and replace &lt;code&gt;get 'search/index'&lt;/code&gt; with:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/search'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'search#index'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'search'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll be making API requests using this route and also display response on browser on the same route.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open &lt;code&gt;/app/views/search/index.html.erb&lt;/code&gt; and fill it with:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Search for world weather by location&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;

&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;form_with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;url: &lt;/span&gt;&lt;span class="n"&gt;search_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;method: &lt;/span&gt;&lt;span class="s2"&gt;"get"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;local: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;label_tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:location&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Enter Location name:"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;text_field_tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:location&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;submit_tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Search"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;

&lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@response&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="vi"&gt;@response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;body&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which gives us a form to enter a location whose weather data we can pull from OpenWeather. And in &lt;code&gt;if&lt;/code&gt; statement we have &lt;code&gt;@response&lt;/code&gt; variable which is set to response from API if we made a call in the controller.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create API service
&lt;/h2&gt;

&lt;p&gt;Now let's actually get into the process of making API request to OpenWeather.&lt;br&gt;
Although we have Faraday installed, it can't be directly called from within the controller.&lt;br&gt;
Create a new folder named &lt;code&gt;services&lt;/code&gt; inside &lt;code&gt;/app&lt;/code&gt;. Make sure not to change the name of the folder.&lt;br&gt;
Next add a ruby file in &lt;code&gt;/app/services&lt;/code&gt;, this file can be named anything you wish but the same name albeit capitalized should be used for the module inside it.&lt;/p&gt;

&lt;p&gt;I'll create &lt;code&gt;openweather.rb&lt;/code&gt; inside &lt;code&gt;/app/services&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;Openweather&lt;/span&gt;
  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Search&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;by_location&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="no"&gt;Faraday&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'https://api.openweathermap.org/data/2.5/weather?q='&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;'&amp;amp;appid='&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'API_KEY'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;end&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;p&gt;The class inside the module and the method inside the class can be named anything.&lt;/p&gt;

&lt;p&gt;From the code above, we can make out that - by calling &lt;code&gt;Openweather::Search.by_location&lt;/code&gt; method with a &lt;code&gt;location&lt;/code&gt; parameter would make an API call to OpenWeather, but what about &lt;code&gt;ENV['API_KEY']&lt;/code&gt;?&lt;br&gt;
We sure can replace &lt;code&gt;ENV['API_KEY']&lt;/code&gt; with actual API key provided by OpenWeather, but leaving an API key within code is not right. So, we are going to place our API key as an &lt;code&gt;Environment variable&lt;/code&gt;.&lt;br&gt;
First let's place API key as Environment variable in our local machine.&lt;br&gt;
To do this we'll be using &lt;a href="https://github.com/bkeepers/dotenv"&gt;Dotenv&lt;/a&gt; gem&lt;/p&gt;
&lt;h2&gt;
  
  
  Install &lt;a href="https://github.com/bkeepers/dotenv"&gt;Dotenv&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Add this line to the top of your application's Gemfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'dotenv-rails'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;groups: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:development&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:test&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then execute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bundle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now add a file named &lt;code&gt;.env&lt;/code&gt; to the root of your application. Make sure not to change the name of the file. Add your API key in the first line like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API_KEY=your_api_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;your_api_key&lt;/code&gt; with your actual key provided by OpenWeather.&lt;br&gt;
If your going to commit your work add &lt;code&gt;.env&lt;/code&gt; file to &lt;code&gt;.gitignore&lt;/code&gt;so that it is not tracked by git.&lt;/p&gt;
&lt;h2&gt;
  
  
  Call API service from the controller
&lt;/h2&gt;

&lt;p&gt;Now for the final part, add this to &lt;code&gt;index&lt;/code&gt; action of your controller &lt;code&gt;/app/controllers/search_controller.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'location'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="vi"&gt;@response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Openweather&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Search&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;by_location&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'location'&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;Make sure match the names of module, class and function that you named earlier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the result
&lt;/h2&gt;

&lt;p&gt;Now, open the server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And visit &lt;code&gt;http://localhost:3000/search&lt;/code&gt; from your browser.&lt;br&gt;
Search for a location to see the response.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
