<?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: Naoufal El hassnaoui</title>
    <description>The latest articles on DEV Community by Naoufal El hassnaoui (@naoufalelh).</description>
    <link>https://dev.to/naoufalelh</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%2F395069%2F0c88166b-2b4b-4e7e-9b58-095b297195bf.jpg</url>
      <title>DEV Community: Naoufal El hassnaoui</title>
      <link>https://dev.to/naoufalelh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/naoufalelh"/>
    <language>en</language>
    <item>
      <title>Personal branding for engineers: part 1</title>
      <dc:creator>Naoufal El hassnaoui</dc:creator>
      <pubDate>Tue, 15 Dec 2020 21:28:02 +0000</pubDate>
      <link>https://dev.to/naoufalelh/personal-branding-for-engineers-part-1-13n2</link>
      <guid>https://dev.to/naoufalelh/personal-branding-for-engineers-part-1-13n2</guid>
      <description>&lt;p&gt;Not everyone is talking about the fact that as an engineer you need a personal brand. This is something we can say not only for software engineers or developers, but everyone in the world needs a personal brand. Whatever your job, you need a personal brand, why? To tell you why you need a personal brand, we first need to define personal branding, then we can talk about why you need a personal brand.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is personal branding?
&lt;/h2&gt;

&lt;p&gt;The Wikipedia answer:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Personal branding&lt;/strong&gt; is the conscious and intentional effort to create and influence public perception of an individual by positioning them as an authority in their industry, elevating their credibility, and differentiating themselves from the competition, to ultimately advance their career, increase their circle of influence, and have a larger impact.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/garyvee"&gt;@GaryVee&lt;/a&gt;'s answer &lt;em&gt;Gary Vaynerchuk is CEO of @Vaynermedia. @VaynerSports @Empathywines. Investor in Twitter, Uber, FB.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Your personal brand is your &lt;strong&gt;reputation&lt;/strong&gt;. And your reputation in perpetuity is the foundation of your career.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;My answer is quite the same as Gary, I think personal branding is working on your reputation to build your career around it. Working on your reputation should be a long-term goal, not a short-term one. Don't expect results in the first weeks/months or even years.&lt;/p&gt;

&lt;p&gt;Most people don't get this! They want to convert customers on the first day. This is the short-term thing I was talking about, trying to extract money from your blog viewers or your audience in LinkedIn, this is what we call being impatient.&lt;/p&gt;

&lt;p&gt;For example, if I was impatient, I will publish a book next week titled "Personal Branding For Engineers" and I will try to use this blog and my other social media accounts to sell you this book. The problem here is that I wanted to convert you, the reader of my blog posts, to a customer directly from the first interaction.&lt;/p&gt;

&lt;p&gt;The right way to do the conversion is to create a great experience, give you a lot of free value, then say that I'm selling a book about personal branding that you may be interested in. My goal in this example was to create a reputation first as someone who can help you build your personal brand, someone who is giving you value every time you read something he wrote.&lt;/p&gt;

&lt;p&gt;To explain this a little bit more, I would bring Apple to the table. Apple never tries to sell you an iPhone directly they have built a reputation of a great iPhone experience that will make you buy an iPhone without them trying to sell it to you.&lt;/p&gt;

&lt;p&gt;Personal branding for engineers is a bit different, you are not trying to sell a product, but you are trying to sell your profile to get hired (no matter what the contract is, independent, full-time, part-time ... ).&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I should care about my personal brand?
&lt;/h2&gt;

&lt;p&gt;First, you will need to sit with yourself and think about your long-term goals, you want to get a better job, you want to get a job, you want to sell your services as a consultant for example.&lt;/p&gt;

&lt;p&gt;To achieve your goals in the long-term, the best way to do it is to build a personal brand, a good image, a reputation in the world. When you are known in your community as someone kind, honest, and helpful. People will look forward to doing business with you or hire you, because of your reputation.&lt;/p&gt;

&lt;h2&gt;
  
  
  How can I build a personal brand?
