<?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: Fred B.</title>
    <description>The latest articles on DEV Community by Fred B. (@boostup).</description>
    <link>https://dev.to/boostup</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%2F453613%2Fe6654e99-3421-4191-97e4-2aabf44c1e1d.png</url>
      <title>DEV Community: Fred B.</title>
      <link>https://dev.to/boostup</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/boostup"/>
    <language>en</language>
    <item>
      <title>Uncaught ReferenceError: process is not defined</title>
      <dc:creator>Fred B.</dc:creator>
      <pubDate>Sun, 20 Aug 2023 15:42:10 +0000</pubDate>
      <link>https://dev.to/boostup/uncaught-referenceerror-process-is-not-defined-12kg</link>
      <guid>https://dev.to/boostup/uncaught-referenceerror-process-is-not-defined-12kg</guid>
      <description>&lt;h2&gt;
  
  
  How to solve the following error ?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uncaught ReferenceError: process is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, this happens when, in your &lt;a href="https://vitejs.dev/guide/"&gt;Vite/React project&lt;/a&gt;, you add a code equivalent to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const someValue = process.env.SOME_KEY;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In other words, you're simply trying to read a value from your &lt;code&gt;.env&lt;/code&gt; file, which includes assignments similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SOME_KEY=A_VERY_IMPORTANT_VALUE_YOU_NEED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Solving this issue
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open the &lt;code&gt;vite.config.ts&lt;/code&gt; file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add &lt;code&gt;loadEnv&lt;/code&gt; in your imports: &lt;br&gt;
&lt;code&gt;import { defineConfig, loadEnv } from 'vite'&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add an &lt;code&gt;env&lt;/code&gt; const assigment: &lt;br&gt;
&lt;code&gt;const env = loadEnv(mode, process.cwd(), '');&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;add a &lt;code&gt;define&lt;/code&gt; object at the same level than the &lt;code&gt;plugins&lt;/code&gt; array:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return {
    define: {
      'process.env.SOME_KEY': JSON.stringify(env.SOME_KEY)
    },
    plugins: [react()],
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Complete code
&lt;/h2&gt;

&lt;p&gt;Now, here's the &lt;code&gt;before&lt;/code&gt; &amp;amp; &lt;code&gt;after&lt;/code&gt; code.&lt;/p&gt;

&lt;h3&gt;
  
  
  The &lt;code&gt;vite.config.ts&lt;/code&gt; file before:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  the &lt;code&gt;vite.config.ts&lt;/code&gt; file after:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) =&amp;gt; {
  const env = loadEnv(mode, process.cwd(), '');
  return {
    define: {
      'process.env.SOME_KEY': JSON.stringify(env.SOME_KEY)
    },
    plugins: [react()],
  }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Some final notes
&lt;/h2&gt;

&lt;p&gt;So, if your like me, you'd be like: "but, wait a minute! Am I gonna have to manually write every single new key/value pair in the &lt;code&gt;.env&lt;/code&gt; file, AND repeat myself in the &lt;code&gt;vite.config.ts&lt;/code&gt; ?"  &lt;/p&gt;

&lt;p&gt;Well...this is exactly what this solution implies! I'm not happy about this, but at least it is a solution.&lt;/p&gt;

&lt;p&gt;Why is is important to have this solution?  Well because the CI/CD process on Netlify would fail because of the &lt;code&gt;Uncaught ReferenceError: process is not defined&lt;/code&gt; error.&lt;/p&gt;

&lt;h3&gt;
  
  
  Alternative solution:
&lt;/h3&gt;

&lt;p&gt;If you wish to avoid having to repeat the name of the keys in the &lt;code&gt;vite.config.ts&lt;/code&gt; file, you could have the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) =&amp;gt; {
  const env = loadEnv(mode, process.cwd(), '');
  return {
    define: {
      'process.env': env
    },
    plugins: [react()],
  }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Disclaimer
&lt;/h4&gt;

&lt;p&gt;You might not wish to expose the entire contents of &lt;code&gt;process.env&lt;/code&gt; to the front end, so manually picking the keys/names of the values you wish to get access to in the front, becomes an sort of &lt;code&gt;security&lt;/code&gt; device...&lt;/p&gt;

&lt;p&gt;Also, notice that in the &lt;code&gt;after&lt;/code&gt; code suggested where you do manually pick them, you might or might not have to &lt;code&gt;stringify&lt;/code&gt; the selected keys' values.&lt;/p&gt;

&lt;h2&gt;
  
  
  A better alternative solution perhaps
&lt;/h2&gt;

&lt;p&gt;I guess a solution somewhere in the middle would be to have an array containaing the name of the keys you wish to cherrypick from the &lt;code&gt;process.env&lt;/code&gt;, and then loop over it, so as to dynamically generate the object that is assigned to the &lt;code&gt;define&lt;/code&gt; key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'

const cherryPickedKeys = [
  "SOME_KEY_IN_YOUR_ENV_FILE",
  "SOME_OTHER_KEY_IN_YOUR_ENV_FILE",
];

// https://vitejs.dev/config/
export default defineConfig(({ mode }) =&amp;gt; {
  const env = loadEnv(mode, process.cwd(), '');
  const processEnv = {};
  cherryPickedKeys.forEach(key =&amp;gt; processEnv[key] = env[key]);

  return {
    define: {
      'process.env': processEnv
    },
    plugins: [react()],
  }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final notes for TypeScript
&lt;/h2&gt;

&lt;p&gt;If your project is in Typescript, an intellisense problem will pop up, which will also have the CI/CD process fail:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.ts(2580)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And indeed, the solution to install the &lt;code&gt;@types/node&lt;/code&gt; package, as suggested by VS Code, works and the problem goes away !&lt;/p&gt;

</description>
      <category>vite</category>
      <category>react</category>
      <category>environment</category>
      <category>variables</category>
    </item>
    <item>
      <title>The Flux architectural pattern using useReducer, the Context API, and Sagas</title>
      <dc:creator>Fred B.</dc:creator>
      <pubDate>Sat, 07 Nov 2020 17:40:18 +0000</pubDate>
      <link>https://dev.to/boostup/the-flux-architectural-pattern-using-usereducer-the-context-api-and-sagas-8ie</link>
      <guid>https://dev.to/boostup/the-flux-architectural-pattern-using-usereducer-the-context-api-and-sagas-8ie</guid>
      <description>&lt;p&gt;Just in case, here is a nice diagram about the generic Flux pattern in React.&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%2Fck4cgie4y8mdr7iefxtt.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%2Fck4cgie4y8mdr7iefxtt.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  So, why am I writing about this?
&lt;/h2&gt;

&lt;p&gt;It demonstrates the combination of :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Context&lt;/code&gt; API and &lt;code&gt;useContext&lt;/code&gt; hook&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useReducer&lt;/code&gt; hook&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/use-react-saga" rel="noopener noreferrer"&gt;&lt;code&gt;useReactSaga&lt;/code&gt; custom hook&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a href="https://confident-turing-f05f43.netlify.app/" rel="noopener noreferrer"&gt;Demo Link&lt;/a&gt; | &lt;a href="https://github.com/boostup/react-context-api-multiple-reducers-mulitple-sagas" rel="noopener noreferrer"&gt;GitHub Repo&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  But why, you ask ?
&lt;/h2&gt;

&lt;p&gt;Because I can ;)&lt;/p&gt;

&lt;p&gt;No, but seriously, because I needed to make sense of Redux, of the Context API, and more generally, the Flux Pattern, and of async actions.&lt;/p&gt;

&lt;p&gt;Also, to me, it is important to understand as many React functions or third-party packages as I include in my apps, and &lt;code&gt;useContext&lt;/code&gt; and &lt;code&gt;useReducer&lt;/code&gt; being shipped defacto with React is a plus, versus having to include a whole bunch of packages that revolve around the Redux ecosystem.&lt;/p&gt;

&lt;p&gt;So this demo allows to demonstrate that the &lt;code&gt;redux&lt;/code&gt; and &lt;code&gt;react-redux&lt;/code&gt; packages are no longer required dependencies to implement the Flux Pattern in React, in a way that makes both sense and is scalable with combined reducers to handle endless future slices of state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Word of caution
&lt;/h2&gt;

&lt;p&gt;What this demo does not demonstrate though, is if this combination mimicking redux will be as performant as redux.&lt;br&gt;
And this, I do not know myself, as this is very experimental. I wouldn't recommend using this in production ;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Notes
&lt;/h2&gt;

&lt;p&gt;This demo depends on a tiny package called &lt;code&gt;use-react-saga&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;All it is, is a custom hook for React which depends on the &lt;code&gt;redux-saga&lt;/code&gt; package, which is something I wanted to experiment with as the next natural evolution step after &lt;code&gt;redux-thunk&lt;/code&gt;, for async actions.&lt;/p&gt;




&lt;h2&gt;
  
  
  Addendum
&lt;/h2&gt;

&lt;p&gt;After the perusal of the installed packages in the &lt;code&gt;node_modules&lt;/code&gt; directory, I have come to realize that there is a &lt;code&gt;redux&lt;/code&gt; directory in there!! After perusing the &lt;code&gt;yarn.lock&lt;/code&gt; file, &lt;code&gt;redux-saga&lt;/code&gt; packages has it as a dependency.&lt;/p&gt;

&lt;p&gt;So this demo does NOT unfortunately demonstrate that adding Redux as a dependency can be avoided. Fortunately, it is only &lt;a href="https://www.npmjs.com/package/redux" rel="noopener noreferrer"&gt;2kB, including dependencies&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;So this demo only goes to shows how &lt;strong&gt;unavoidable&lt;/strong&gt; &lt;code&gt;redux&lt;/code&gt; is when it comes to making stable apps ;)&lt;/p&gt;

&lt;p&gt;In the particular case of this demo, if I wish to remove it as a dependency, I must implement Sagas myself. Is it worth it ? I'll leave it up to you to decide.&lt;/p&gt;

&lt;p&gt;Finally, I should mention that I do not hold a grudge against Redux, I just wanted to evaluate the Context API as a potential replacement, since we see so many articles on this topic, but they all show very small unscalable demos or POCs which were never convincing to me.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>CSS Cheat Sheet</title>
      <dc:creator>Fred B.</dc:creator>
      <pubDate>Wed, 04 Nov 2020 15:19:44 +0000</pubDate>
      <link>https://dev.to/boostup/css-cheat-sheet-1d2j</link>
      <guid>https://dev.to/boostup/css-cheat-sheet-1d2j</guid>
      <description>&lt;h2&gt;
  
  
  Misc.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;transform: translate&lt;/code&gt; instead of top, left, right, bottom positioning, especially when animating&lt;/li&gt;
&lt;li&gt;&lt;code&gt;box-sizing: border-box;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;object-fit: contain; /* maintains aspect ratio */&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;place-items: center;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;user-select: none;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pointer-events: none;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;height: 20vw;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;box-shadow: 0 4px 60px rgba(0, 0, 0, 0.5);&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body::-webkit-scrollbar {
  /* NICE TRICK : it hides the scrollbar, but the scrolling behavior is maintained*/
  display: none;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Media Queries
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Targeting Touch devices
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* For touch devices */
@media (hover: none) {
  .mainLayout__sidebar {
    padding-bottom: var(--main-layout-footer-height);
  }

  .mainLayout__body {
    height: calc(100vh - var(--main-layout-footer-height));
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Grid &amp;amp; Flex layouts
&lt;/h2&gt;

&lt;p&gt;For those landing here looking for a way to have a sort of dynamic table, with items wrapping to new rows, and still being aligned across rows, a pretty good solution is to use flex with flex-wrap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CSS custom variables
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
  --main-font-color: white;
  --main-theme-color: 0, 0, 0;
  --main-background-color: 4, 4, 4;
  --main-interactive-text-color: #b3b3b3;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CSS animation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.someClass{
  animation: name duration timing-function delay iteration-count direction fill-mode;
}

@keyframes wheel {
  from {
    transform: rotateZ(0deg);
  }
  to {
    transform: rotateZ(360deg);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  REM units
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10px = 0.625rem
12px = 0.75rem
14px = 0.875rem
16px = 1rem (base)
18px = 1.125rem
20px = 1.25rem
24px = 1.5rem
30px = 1.875rem
32px = 2rem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;html { 
  font-size: 16px; 
}

h1 { 
  font-size: 2rem;          /* 32px */
}

p { 
  font-size: 1rem;          /* 16px */ 
}

li { 
  font-size: 1.5em;         /* 24px */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://youtu.be/CxC925yUxSI?t=1168"&gt;https://youtu.be/CxC925yUxSI?t=1168&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;html {
  font-size: 62.5%; /* This makes a better base for REM units AND for accessibilty font adaptation*/
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

</description>
    </item>
    <item>
      <title>The tribulations of React performance optimizations </title>
      <dc:creator>Fred B.</dc:creator>
      <pubDate>Tue, 13 Oct 2020 08:51:33 +0000</pubDate>
      <link>https://dev.to/boostup/the-tribulations-of-react-performance-optimizations-1i2k</link>
      <guid>https://dev.to/boostup/the-tribulations-of-react-performance-optimizations-1i2k</guid>
      <description>&lt;p&gt;As I see it occuring so many times in the industry, it so happens that many developers do anticipate performance issues while still in early development stages of an application project. &lt;/p&gt;

&lt;p&gt;And this, even prior to running the app on a production-like environment ! &lt;/p&gt;

&lt;p&gt;This strategy often ends up being the same as shooting oneself in the foot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why you say? Because optimizations always come with a cost!&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Use case: code-splitting
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Is spreading the total loading time of the app always a good idea? Is splitting the code and lazy-loading the different chunks, always a good solution? Every time? No matter what?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Well:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Are those chunks really heavy enough to justify having the &lt;a href="https://www.businessinsider.fr/us/how-to-stop-spinning-wheel-on-mac"&gt;&lt;em&gt;spinning wheel of death&lt;/em&gt;&lt;/a&gt; appear everytime the user clicks on a link?&lt;/li&gt;
&lt;li&gt;Or should you rather have an app displaying a longer intial loading time but which, once fully loaded and cached, responds swiftly to all user interactions?&lt;/li&gt;
&lt;li&gt;Are your end users from the general public, or are they B2B customers? Sure users in general don't like to wait of course, nobody does, however:

&lt;ul&gt;
&lt;li&gt;B2B users might not have a choice than to be using your app, so if there is no budget for optimization, then intial loading time can be "&lt;em&gt;imposed&lt;/em&gt;" upon them with minimal business repercussions;&lt;/li&gt;
&lt;li&gt;On the other hand, public users, C2B users, WILL go away and shop somewhere else if your e-commerce app takes too long to load, having a real impact on business revenue in the short or medium term&lt;/li&gt;
&lt;/ul&gt;


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

&lt;h2&gt;
  
  
  What to look out for
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;After a hard reload, meaning you got rid of all cached elements, and after applying a given optimization, is the app starting faster during its initial render?
&lt;/li&gt;
&lt;li&gt;Is this really the only criteria to consider ?&lt;/li&gt;
&lt;li&gt;What are you trying to achieve?

&lt;ul&gt;
&lt;li&gt;Do you want users to feel that your app loads fast? &lt;/li&gt;
&lt;li&gt;Do you want the app to respond quickly to user interaction? &lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;strong&gt;Sure! We all want both, but again, at what cost?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But most importantly : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;does it depend only on what YOU want or think as a developer ?
&lt;/li&gt;
&lt;li&gt;what if the target machine is a smartphone, can you afford to have many http requests, knowing how it impacts battery life ?&lt;/li&gt;
&lt;li&gt;what if there is no budget for optimization ?&lt;/li&gt;
&lt;li&gt;what is the hosting plan in production, and what is the cost related to hitting your server by an increased amount of http requests ?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  So what is the solution?
&lt;/h2&gt;

&lt;p&gt;We must be able to evaluate the cost of the optimization by clearly identifying what was lost and what was gained. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It's all about the tradeoffs baby!&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step #1 - Diagnose
&lt;/h3&gt;

&lt;p&gt;So, let's first run the app we are working on, and IF we find that the app starts too slowly, or a certain component takes too much time to mount or render, THEN let's diagnose the problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How?&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;a href="https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi"&gt;React devtools Profiler&lt;/a&gt; or the &lt;a href="https://reactjs.org/docs/profiler.html#usage"&gt;React Profiler API&lt;/a&gt; are examples of a tools which might help identifying long re-rendering times.&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://developers.google.com/web/tools/chrome-devtools/network"&gt;network devtools&lt;/a&gt; might also help identifying heavy JS or CSS resources.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The build report provided by the &lt;a href="https://create-react-app.dev/docs/production-build"&gt;create-react-app build script&lt;/a&gt; also provides a list of chunks along with their gzip file size &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YpYSVKjk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xhwfjnq8h4xbzugzsqrg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YpYSVKjk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xhwfjnq8h4xbzugzsqrg.png" alt="Alt Text" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And let's not forget the almighty &lt;a href="https://developers.google.com/web/tools/lighthouse"&gt;Lighthouse&lt;/a&gt;, another one of the Chrome devtools.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step #2 - Measure
&lt;/h3&gt;

&lt;p&gt;So let's measure the problem. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How much time do components take to mount or render? &lt;/li&gt;
&lt;li&gt;How much time is a function taking to run ? &lt;/li&gt;
&lt;li&gt;Is there some JS or CSS resource blocking the intial app rendering ?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check out &lt;a href="https://houssein.me/progressive-react"&gt;Progressive React&lt;/a&gt; for details on measuring using different tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step #3 - Identify &amp;amp; Apply optimization
&lt;/h3&gt;

&lt;p&gt;After diagnosis and measurement, the right optimization strategy should form.  This allows to identify the appropriate optimization technique(s) for the particular situation we're trying to solve. So, here's when we apply an initial solution.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step #4 - Measure again &amp;amp; Compare
&lt;/h3&gt;

&lt;p&gt;Lastly, let's measure once again to ensure that the optimization cost was worthwhile.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How?&lt;/strong&gt; By comparing the new measure to the original measure, the one we took while diagnosing the problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;All in all, these are examples &lt;em&gt;only&lt;/em&gt; of considerations to take into account even &lt;em&gt;before&lt;/em&gt; we start optimizing just for the sake of it.&lt;/p&gt;

&lt;p&gt;The right optimization strategy is far from being a "simple"  &lt;em&gt;technical-only&lt;/em&gt; subject, and depends &lt;em&gt;at least&lt;/em&gt; on: &lt;/p&gt;

&lt;p&gt;1) budget,&lt;br&gt;
2) the nature of the app,&lt;br&gt;
3) end users (&amp;amp; stakeholders at large),&lt;br&gt;
4) the end users' target machines&lt;br&gt;
5) technical requirements of the production environment&lt;/p&gt;

&lt;h2&gt;
  
  
  Final words of caution about optimization in general
&lt;/h2&gt;

&lt;p&gt;So, let's not &lt;a href="https://reactjs.org/docs/optimizing-performance.html#profiling-components-with-the-devtools-profiler"&gt;optimize&lt;/a&gt; for the sake of it.&lt;/p&gt;

&lt;p&gt;Meaning, let's not memoize or avoid inline objects systematically (&lt;a href="https://reactjs.org/docs/hooks-reference.html#usememo"&gt;&lt;code&gt;React.useMemo&lt;/code&gt;&lt;/a&gt; &amp;amp; &lt;a href="https://reactjs.org/docs/hooks-reference.html#usecallback"&gt;&lt;code&gt;React.useCallback&lt;/code&gt;&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Let's not split our code and lazy load it systematically (&lt;a href="https://reactjs.org/docs/code-splitting.html"&gt;&lt;code&gt;React.lazy&lt;/code&gt; + &lt;code&gt;React.Suspense&lt;/code&gt; + &lt;code&gt;Spinner&lt;/code&gt; + &lt;code&gt;ErroBoundary&lt;/code&gt;&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Let's not memoize components systematically (&lt;a href="https://reactjs.org/docs/react-api.html#reactmemo"&gt;&lt;code&gt;React.memo&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://reactjs.org/docs/react-api.html#reactpurecomponent"&gt;&lt;code&gt;React.PureComponent&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://reactjs.org/docs/react-component.html#shouldcomponentupdate"&gt;&lt;code&gt;shouldComponentUpdate&lt;/code&gt;&lt;/a&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  In order words: consider the act of optimizing ONLY if there is a performance problem or complaint in production!
&lt;/h3&gt;




&lt;h2&gt;
  
  
  Bonus: Recommended Toolchains
&lt;/h2&gt;

&lt;p&gt;The React team primarily recommends these solutions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you’re &lt;strong&gt;learning React&lt;/strong&gt; or &lt;strong&gt;creating a new &lt;a href="https://reactjs.org/docs/glossary.html#single-page-application"&gt;single-page app&lt;/a&gt;&lt;/strong&gt;, use &lt;a href="https://github.com/facebook/create-react-app"&gt;Create React App&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;If you’re building a &lt;strong&gt;server-rendered website with Node.js&lt;/strong&gt;, try &lt;a href="https://nextjs.org/"&gt;Next.js&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;If you’re building a &lt;strong&gt;static content-oriented website&lt;/strong&gt;, try &lt;a href="https://www.gatsbyjs.com/"&gt;Gatsby&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;If you’re building a &lt;strong&gt;component library&lt;/strong&gt; or &lt;strong&gt;integrating with an existing codebase&lt;/strong&gt;, try &lt;a href="https://reactjs.org/docs/create-a-new-react-app.html#more-flexible-toolchains"&gt;More Flexible Toolchains&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>performance</category>
      <category>usememo</category>
      <category>usecallback</category>
    </item>
    <item>
      <title>The useEffect hook tribulations + Cheat Sheet</title>
      <dc:creator>Fred B.</dc:creator>
      <pubDate>Tue, 06 Oct 2020 12:54:16 +0000</pubDate>
      <link>https://dev.to/boostup/the-useeffect-hook-tribulations-1gbe</link>
      <guid>https://dev.to/boostup/the-useeffect-hook-tribulations-1gbe</guid>
      <description>&lt;p&gt;Yesterday, while working on &lt;a href="https://github.com/boostup/regalia-clothing/projects/1"&gt;this project&lt;/a&gt;, I came to realise that logic contained in &lt;a href="https://github.com/boostup/regalia-clothing/blob/878d2be9f9f252d57db16f0131e48a2589131dab/src/contexts/collections/useFetchCollections.js"&gt;&lt;code&gt;useFetchCollections&lt;/code&gt;&lt;/a&gt; was flawed in that it was invoked endlessly.  &lt;/p&gt;

&lt;p&gt;This had for perverse effect that the free daily allowed quota in &lt;code&gt;firestore&lt;/code&gt; was reached !&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read access to the cloud database was forbidden for almost 24 hours !!!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Therefore, to fix this, I pushed a commit that :&lt;/p&gt;

&lt;p&gt;1) fixes the endless loop, and &lt;br&gt;
2) now makes use of &lt;code&gt;collections&lt;/code&gt; data from a local json file instead of fetching it from the database (using &lt;code&gt;process.env.NODE_ENV&lt;/code&gt; the code determines whether the environment is &lt;code&gt;production&lt;/code&gt; or &lt;code&gt;development&lt;/code&gt; in order to conditionally fetch this data set in one data source or the other)&lt;/p&gt;
&lt;h2&gt;
  
  
  The &lt;code&gt;useEffect&lt;/code&gt; hook tribulations
