<?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>Forem: Guille Acosta</title>
    <description>The latest articles on Forem by Guille Acosta (@ghacosta).</description>
    <link>https://forem.com/ghacosta</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%2F615683%2F66fc2903-2db4-4b55-b0a6-d32c53857193.jpeg</url>
      <title>Forem: Guille Acosta</title>
      <link>https://forem.com/ghacosta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ghacosta"/>
    <language>en</language>
    <item>
      <title>How (and Why) to enforce conventional commits on your project?</title>
      <dc:creator>Guille Acosta</dc:creator>
      <pubDate>Fri, 27 Jan 2023 18:42:10 +0000</pubDate>
      <link>https://forem.com/ghacosta/definitive-guide-for-commitizen-commitlint-husky-3of9</link>
      <guid>https://forem.com/ghacosta/definitive-guide-for-commitizen-commitlint-husky-3of9</guid>
      <description>&lt;p&gt;After reading a lot of post and checking a few videos I come up with a configuration which will help you to enforce conventional commit messages on your repository.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;But.. Why is it important to use conventional commits?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatically generating CHANGELOGs.&lt;/li&gt;
&lt;li&gt;Automatically determining a semantic version bump (based on the types of commits landed).&lt;/li&gt;
&lt;li&gt;Communicating the nature of changes to teammates, the public, and other stakeholders.&lt;/li&gt;
&lt;li&gt;Triggering build and publish processes.&lt;/li&gt;
&lt;li&gt;Making it easier for people to contribute to your projects, by allowing them to explore a more structured commit history.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Enforcing conventional commits
&lt;/h2&gt;

&lt;p&gt;To accomplish this, we will use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;husky: for handling the git hooks in a easy (and shareable) way.&lt;/li&gt;
&lt;li&gt;commitizen: for a cli wizard which will help us write conventional commits.&lt;/li&gt;
&lt;li&gt;commitlint: as the name suggests, lint our commit messages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok, hands on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pre-requisites: 
- project where you have run `npm init` or you already have a package.json.
- project where you have run `git init` or you already have a repository configured.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;install commitizen as a dev dependency and save the exact version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx commitizen init cz-conventional-changelog --save-dev --save-exact
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;same for commitlint&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D @commitlint/{cli,config-conventional} --save-exact
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now on a file called .commitlintrc.json  set the extends to the rules from config-conventional&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{  "extends": ["@commitlint/config-conventional"]} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now run husky from npx and run npm install which will trigger the just appended script &lt;code&gt;prepare&lt;/code&gt; which executes &lt;code&gt;husky install&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;npx husky-init &amp;amp;&amp;amp; npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now you need to add your hooks to prevent a commit message which is not formatted as a conventional commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE: this hook could be useful as starts up the commitizen wizard every time you type &lt;code&gt;git commit&lt;/code&gt; on the terminal but it changes the behaviour of the &lt;code&gt;git commit&lt;/code&gt; command and opens an editor to save the commit message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx husky add .husky/prepare-commit-msg "exec &amp;lt; /dev/tty &amp;amp;&amp;amp; node_modules/.bin/cz --hook || true"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead, I prefer to add a script on the &lt;code&gt;package.json&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    ...
    "cz": "cz"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so you can run &lt;code&gt;npm run cz&lt;/code&gt; to start the wizard or even create an alias to shorten this command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Releasing
&lt;/h2&gt;

&lt;p&gt;now that you already have a few commits, it's time to create releases and by using semver, you will be able to show those changes on the changelog as patches, minor or major ones.&lt;/p&gt;

&lt;p&gt;first install &lt;code&gt;standard-version&lt;/code&gt; 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;npm i --save-dev standard-version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then place this new scripts on your &lt;code&gt;package.json&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;  "scripts": {
    ...
    "release": "standard-version",
    "release:minor": "standard-version --release-as minor",
    "release:patch": "standard-version --release-as patch",
    "release:major": "standard-version --release-as major"
  },

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

&lt;/div&gt;



&lt;p&gt;now just for only time do a initial release this way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run release -- --first-release
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CONGRATS! now you have a wonderful auto-generated changelog.md based on your conventional commit messages.&lt;/p&gt;

&lt;p&gt;From now on after you commit your changes you will be able to run &lt;code&gt;npm run release:patch&lt;/code&gt; (minor or major) depending on your changes.&lt;/p&gt;




&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>codequality</category>
      <category>development</category>
      <category>productivity</category>
    </item>
    <item>
      <title>TIL: setting up proxy server on vite</title>
      <dc:creator>Guille Acosta</dc:creator>
      <pubDate>Thu, 29 Dec 2022 21:04:53 +0000</pubDate>
      <link>https://forem.com/ghacosta/til-setting-up-proxy-server-on-vite-2cng</link>
      <guid>https://forem.com/ghacosta/til-setting-up-proxy-server-on-vite-2cng</guid>
      <description>&lt;p&gt;So, Today I learned how to setup a proxy server on vite. I was tired of seeing this kind of lines over an over:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;axios.get('localhost:5001/api/products/1234')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;so, first approach was to create a &lt;code&gt;.env.local&lt;/code&gt; and set there a env variable like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;VITE_API_BASE_URL="localhost:5001"&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;this way my initial code would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const API_BASE_URL = import.meta.env.VITE_API_BASE_URL