&lt;/h2&gt;

&lt;p&gt;The question you should ask yourself is how can you build a good reputation? in reality and the internet.&lt;/p&gt;

&lt;p&gt;In reality, be a good person, helpful, give more than you take. Help your community and people in need. Share your experience with them, they will get value from it for sure.&lt;/p&gt;

&lt;p&gt;On the internet, building a good reputation is almost the same as in reality, but through social media platforms. Your presence on these platforms and how you use them is very important to your personal brand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is how you can achieve this:&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Document over create
&lt;/h3&gt;

&lt;p&gt;Creating content in social media is a very difficult task. The solution is to document your journey, vlogging is a good example, you share part of what you are doing when you are doing it.&lt;/p&gt;

&lt;p&gt;If you are an expert you will be able to create valuable content because you have the expertise in some fields that others don't, which makes you in a good position to create content.&lt;/p&gt;

&lt;p&gt;Don't put yourself as an expert if you are not one! You have seen an Instagram profile with "e-commerce expert" in the bio, but when you read their posts, you find that they are just trying to sell you something without giving you "the iPhone experience" we talked about.&lt;/p&gt;

&lt;p&gt;If they are experts like they say, they should first put out free, valuable content, they can create real content that will help you in the e-commerce world for free. After they have built a reputation you will go and buy their services without them selling them to you directly.&lt;/p&gt;

&lt;p&gt;When you don't have the experience, you should not try to create content the way experts will do, you should instead document your journey to becoming an expert in your field, by sharing about what you are currently learning, what problems you are currently facing, and how you are trying to solve them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Be yourself, 100% yourself, don't fake it till you make it!
&lt;/h3&gt;

&lt;p&gt;"Fake it till you make it" is a really bad practice for personal branding. Be yourself and show your true self. Show what you really like to do, no need to show a fancy life, show your true life experience, be authentic!&lt;/p&gt;

&lt;p&gt;"Fake" people don't last long, our goal is to last (long-term over short-term) that's why we need to be authentic and only show our true selves to the world.&lt;/p&gt;

&lt;p&gt;Don't lie to your followers!&lt;/p&gt;

&lt;p&gt;This first part was an introduction to personal branding not just for engineers but you can tell that this advice is for everyone who is looking for building a personal brand, a good reputation, and who is focusing on long-term goals.&lt;/p&gt;

&lt;p&gt;In the next parts of this series about personal branding, we will go through each platform and how to use it with a focus on engineers, developers, and consultants.&lt;/p&gt;

&lt;p&gt;I hope that I provided you today with some free valuable content as part of me building my personal brand and documenting my journey as a software engineer.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What to do when you get stuck on a problem?</title>
      <dc:creator>Naoufal El hassnaoui</dc:creator>
      <pubDate>Tue, 08 Dec 2020 13:24:28 +0000</pubDate>
      <link>https://dev.to/naoufalelh/what-to-do-when-you-get-stuck-on-a-problem-2oen</link>
      <guid>https://dev.to/naoufalelh/what-to-do-when-you-get-stuck-on-a-problem-2oen</guid>
      <description>&lt;p&gt;A very useful tip for developers&lt;/p&gt;

&lt;p&gt;When you are stuck trying to fix something but you passed many hours working on it but still you don’t know the source of the problem/error … you checked the logs and still nothing, try this:&lt;/p&gt;

&lt;p&gt;Go! leave it for a bit of time, I’m not saying take a break, because you should take a break that’s for your health, but what you should try, is leave the issue and work on another thing ;) Use your mind to work on something totally different to the issue for a few minutes or hours, then get back to the original problem and you will just easily find the source of the problem then the solution as simple as that! It’s like when someone needs some “space” to breathe.&lt;/p&gt;

&lt;p&gt;I used this technique many times and it really helped me solve some problems. Sometimes we are just tired not physically but our minds are tired from working on the same thing! Give you mind some space let it breathe. When you succeed at doing something else your mind feels that it is better and can solve more problems than before.&lt;/p&gt;