&lt;/h2&gt;

&lt;p&gt;This loop happened because the data fetching was inside a &lt;code&gt;useEffect&lt;/code&gt; hook, as seen &lt;a href="https://github.com/boostup/regalia-clothing/blob/878d2be9f9f252d57db16f0131e48a2589131dab/src/contexts/collections/useFetchCollections.js"&gt;in this file history&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const fetchCollections = fetchCollectionsAsync(setCollectionsState);

  useEffect(() =&amp;gt; {
    fetchCollections();
  }, [fetchCollections]);
  return collectionsState;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem was to have included &lt;code&gt;fetchCollections&lt;/code&gt; as a dependency inside the array (the second argument that &lt;code&gt;useEffect&lt;/code&gt; takes).  Without its inclusion there, the &lt;strong&gt;React&lt;/strong&gt; lib issued a warning :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React Hook useEffect has a missing dependency: `fetchCollections`.
Either include it or remove the dependency array. 
If `fetchCollections` changes too often, find the parent component that defines it and wrap that definition in useCallback
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this particular issue, I needed to ensure that &lt;code&gt;useEffect&lt;/code&gt; fired only once, so the fix I issued is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  useEffect(() =&amp;gt; {
    fetchCollectionsAsync(setCollectionsState);
  }, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fix allowed to:&lt;/p&gt;

&lt;p&gt;A) get rid of the &lt;strong&gt;React&lt;/strong&gt; warning, and &lt;br&gt;
B) get &lt;code&gt;useEffect&lt;/code&gt; to behave as needed by providing an empty dependency array, to have it fire &lt;strong&gt;only once&lt;/strong&gt; in the whole component lifecycle.&lt;/p&gt;