axios.get(`${API_BASE_URL}/api/products/1234`)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but this approach add this new line each time I need to get the API_BASE_URL.&lt;/p&gt;

&lt;p&gt;So I decided to setup a proxy server. This is useful not only for "making URLs shorter" but for overcoming CORS issues if your api is in a host other than "localhost".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default defineConfig({
  plugins: ...,
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:5001',
        changeOrigin: true,
        secure: false,
      }
    }
  }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Loading target from .env
&lt;/h2&gt;

&lt;p&gt;let's say you would like to change that target prop based on the environment you are running the application.&lt;/p&gt;

&lt;p&gt;You can do it by checking the command or the mode, but I recommend load the &lt;code&gt;.env&lt;/code&gt; file and using the VITE_API_BASE_URL we already defined.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default defineConfig(({ mode }) =&amp;gt; {
  const env = loadEnv(mode, process.cwd(), '');

  return {
    plugins: ...,
    server: {
      proxy: {
        '/api': {
          target: env.VITE_API_BASE_URL,
          changeOrigin: true,
          secure: false,
        },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this way, the target will depend on the VITE_API_BASE_URL defined on the .env which should be different on production, staging or local.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixing "http proxy error ECONNRESET"
&lt;/h2&gt;

&lt;p&gt;Even if the request are succeding (by checking the network inspector) there is an error logged by vite on the terminal.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http proxy error ECONNRESET at TLSWrap.onStreamRead&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;for every single request which gets proxied.&lt;/p&gt;

&lt;p&gt;So the answer posted &lt;a href="https://github.com/vitejs/vite/issues/4794#issuecomment-957095720" rel="noopener noreferrer"&gt;here&lt;/a&gt; does the trick.&lt;/p&gt;

&lt;p&gt;You will need first to add &lt;strong&gt;https&lt;/strong&gt; as a dev dependency by doing: &lt;code&gt;npm i -D https&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and then importing on the top of &lt;code&gt;vite.config.js&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;import http from "https";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then adding the agent prop on the proxy key &lt;code&gt;/api&lt;/code&gt; we just created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server: {
      proxy: {
        '/api': {
          target: env.VITE_API_BASE_URL,
          changeOrigin: true,
          secure: false,
          agent: new http.Agent()
        },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope this helps somebody to save some minutes on your next project. Happy coding!&lt;/p&gt;

&lt;p&gt;Official docs can be found here: &lt;a href="https://vitejs.dev/config/server-options.html#server-proxy" rel="noopener noreferrer"&gt;vite server proxy options&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Data Science 101: Install miniconda and rstudio on a Mac</title>
      <dc:creator>Guille Acosta</dc:creator>
      <pubDate>Mon, 19 Sep 2022 15:02:44 +0000</pubDate>
      <link>https://forem.com/ghacosta/data-science-101-install-miniconda-and-rstudio-on-a-mac-2170</link>
      <guid>https://forem.com/ghacosta/data-science-101-install-miniconda-and-rstudio-on-a-mac-2170</guid>
      <description>&lt;p&gt;So, you want to start your Data Science journey to become a Quant developer but you have a Mac and you're not sure how to configure your environment to install miniconda and rstudio? Stay tuned, this is your post.&lt;/p&gt;

&lt;p&gt;Step 1: install &lt;strong&gt;Xcode Developer Tools&lt;/strong&gt; by running &lt;code&gt;sudo xcode-select --install&lt;/code&gt; (you need at least Xcode 11.4) &lt;/p&gt;

&lt;p&gt;Step 2: download and install &lt;strong&gt;rstudio&lt;/strong&gt; from &lt;a href="https://www.rstudio.com/products/rstudio/download/#download"&gt;its website&lt;/a&gt; but do not open it yet.&lt;/p&gt;

&lt;p&gt;Step 3: donwload &lt;strong&gt;miniconda&lt;/strong&gt; from &lt;a href="https://docs.conda.io/en/latest/miniconda.html"&gt;its website&lt;/a&gt; and follow the wizard steps.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;with miniconda installed now you have a new command to use: &lt;code&gt;conda&lt;/code&gt;. The idea behind conda is to create isolated environments where you can install not only different pypi libraries &lt;em&gt;(as venv or virtualenv does on Python)&lt;/em&gt; but also install different versions of Python (or R, etc). This way you can create a conda env with python 2.9 and other conda env with python 3.10 on it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now it's time to open the &lt;strong&gt;Terminal&lt;/strong&gt; to create a new conda env for &lt;strong&gt;R&lt;/strong&gt; but first, to get the latest version we need to set the right channel.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;conda config --add channels conda-forge&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then you need to set the priority level as follows:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;conda config --set channel_priority strict&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: to undo this changes you can check &lt;a href="https://stackoverflow.com/questions/48547046/resetting-conda-channel-priorities"&gt;these answers&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;At the time I'm writing this post default channel does not have R version &amp;gt;= 4.0 you can check it by running &lt;code&gt;conda search r-base&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now you are good to create a new env like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;conda create -n r-env r -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;this way you are creating a conda env called &lt;code&gt;r-env&lt;/code&gt; which by default got latest &lt;code&gt;r&lt;/code&gt; installed and &lt;code&gt;-y&lt;/code&gt; flag to accept the terms.&lt;/p&gt;

&lt;p&gt;to activate this env you should run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;conda activate r-env&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;once you finish your job you can deactivate it by doing:&lt;br&gt;
&lt;code&gt;conda deactivate&lt;/code&gt;&lt;br&gt;
and if you want to delete this env you can do it this way:&lt;br&gt;
&lt;code&gt;conda env remove -n r-env&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now you are good to open rstudio and start working from there.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;PS: if you are running R on a M1 Mac, check &lt;a href="https://mac.r-project.org/"&gt;this page&lt;/a&gt; for more information.&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>miniconda</category>
      <category>rstudio</category>
      <category>quant</category>
    </item>
    <item>
      <title>How to use Prismic.io on React Native</title>
      <dc:creator>Guille Acosta</dc:creator>
      <pubDate>Fri, 11 Feb 2022 15:40:38 +0000</pubDate>
      <link>https://forem.com/ghacosta/how-to-use-prismicio-on-react-native-1nk5</link>
      <guid>https://forem.com/ghacosta/how-to-use-prismicio-on-react-native-1nk5</guid>
      <description>&lt;p&gt;Prismic is a Content Management System, also known as headless CMS or API CMS. &lt;/p&gt;

&lt;p&gt;I was asked to integrate Prismic.io into a React Native project, so first thing I did was to check how it was implemented on the web project.&lt;/p&gt;

&lt;p&gt;They were using &lt;a href="https://www.npmjs.com/package/prismic-javascript"&gt;prismic-javascript&lt;/a&gt; library which is &lt;strong&gt;deprecated&lt;/strong&gt; already and no docs available either.&lt;/p&gt;

&lt;p&gt;The recommended solution on Prismic site is to use &lt;code&gt;prismic-client&lt;/code&gt; along with &lt;code&gt;prismic-react&lt;/code&gt; for react projects, but no particular examples for react-native.&lt;/p&gt;

&lt;p&gt;I followed prismic installation steps line to line but at the time of bundling the app (I'm using an ejected expo app) came up the first issue:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;While trying to resolve module `imgix-url-builder` from file `/Path/to/project/node_modules/@prismicio/helpers/dist/index.js`, the package `/Path/to/project/node_modules/imgix-url-builder/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Path/to/project/node_modules/imgix-url-builder/dist/index.cjs`. Indeed, none of these files exist:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So &lt;code&gt;imgix-url-builder&lt;/code&gt; is not being resolved, and the solution is to add a source extension to the metro config like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { getDefaultConfig } = require("expo/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.resolver.sourceExts.push("cjs");

module.exports = defaultConfig;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I tried to bundle again, which succeeded but at the time of execute any prismic hook such as &lt;code&gt;usePrismicDocumentByID&lt;/code&gt; I was receiving an error like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;error: Not implemented
node_modules/react-native/Libraries/Blob/URL.js:86:10 in URLSearchParams#set
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After googling a little bit I found that according to &lt;a href="https://justinnoel.dev/2020/12/08/react-native-urlsearchparams-error-not-implemented/"&gt;this post&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;React Native react-native/Libraries/Blob/URL.js doesn't import all the Web API functionality due to size concerns&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And to fix this we need to add a polyfill for this particular issue.&lt;/p&gt;

&lt;p&gt;First you need to &lt;code&gt;npm i react-native-url-polyfill&lt;/code&gt;, then add this line to your &lt;code&gt;index.js&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;import "react-native-url-polyfill/auto";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, and restarting your server (just in case), you will be able to start using the prismic hooks from &lt;code&gt;prismic-react&lt;/code&gt; library.&lt;/p&gt;

&lt;p&gt;Remember that you won't be able to use any Component exported from this mentioned library as this are intended to be used on web only but not on React Native.&lt;/p&gt;

&lt;p&gt;Hope this hacks helps you to use this lib on your RN projects!&lt;/p&gt;

</description>
      <category>prismic</category>
      <category>reactnative</category>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