&lt;p&gt;Try this technique and see if it works for you :)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A Ruby On Rails Active Storage Cheatsheet</title>
      <dc:creator>Naoufal El hassnaoui</dc:creator>
      <pubDate>Tue, 26 May 2020 22:48:48 +0000</pubDate>
      <link>https://dev.to/naoufalelh/a-ruby-on-rails-active-storage-cheatsheet-4120</link>
      <guid>https://dev.to/naoufalelh/a-ruby-on-rails-active-storage-cheatsheet-4120</guid>
      <description>&lt;h1&gt;
  
  
  Rails Active Storage Cheatsheet
&lt;/h1&gt;

&lt;p&gt;Without an introduction, here is the table of content:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Rails Active Storage Cheatsheet

&lt;ul&gt;
&lt;li&gt;Install Active Storage&lt;/li&gt;
&lt;li&gt;Usage&lt;/li&gt;
&lt;li&gt;Model&lt;/li&gt;
&lt;li&gt;Controller&lt;/li&gt;
&lt;li&gt;Views (in ERB)&lt;/li&gt;
&lt;li&gt;
Display Image and its variants or Preview (PDF or Video)

&lt;ul&gt;
&lt;li&gt;Install this libraries first&lt;/li&gt;
&lt;li&gt;Display an image (when document is an image)&lt;/li&gt;
&lt;li&gt;Generate a variant of an image with &lt;code&gt;variant&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Generate a preview with &lt;code&gt;preview&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Don't know the type of document? Use &lt;code&gt;representation&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Content type and size&lt;/li&gt;
&lt;li&gt;Attach a local file&lt;/li&gt;
&lt;li&gt;Validation with activestorage-validator gem&lt;/li&gt;
&lt;li&gt;Select all records with an attachment&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Install Active Storage
&lt;/h2&gt;

&lt;p&gt;Only for Rails version 5.2 and up (Rails 5.2.X &amp;amp; Rails 6.X.X).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Run migration
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;We will use User model with attachment(s) name document(s), this document can be an image or PDF or video or any other type.&lt;/p&gt;

&lt;h3&gt;
  
  
  Model
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One attachment&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;

  &lt;span class="n"&gt;has_one_attached&lt;/span&gt; &lt;span class="ss"&gt;:document&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;strong&gt;Many attachments&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;

  &lt;span class="n"&gt;has_many_attached&lt;/span&gt; &lt;span class="ss"&gt;:documents&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Controller
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One attachment&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UsersController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
  &lt;span class="c1"&gt;# your controller methods (index, show ...).&lt;/span&gt;
  &lt;span class="kp"&gt;private&lt;/span&gt;

  &lt;span class="c1"&gt;# Only allow a list of trusted parameters through.&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;user_params&lt;/span&gt;
    &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:yser&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;permit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:last_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:document&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Many attachments&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UsersController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
  &lt;span class="c1"&gt;# your controller methods (index, show ...).&lt;/span&gt;
  &lt;span class="kp"&gt;private&lt;/span&gt;

  &lt;span class="c1"&gt;# Only allow a list of trusted parameters through.&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;user_params&lt;/span&gt;
    &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:user&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;permit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:last_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;documents: &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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Views (in ERB)
&lt;/h3&gt;

&lt;p&gt;Form filed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One attachment&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;file_field&lt;/span&gt; &lt;span class="ss"&gt;:document&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Many attachments&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;file_field&lt;/span&gt; &lt;span class="ss"&gt;:documents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;multiple: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Display Image and its variants or Preview (PDF or Video)
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Install this libraries first
&lt;/h4&gt;