&lt;h3&gt;
  
  
  When NOT to pass array of dependency to &lt;code&gt;useEffect&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;One of the suggestions found in the warning message was to &lt;code&gt;remove the dependency array&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;After some research, it turns out that we must omit this array of dependency when we want &lt;code&gt;useEffect&lt;/code&gt; to trigger:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;everytime&lt;/strong&gt; the component it is in has finished rendering&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;whenever&lt;/strong&gt; &lt;code&gt;useEffect&lt;/code&gt; is invoked&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Reminder about component rendering
&lt;/h3&gt;

&lt;p&gt;A component will re-render when either: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;props change&lt;/li&gt;
&lt;li&gt;state change&lt;/li&gt;
&lt;li&gt;the parent component re-renders&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;useEffect&lt;/code&gt; Cheat Sheet
&lt;/h2&gt;

&lt;p&gt;Even though Dan Abramov, the lead dev in the React team will not like it, here is a cheat sheet which "maps" &lt;code&gt;useEffect&lt;/code&gt; use cases in terms of Class-based component lifecycles.&lt;/p&gt;

&lt;h3&gt;
  
  
  ComponentDidMount
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Class
componentDidMount() {
    console.log('I just mounted!');
}

//Hooks
useEffect(() =&amp;gt; {
    console.log('I just mounted!');
}, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ComponentWillUnmount
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Class
componentWillUnmount() {
    console.log('I am unmounting');
}

//Hooks
useEffect(() =&amp;gt; {
    return () =&amp;gt; console.log('I am unmounting');
}, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ComponentWillReceiveProps
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
//Class
componentWillReceiveProps(nextProps) {
    if (nextProps.count !== this.props.count) {
        console.log('count changed', nextProps.count);
    }
}

//Hooks
useEffect(() =&amp;gt; {
    console.log('count changed', props.count);
}, [props.count])

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

&lt;/div&gt;



</description>
      <category>react</category>
      <category>firebase</category>
      <category>useeffect</category>
      <category>cheatsheet</category>
    </item>
    <item>
      <title>Ubuntu/Linux cmd-line Cheat Sheet</title>
      <dc:creator>Fred B.</dc:creator>
      <pubDate>Sun, 16 Aug 2020 16:20:06 +0000</pubDate>
      <link>https://dev.to/boostup/ubuntu-linux-cmd-line-cheat-sheet-4hec</link>
      <guid>https://dev.to/boostup/ubuntu-linux-cmd-line-cheat-sheet-4hec</guid>
      <description>&lt;h5&gt;
  
  
  &lt;em&gt;&lt;a href="https://codepen.io/write/bash-cheat-sheet2"&gt;Originally posted on Codepen Oct 30, 2015&lt;/a&gt;&lt;/em&gt;
&lt;/h5&gt;

&lt;h4&gt;
  
  
  Convert binary, hex, or any base, into decimal
&lt;/h4&gt;

&lt;p&gt;from hex to decimal: &lt;code&gt;$((16#62)) =&amp;gt; 98&lt;/code&gt; (note the &lt;code&gt;16#&lt;/code&gt;)&lt;br&gt;
from binary to decimal: &lt;code&gt;$((2#01110011)) =&amp;gt; 115&lt;/code&gt; (note the &lt;code&gt;2#&lt;/code&gt;)&lt;br&gt;
&lt;strong&gt;Note&lt;/strong&gt;: the expression &lt;code&gt;$(())&lt;/code&gt; will execute a command named according to what it returns, so &lt;code&gt;echo&lt;/code&gt; it to avoid the prompt complaining that it knows no command named &lt;code&gt;98&lt;/code&gt; or &lt;code&gt;115&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;picoplayer@challenge:~$ $((16#62))
98: command not found
picoplayer@challenge:~$ echo $((16#62))
98
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Convert ASCII hex value into the actual characters
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;note&lt;/strong&gt;: also works with &lt;code&gt;0x&lt;/code&gt; prefix, ie: &lt;code&gt;0x62 0x64 0x61 0x36 0x38 0x66 0x37 0x35&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo "62 64 61 36 38 66 37 35" | xxd -p -r
bda68f75
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Convert to text from [binary|octal|hex]
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ x="01100011 01101111 01101101 01110000 01110101 01110100 01100101 01110010"
$ for a in $x; do printf "%x" $((2#$a)); done | xxd -r -p &amp;amp;&amp;amp; echo " "
computer
$ x="160 145 141 162"
$ for a in $x; do printf "%x" $((8#$a)); done | xxd -r -p &amp;amp;&amp;amp; echo " "
pear
$ x="66616c636f6e"
$ for a in $x; do printf "%x" $((16#$a)); done | xxd -r -p &amp;amp;&amp;amp; echo " "
falcon
$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Convert character into decimal ASCII value
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ printf "%d\n" "'a"
97
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Convert decimal ASCII value into a character
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ printf "%x" 97 | xxd -r -p
a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Convert decimal ASCII value into hex value
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ printf "%x" 97
61
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  List sudo available commands: &lt;code&gt;sudo -l&lt;/code&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Bypassing permissions
&lt;/h4&gt;

&lt;p&gt;As can be seen in the output below, the &lt;code&gt;challenge&lt;/code&gt; directory is not accessible since no permissions have been set (&lt;code&gt;0 d---------    1 root   root     27 Aug  4 21:34 challenge&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;picoplayer@challenge:~$ cd /
picoplayer@challenge:/$ ls -ls

total 0
0 lrwxrwxrwx    1 root   root      7 Mar  8  2023 bin -&amp;gt; usr/bin
0 drwxr-xr-x    2 root   root      6 Apr 15  2020 boot
0 d---------    1 root   root     27 Aug  4 21:34 challenge
0 drwxr-xr-x    5 root   root    340 Dec 13 17:55 dev
0 drwxr-xr-x    1 root   root     66 Dec 13 17:55 etc
0 drwxr-xr-x    1 root   root     24 Aug  4 21:32 home
0 lrwxrwxrwx    1 root   root      7 Mar  8  2023 lib -&amp;gt; usr/lib
0 lrwxrwxrwx    1 root   root      9 Mar  8  2023 lib32 -&amp;gt; usr/lib32
0 lrwxrwxrwx    1 root   root      9 Mar  8  2023 lib64 -&amp;gt; usr/lib64
0 lrwxrwxrwx    1 root   root     10 Mar  8  2023 libx32 -&amp;gt; usr/libx32
0 drwxr-xr-x    2 root   root      6 Mar  8  2023 media
0 drwxr-xr-x    2 root   root      6 Mar  8  2023 mnt
0 drwxr-xr-x    2 root   root      6 Mar  8  2023 opt
0 dr-xr-xr-x 2501 nobody nogroup   0 Dec 13 17:55 proc
0 drwx------    1 root   root     23 Aug  4 21:34 root
0 drwxr-xr-x    1 root   root     54 Dec 13 17:56 run
0 lrwxrwxrwx    1 root   root      8 Mar  8  2023 sbin -&amp;gt; usr/sbin
0 drwxr-xr-x    2 root   root      6 Mar  8  2023 srv
0 dr-xr-xr-x   13 nobody nogroup   0 Dec 13 17:55 sys
0 drwxrwxrwt    1 root   root      6 Aug  4 21:34 tmp
0 drwxr-xr-x    1 root   root     18 Mar  8  2023 usr
0 drwxr-xr-x    1 root   root     17 Mar  8  2023 var
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the idea, is to use &lt;code&gt;vi&lt;/code&gt; to access the contents of the &lt;code&gt;challenge&lt;/code&gt; directory anyway, because as seen in the last line of the following output, &lt;code&gt;vi&lt;/code&gt; can be used with &lt;code&gt;sudo&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;picoplayer@challenge:/$ sudo -l
Matching Defaults entries for picoplayer on challenge:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User picoplayer may run the following commands on challenge:
    (ALL) /usr/bin/vi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, finally:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;type &lt;code&gt;sudo vi&lt;/code&gt;, &lt;/li&gt;
&lt;li&gt;type &lt;code&gt;:! ls -ls /challenge/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;read the following output
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;picoplayer@challenge:/$ sudo vi
[sudo] password for picoplayer: 

4 ---------- 1 root root 98 Aug  4 21:34 metadata.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I now even can print the contents of that file.  So, still from vi, type &lt;code&gt;:! cat /challenge/metadata.json&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Convert string to MD5 hash
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# to avoid the trailing newline added by the shell: '%s'
printf '%s' "money" | md5sum
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Determining the contents of non-text files, like a binary file for example.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;strings -a -t x [path-to-binary-file-for-example]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create a binary (executable) file from a bash script (&lt;a href="https://www.geeksforgeeks.org/shell-scripting-creating-a-binary-file/"&gt;install shc&lt;/a&gt;)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# This will create 2 files, and the binary/exec one is 'add.sh.x'
shc -f add.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  View contents of binary file
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# bvi, bview - visual editor for binary files
bvi ./add.sh.x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Is package installed?
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dpkg -s gimp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Update all packages at once
&lt;/h4&gt;

&lt;p&gt;Disclaimer: this command should probably never be used in an actual production server ;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install -f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Free port
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kill $(lsof -t -i:3000)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  LAN Access for WSL localhost
&lt;/h4&gt;

&lt;p&gt;These are Powershell (run as admin) commands. (&lt;a href="https://superuser.com/questions/1586386/how-to-find-wsl2-machines-ip-address-from-windows"&gt;source1&lt;/a&gt; | &lt;a href="https://stackoverflow.com/questions/61002681/connecting-to-wsl2-server-via-local-network"&gt;source2&lt;/a&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netsh advfirewall firewall add rule name="Allowing connections to WSL2 servers" dir=in action=allow protocol=TCP localport=3000

netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=[plug here the result of `wsl hostname -I`]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  To show added rule &amp;amp; proxy
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netsh advfirewall firewall show rule name="Allowing connections to WSL2 servers"

netsh interface portproxy show v4tov4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Install a package (.deb)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo dpkg -i /path/to/deb/file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  create a tree of directories in one command
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -pv dir1/dir2/dir3/dir4/dir5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above commands will create directory(s) recursively inside a non-existent directory(s). You can use the 'tree' command to view the directory structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tree dir1/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dir1/
└── dir2
 └── dir3
 └── dir4
 └── dir5
4 directories, 0 files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Find files recursively in all subdirectories and list them by DESC file size
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls -lhR | grep -E "\.(jpg|zip)$" | awk '{print $5, $9}' | sort -hr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find . -type f -exec du -h {} + | grep -E "\./.*\.(jpg|zip)" | sort -hr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Find files by name in a directory tree
&lt;/h4&gt;

&lt;p&gt;This search is case insensitive (-ipath) and recursively traverses the all subdirectories.&lt;br&gt;
The path&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find -ipath */ubeR-secret.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./adequate_books/more_books/.secret/deeper_secrets/deepest_secrets/uber-secret.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using command output as the parameter of another command
&lt;/h4&gt;

&lt;p&gt;Just place it between &lt;code&gt;$([command])&lt;/code&gt;.&lt;br&gt;
I should call that this works because I'm expecting a single result in the output.  Unexpected results might happen if cat (or the encapsulating command) was fed a multiline result as parameters...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat $(find -ipath */ubeR-secret.txt)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  List files that were created between 2 dates
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find . -type f -newermt "2012-01-01" \! -newermt "2020-09-01"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Search for file contents in a directory tree recursively
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grep -r "pico"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;big-zip-files/folder_pmbymkjcya/folder_cawigcwvgv/folder_ltdayfmktr/folder_fnpfclfyee/whzxrpivpqld.txt:information on the record will last a billion years. Genes and brains and books encode &lt;strong&gt;pico&lt;/strong&gt;CTF{gr3p_15_m4g1c_ef8790dc}&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  make script file executable
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x [filename]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Get local IP address
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hostname -I | awk '{print $1}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Open current terminal location into file explorer
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;xdg-open file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Download file to current directory, using the name and extension found in the URL
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://raw.githubusercontent.com/ariya/phantomjs/master/examples/printenv.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create a symbolic link
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ln -s /path/to/original /path/to/symlink
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Saving as unix file from VIM
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:set fileformat=unix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Find what PID is locking a port
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netstat -tulpn | grep &amp;lt;port&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Force kill a PID
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kill -9 &amp;lt;PID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Find out what process is locking a file
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fuser &amp;lt;file_path&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Avoid being prompted for private key when using SSH or scp to connect to hosts with your public key.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; eval `ssh-agent`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; ssh-add
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Command to kill a UI/Desktop Application
&lt;/h4&gt;



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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Terminator preferences profile (~/.config/terminator/config)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[global_config]
[keybindings]
[profiles]
  [[default]]
    use_system_font = False
    background_image = None
    background_darkness = 0.91
    active_encodings = ANSI_X3.4-1968, UTF-8, ISO-8859-1
    foreground_color = "#839496"
    font = Ubuntu Mono 14
    background_color = "#002b36"
    scrollback_infinite = True
[layouts]
  [[default]]
    [[[child1]]]
      type = Terminal
      parent = window0
    [[[window0]]]
      type = Window
      parent = ""
[plugins]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  My custom bash prompt
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;########### current_dir(current_git_branch) ####################
parse_git_branch() {
 git branch 2&amp;gt; /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOR="\[\033[0m\]"

PS1="$GREEN\W$YELLOW\$(parse_git_branch)$NO_COLOR "
####################
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Cancel reverse-i-search
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ctrl+G
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Activate reverse-i-search
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ctrl+R
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Reload bash prompt after &lt;strong&gt;.bashrc&lt;/strong&gt; modification
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source .bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Google chrome path
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;which google-chrome
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Check ubuntu version
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lsb_release -a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Make umount Work with sshfs
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fusermount -u /path/to/mounted-dir
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Get a report of the used and available space on all mounted drives
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df -h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Get a report of the size of data by folder
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo du -sk /home/* &amp;gt; tmp3.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Sort report
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sort -n tmp.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Get a list of processes, ssh in this case
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ps -ax | grep ssh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Print number of &lt;strong&gt;.tpl&lt;/strong&gt; files (from current directory and in all nested directories..)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find -name '*.tpl' | wc -l
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Print a list of &lt;strong&gt;.tpl&lt;/strong&gt; files (from current directory and in all nested directories..)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find -name '*.tpl'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Look for the number of files (.tpl in this case) per directory
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; for D in *; do echo $D; find $D -type f -name '*.tpl'| wc -l; done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>bash</category>
      <category>ubuntu</category>
      <category>linux</category>
    </item>
    <item>
      <title>Git/Github Cheat Sheet</title>
      <dc:creator>Fred B.</dc:creator>
      <pubDate>Sun, 16 Aug 2020 16:10:31 +0000</pubDate>
      <link>https://dev.to/boostup/git-github-cheat-sheet-316p</link>
      <guid>https://dev.to/boostup/git-github-cheat-sheet-316p</guid>
      <description>&lt;h5&gt;
  
  
  &lt;em&gt;&lt;a href="https://codepen.io/write/git-cheat-sheet"&gt;Originally posted on Codepen on January 21, 2015&lt;/a&gt;&lt;/em&gt;
&lt;/h5&gt;




&lt;h3&gt;
  
  
  Offical Doc
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.atlassian.com/git/tutorials"&gt;Documentation&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Git stash
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/docs/git-stash/en#_examples"&gt;Handle blocking situations well&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Git Tutorial
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=6nolZKpiG_w"&gt;Advanced Git Tutorial (Level 1): Git Rebase&lt;/a&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  Show commits oneline, author, commit date, change
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log --pretty=format:"%h%x09%an%x09%ad%x09%s"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;%h&lt;/code&gt; = abbreviated commit hash&lt;br&gt;
&lt;code&gt;%x09&lt;/code&gt; = tab (character for code 9)&lt;br&gt;
&lt;code&gt;%an&lt;/code&gt; = author name&lt;br&gt;
&lt;code&gt;%ad&lt;/code&gt; = author date (format respects --date= option)&lt;br&gt;
&lt;code&gt;%s&lt;/code&gt; = subject&lt;/p&gt;
&lt;h4&gt;
  
  
  Git stash
&lt;/h4&gt;

&lt;p&gt;Use git stash to be able to checkout master&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash // put changes aside temporarily
git checkout master
git stash pop // apply the changes back to the master local branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create and view repo from command line
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gh repo create boostup/`basename "$PWD"`
gh repo view -w boostup/`basename "$PWD"`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Check for unpushed commits
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log --branches --not --remotes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log @{u}..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log origin/master..HEAD 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Publish on gh-pages
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://github.com/gitname/react-gh-pages"&gt;Follow instructions here&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Open repo on Git Hub
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gh repo view -w boostup/`basename "$PWD"`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  New Repo
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gh repo create boostup/`basename "$PWD"`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Stop tracking a file
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rm --cached &amp;lt;file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Download one file from any github repo
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -o app.css https://raw.githubusercontent.com/angular-university/complete-typescript-course/section-7-6/client/src/assets/app.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Showing repo remote URLs
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Changing repo remote URLs
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Showing remote tracking
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote show origin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Setting remote tracking from local branch
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push --set-upstream origin &amp;lt;branch name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch --set-upstream-to origin/master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Unsetting remote tracking by branch name
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --unset branch.&amp;lt;branch name&amp;gt;.remote
git config --unset branch.&amp;lt;branch name&amp;gt;.merge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Unsetting remote tracking from branch
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch --unset-upstream
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Squasing commits
&lt;/h4&gt;

&lt;p&gt;&lt;a href="http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html"&gt;Follow instructions here&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Finding commits where a file has been modified
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log --author=clark --stat &amp;lt;file path from project root&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Finding remote merged branches
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch -r --merged | grep origin | grep -Ev 'master|deamon'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: (grep -v 'master|deamon' =&amp;gt; exlcuding branches with names that contain the words 'master' or 'deamon')&lt;/p&gt;

&lt;h4&gt;
  
  
  To amend the previous commit
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
git commit --amend

git log --stat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  To change git password when Windows password changes
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global credential.helper wincred
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  To remove untracked files / directories do:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clean -fdx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;-f&lt;/strong&gt; - force&lt;br&gt;
&lt;strong&gt;-d&lt;/strong&gt; - directories too&lt;br&gt;
&lt;strong&gt;-x&lt;/strong&gt; - remove ignored files too ( don't use this if you don't want to remove ignored files)&lt;/p&gt;
&lt;h4&gt;
  
  
  Show a file on a particular commit
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git show REVISION:path/to/file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  See a graph of branch hierarchy
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log --all --graph --decorate --oneline --simplify-by-decoration
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Throwing out all of the changes not committed or pushed
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -f 
or 
git reset --HARD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Git Undo Last Commit (not yet pushed)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;keeping changes
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset --soft HEAD^
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;trashing changes
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset --hard HEAD^
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now if you already pushed and someone pulled which is usually my case, you can't use git reset. You can however do a git revert,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git revert HEAD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new commit that reverses everything introduced by the accidental commit.&lt;/p&gt;

&lt;h4&gt;
  
  
  Create a new branch:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -b nombranche ( = git branch branchname + git checkout branchname )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Pushing local branch and tracking its remote counterpart:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push -u origin nombranche
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Display all local and remote branches:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch -a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Display remote branch commits:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log origin/nombranche
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Merging a branch into the build branch:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout build
git pull origin build
git merge branchname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Deleting a local branch:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch -d nombranche
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Deleting a remote branch:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push origin :nombranche
ou 
git push origin --delete nombranche
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Removing staged and working :
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset --hard directory changes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Removing untracked files:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clean -f -d 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Get list of files with conflicts:
&lt;/h4&gt;



&lt;p&gt;&lt;code&gt;git diff --name-only --diff-filter=U&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 or&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;git ls-files -u&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  Display commits by user:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log --author=authorname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Diffing
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git diff f98c5f277e28160ee5076e8ac4fabe7a60e8ca6f  --name-only
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Creating a new tag
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git tag tagname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Pushing the tag
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push origin branchname --tags
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Deleting a pushed tag
&lt;/h4&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push origin :refs/tags/tagname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git tag -d tagname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Troubelshooting
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Git asks me to commit or stash changes on checkout master, even though there are no changes
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -- .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>git</category>
      <category>github</category>
    </item>
  </channel>
</rss>