&lt;p&gt;First to generate &lt;strong&gt;variants&lt;/strong&gt; and &lt;strong&gt;previews&lt;/strong&gt; of PDFs and videos, you will need to :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add &lt;code&gt;gem 'image_processing', '~&amp;gt; 1.2'&lt;/code&gt; to your Gemfile.&lt;/li&gt;
&lt;li&gt;Install &lt;a href="https://imagemagick.org/script/download.php"&gt;MiniMagick&lt;/a&gt; for image variants.&lt;/li&gt;
&lt;li&gt;To generate previews of PDFs, install &lt;a href="https://poppler.freedesktop.org"&gt;Poppler&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;To generate previews of Videos, install &lt;a href="https://www.ffmpeg.org/download.html"&gt;FFmpeg&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Display an image (when document is an image)
&lt;/h4&gt;

&lt;p&gt;To check if there is an image attached before displaying it use:&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;attached?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One attachment&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&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="nf"&gt;attached?&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;image_tag&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;document&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Many attachments&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At least one document is attached&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;attached?&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="o"&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;image_tag&lt;/span&gt; &lt;span class="n"&gt;document&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;end&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Generate a variant of an image with &lt;code&gt;variant&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Don't forget &lt;code&gt;user.document&lt;/code&gt; should be an &lt;strong&gt;image&lt;/strong&gt; in this case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;image_tag&lt;/span&gt; &lt;span class="n"&gt;user&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="nf"&gt;variant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;resize_to_limit: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;75&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;75&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="nf"&gt;processed&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;.processed&lt;/code&gt; method will store the variant for performance reasons.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For more variant transformations check &lt;a href="https://github.com/janko/image_processing#installation"&gt;image_processing docs&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Generate a preview with &lt;code&gt;preview&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;For PDFs or videos.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&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="nf"&gt;previewable?&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;image_tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&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="nf"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;resize: &lt;/span&gt;&lt;span class="s1"&gt;'200x200'&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;.previewable?&lt;/code&gt; method will check if you can create a preview of the document attached.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Don't know the type of document? Use &lt;code&gt;representation&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&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="nf"&gt;representable?&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;image_tag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&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="nf"&gt;representation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;resize: &lt;/span&gt;&lt;span class="s1"&gt;'200x200'&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;.representable?&lt;/code&gt; method will check if you can create a preview or a variant of the document attached.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Content type and size
&lt;/h3&gt;

&lt;p&gt;Document attachment content type:&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;user&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="nf"&gt;content_type&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Video attachment file size:&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;video&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;byte_size&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Attach a local file
&lt;/h3&gt;

&lt;p&gt;In tests for example we want to be able to save/attach local files in Active Storage.&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;picture&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;attach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;io: &lt;/span&gt;&lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/path/to/file'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="ss"&gt;filename: &lt;/span&gt;&lt;span class="s1"&gt;'my_picture.png'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Validation with activestorage-validator gem
&lt;/h3&gt;

&lt;p&gt;To install &lt;a href="https://github.com/aki77/activestorage-validator"&gt;activestorage-validator&lt;/a&gt; gem add in 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;'activestorage-validator'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use this gem, in your model add:&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;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;has_one_attached&lt;/span&gt; &lt;span class="ss"&gt;:avatar&lt;/span&gt;
  &lt;span class="n"&gt;has_many_attached&lt;/span&gt; &lt;span class="ss"&gt;:photos&lt;/span&gt;

  &lt;span class="n"&gt;validates&lt;/span&gt; &lt;span class="ss"&gt;:avatar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;presence: &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;blob: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;content_type: :image&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;# supported options: :image, :audio, :video, :text&lt;/span&gt;
  &lt;span class="n"&gt;validates&lt;/span&gt; &lt;span class="ss"&gt;:photos&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;presence: &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;blob: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;content_type: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'image/png'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'image/jpg'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'image/jpeg'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="ss"&gt;size_range: &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;megabytes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;# validates :photos, presence: true, blob: { content_type: %r{^image/}, size_range: 1..5.megabytes }&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Select all records with an attachment
&lt;/h3&gt;

&lt;p&gt;From the comment in this &lt;a href="https://github.com/rails/rails/issues/32295#issuecomment-374304126"&gt;issue&lt;/a&gt; in Rails repository in Github.&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="c1"&gt;# Assuming a model defined like so:&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;has_one_attached&lt;/span&gt; &lt;span class="ss"&gt;:image&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# ...you can join against :image_attachment to select posts having attached images:&lt;/span&gt;
&lt;span class="no"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;joins&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:image_attachment&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'published_at &amp;gt;= ?'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;Time&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;I posted this originally in Github as a Gist: &lt;a href="https://gist.github.com/naoufalelh/d49944fb8f9bdac94bdba5d1aae15b10"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Deno 1.0 What ? NodeJS is dead ? are you serious ?</title>
      <dc:creator>Naoufal El hassnaoui</dc:creator>
      <pubDate>Mon, 25 May 2020 21:12:00 +0000</pubDate>
      <link>https://dev.to/naoufalelh/deno-1-0-what-nodejs-is-dead-are-you-serious-26pa</link>
      <guid>https://dev.to/naoufalelh/deno-1-0-what-nodejs-is-dead-are-you-serious-26pa</guid>
      <description>&lt;p&gt;Two years ago the creator of NodeJS Ryan Dahl announced Deno a secure runtime for JavaScript and TypeScript, in this &lt;a href="https://www.youtube.com/watch?v=M3BM9TB-8yA"&gt;talk&lt;/a&gt;  where he talked about the 10 things he regret about NodeJS and in the end of the talk he presented Deno and the motives behind it, why he is building this new JS runtime.&lt;/p&gt;

&lt;p&gt;The 13 of May Deno 1.0 was released (here is the official &lt;a href="https://deno.land/v1"&gt;blog post&lt;/a&gt;). By the end of the day every tech blog was sharing blog posts about Deno and some developers even started saying NodeJS is dead! like are you serious guys ?!&lt;/p&gt;

&lt;p&gt;This is what we always see in the tech community when a new technology come to life the next day every other technology is dead, just take a second and remember how React Native was dead after announcing the first version of Flutter, since that and React Native continue to improve day by day and nothing is dead but the blog post about it :D&lt;/p&gt;

&lt;p&gt;The short answer is &lt;strong&gt;NO!&lt;/strong&gt; NodeJS is not dead and won’t be anytime soon, a lot of companies use it in production and the community around NodeJS is really big.&lt;br&gt;
In the other side Deno come with a lot of improvements (which this post is about) so let’s talk about that now.&lt;/p&gt;

&lt;p&gt;Here is a quick list of Deno features :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is based on "modern" JS features.&lt;/li&gt;
&lt;li&gt;It has TypeScript at its core, this may help it gain popularity, you don’t have to separately compile TypeScript, it’s automatically done by Deno.&lt;/li&gt;
&lt;li&gt;It embraces ES modules.&lt;/li&gt;
&lt;li&gt;It has no package manager.&lt;/li&gt;
&lt;li&gt;It has a first-class await.&lt;/li&gt;
&lt;li&gt;It aims to be browser-compatible as much as it can, for example by providing a built-in fetch and the global window object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What I find cool about Deno, is the TypeScript support out of the box. As we see nowadays TypeScript is getting more popular than ever which will help Deno gain popularity, of course let’s not forget about the security improvements.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Finaly, I hope to not see an HR agent posting “Hiring! Senior Deno developer with +3 years of exp ONLY”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Feel free to leave your opinion on this in the comments section ;)&lt;/p&gt;

&lt;p&gt;I post my thoughts in my &lt;a href="https://www.linkedin.com/in/naoufalelh/"&gt;LinkedIn profile&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Sources:&lt;br&gt;
&lt;a href="https://deno.land"&gt;https://deno.land&lt;/a&gt;&lt;br&gt;
&lt;a href="https://deno.land/v1"&gt;https://deno.land/v1&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.freecodecamp.org/news/the-deno-handbook/#will-it-replace-node-js"&gt;https://www.freecodecamp.org/news/the-deno-handbook/#will-it-replace-node-js&lt;/a&gt;&lt;/p&gt;

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