<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Roy Segall on Medium]]></title>
        <description><![CDATA[Stories by Roy Segall on Medium]]></description>
        <link>https://medium.com/@roysegall?source=rss-37fdc129fe5c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*PI_59SVm-jJSR5Ub.</url>
            <title>Stories by Roy Segall on Medium</title>
            <link>https://medium.com/@roysegall?source=rss-37fdc129fe5c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 11:05:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@roysegall/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[My insights as a web developer in the MedTech industry]]></title>
            <link>https://medium.com/swlh/my-insights-as-a-web-developer-in-the-medtech-industry-adbb62831656?source=rss-37fdc129fe5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/adbb62831656</guid>
            <category><![CDATA[medtech]]></category>
            <category><![CDATA[developer-stories]]></category>
            <dc:creator><![CDATA[Roy Segall]]></dc:creator>
            <pubDate>Sat, 19 Jun 2021 17:01:00 GMT</pubDate>
            <atom:updated>2021-06-19T17:01:00.368Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GOO4mUGMxkcuAkwrb8qIvA.jpeg" /><figcaption>Designed by <a href="http://www.freepik.com/">www.freepik.com</a></figcaption></figure><p>I just finished up my two years of work in <a href="https://dreamed-diabetes.com/"><em>Dreamed Diabetes</em></a><em>. </em>I won’t go into what they do (since their website is pretty cool), but I would describe how it feels to be a med-teach company developer.</p><p>Yes, you probably wonder:</p><blockquote>“how that’s different than any other normal startup?”</blockquote><p>Not much, except for one thing — <strong>bureaucracy!</strong></p><p>If you thought that the startup you’re working for has too much regulation with the all daily meetup, issues on GitHub, and the tedious code reviews — Let me tell you something, you have not seen anything.</p><p>So, buckle up and let me take you on a journey on how a company with FDA-approved software operates in a field that saves people&#39;s lives.</p><h3><strong>An FDA approval for software?</strong></h3><p>In the last year, due to the Covid-19 pandemic, we got a glimpse of how medicine gets FDA approval and then distributed to the public. Of course, it took less time, but all the standard procedures were fulfilled — developing, testing the vaccine, and other steps that I won’t elaborate on.</p><p>There’s no difference with software in that aspect—first, the developers are working on the algorithm. The next step is to test it in the real world with patients (AKA “<em>clinical trials</em>”). Then, we need to collect data about what doctors or patients do not understand in the software; A good example is that the doctor misused a button.</p><h3>But where’s the real pain?</h3><p>When dealing with a standard hi-tech company, we would usually have issues on Github. The developer will start working on an issue, go through code review, wait for the CI to kick in, and eventually deploying to production.</p><p>If something went wrong — the production would be reverted to the previous version, the developer will create a fix and then go over the same process, but this time, hopefully, there will be no problem.</p><p>For an FDA product, the process is a bit different, and there a couple of steps:</p><ol><li>First, we need an <strong>SDD (Software Design Document)</strong>. The document will describe what we need to develop: a shiny blue button above the login form. Usually, the product team will write the SDD.</li><li>The next one is the <strong>SRS (software requirements specification)</strong>; it’s a document that says: “we need to add a button above the login form which leads us to the registration form” The SRS is a bit more technical than the SDD.</li><li>Lastly, we need to have something called <strong>STP (Software Test Plan)</strong>. Any change in the code must have a test. Sure, if you changed a YAML file related to the CI, we don’t need to add a test. But, if we change the logic, we must test for that since our product is critical. Remember, people&#39;s lives are at stake.</li></ol><p>There are more steps, but most of them are overlapping the stuff I’ve mentioned above.</p><p>Before deploying the code, we need to make sure they valid and good enough for review by the FDA. Once that’s over, we can deploy the code and start working on the next version.</p><h3>That’s all, folks</h3><p>So yeah, this is how I’ve worked for the past two years. It’s not easy, but you need to think of it from a good perspective — the product you developed helps people live better. Isn’t that amazing?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adbb62831656" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/my-insights-as-a-web-developer-in-the-medtech-industry-adbb62831656">My insights as a web developer in the MedTech industry</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction: Django Decorated Routes]]></title>
            <link>https://medium.com/swlh/introduction-django-decorated-routes-35c93fd3fee0?source=rss-37fdc129fe5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/35c93fd3fee0</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[mvc-frameworks]]></category>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[mvc]]></category>
            <dc:creator><![CDATA[Roy Segall]]></dc:creator>
            <pubDate>Sun, 29 Mar 2020 05:41:55 GMT</pubDate>
            <atom:updated>2020-03-29T05:41:55.447Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*thwyHkK04AT9l1S0x_-Bcg.png" /></figure><p>I&#39;ve been working with Django for the past year as my daily driver. Up until then, I worked with Drupal, Symfony and a bit of Laravel. One of the most common things between all of the above, and also for others frameworks, is that eventually there’s a file that contains all the routes and it’s can get big. Very big — in the project which I’m working on, alongside my co-workers, there are 100–130 endpoints which eventually brought the urls.py file to be 150 lines of code. Yikes.</p><p>For that, I created a small package called <strong><em>Django Decorated Routes</em></strong>. The package simplify the way we register routes in Django and you probably wonder — what’s the big deal with that? Well, I’ll show you but first, we need to cover some topics:</p><ol><li>HTTP servers and routers</li><li>How routes are defined in MVC and Microframeworks</li><li>How to use Django Decorated Routes to solve the mess.</li></ol><p>Let’s begin!</p><h3>Start from the basic: HTTP servers and routers</h3><p><em>Well, this section going to be a “101 of HTTP servers” kind of. If you already know how the hall HTTP servers works, skip to the next section.</em></p><p>One of the ways that we serve our logic to the world (browsers, mobile application, desktop application, communication with 3rd party services) is with something called “HTTP server”. I’m not going to deep into web protocols but I’ll simplify it like that: our web browser and the HTTP server are like Regina George and Cady Heron from the “Mean Girls” movie. Regina wants to hear some gossip on Ms. Norbury, Cady tells that Ms. Norbury sells drugs, Regina gets that data and then process that info — maybe writing it down in the “Burn book”.</p><p>If we’ll talk in more professionals terms the action in which Regina asks from cady something called a “<strong>request”</strong> and the gossip she’s getting called “<strong>response”</strong>.</p><p>There are a couple of HTTP servers. Applications based on PHP and Python are being served with Nginx/Apache, usually. Applications based on NodeJS or Go would probably use the built-in server, usually. Once an HTTP request is being sent to the server itself, the server forwards the request to a component called “router”.</p><p>All of the routers work the same: get the request type, could be GET, look for the matching logic unit which needs to handle that request, the view in our case. In the view, we might want to return a list of data, maybe some gossip. As I mentioned above, I’m not getting too deep so for now, the information will set you up for the of the article.</p><h3>MVC, Microframework — let’s talk about their routers</h3><p>Let’s look for a second on how routes are being handled in other places. We’ll start from the smallest.</p><p>Microframeworks — the idea is very simple: you only need an HTTP server. No DB layer, no fancy templating. In python, we have Flask (there are more but this the most notable). Node has Express.js. PHP have Lumen and Slim. There are more for each language but all of share the same pattern:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3863dadff7f1ac001830c6202ecf68d3/href">https://medium.com/media/3863dadff7f1ac001830c6202ecf68d3/href</a></iframe><p>MVC — Stands for Model-View-Controller. The idea is that you have a <strong>model</strong> that takes care of handling DB interactions, <strong>View</strong> which return data or do something and a <strong>controller</strong> which acts as the routing. Python has Django and Masonite while PHP has Laravel and Symfony. Defining a route usually takes place in a file. That file will hold all the URLs patterns and the reference to the view. Django’s file looks like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e16c8c98606fde53a617df2416d0e8bf/href">https://medium.com/media/e16c8c98606fde53a617df2416d0e8bf/href</a></iframe><h3>How Django Decorated Router simplify it for us?</h3><p>First, let’s see two issues that the flows above ar causing:</p><ol><li>Maintaining in two files — Defining a route involves two files at least: the file which holds the routes definition alongside the reference to the view and the file of the view.</li><li>Big file — for large projects, as I mention in the prologue, the file gets big. In a project I’m working on the urls.py is about 150 lines. Sure, we can split it into smaller files but now we need to maintain multiple files.</li></ol><p>So, the idea I’m presenting is basically stolen from the Symfony project. Symfony works a lot with annotations which are like decorators in Python but different. In Symfony, you can define routes in a file, just like Django, or with annotations like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b2e55e63d8ca356e26950b9d6b0adcd/href">https://medium.com/media/8b2e55e63d8ca356e26950b9d6b0adcd/href</a></iframe><p>I&#39;ve decided to take the same approach. Since Python has decorators built in the language, the flow is pretty simple: search for all the classes which have a @url_decoration on the class and just register it. Here is an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92eb5d4a1d320f18e6f8331391ae8cfc/href">https://medium.com/media/92eb5d4a1d320f18e6f8331391ae8cfc/href</a></iframe><p>In the urls.py file you should do this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e350b55127014a04c16e81cf283f4698/href">https://medium.com/media/e350b55127014a04c16e81cf283f4698/href</a></iframe><p>And that’s it - now you can place a view based class anywhere you want. One way to do it is going by a Symfony pattern. Let’s take for example the endpoint /api/user/login . Based on the file structure should be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80e8dce66882112dfb5e0f15cfbacaa7/href">https://medium.com/media/80e8dce66882112dfb5e0f15cfbacaa7/href</a></iframe><p>In case we have /api/user/login we would create another file, next to the login.py which will be called logout.py. Pretty simple and easy to understand. For more information, you can read the lovely <a href="https://roysegall.gitbook.io/django-decorated-routes">documentation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35c93fd3fee0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/introduction-django-decorated-routes-35c93fd3fee0">Introduction: Django Decorated Routes</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Masonite and VueJS]]></title>
            <link>https://medium.com/swlh/introduction-to-masonite-and-vuejs-e8538064a054?source=rss-37fdc129fe5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8538064a054</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[masonite]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[mvc]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Roy Segall]]></dc:creator>
            <pubDate>Sat, 07 Dec 2019 19:59:12 GMT</pubDate>
            <atom:updated>2019-12-28T15:54:59.044Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*866zvaK3S2b3Us04rprl7w.jpeg" /></figure><p>Currently, I’m working for a company named <a href="https://dreamed-diabetes.com/">Dreamed Diabetes</a>. My daily drivers are Django and React. But, before I used those awesome technologies I used something less cool — PHP, mainly Drupal, but also Symfony and Laravel. I said less cool because let’s face it — PHP is the language that people love to hate.</p><p>But, if we scoped out of the hate for PHP we can see that there are a lot of awesome architecture decisions in Laravel. For example:</p><ul><li>Larvel provides an awesome CLI: need a controller? Don’t copy and paste, just use the CLI for that</li><li>Service container and dependency injection — Yeah! free of charge</li><li>Simple to use ORM? Yes, eloquent is pretty much good ORM</li></ul><p>Django, which is the best apple-to-apple comparison with Laravel, lacks the above, but still looks like the go-to solution in the Python ecosystem. For a while, larval architecture has been missing to me until one day I heard an <a href="https://talkpython.fm/episodes/show/233/the-masonite-python-web-framework">episode</a> from the “Talk Python to Me” podcast. It was so good that I actually tweet about it:</p><h3>Roy Segall 🐈🍕 on Twitter</h3><p>As someone that came from #php and moved to #python as my daily job, when I heard @TalkPython podcast about @masoniteproject I told my self - Wow! @laravelphp in Python!</p><p>I was sure I’ll going to contribute something back to Masonite, and now when we have a competition for writing the best blog post — I’m in!</p><p>What are we going to discuss:</p><ol><li>Setting up a Masonite project</li><li>Setting up models and adding dummy content</li><li>Create a controller for serving our records</li><li>Connect it to a simple VueJS application</li></ol><p>You probably wonder to yourself — “Roy, Masonite’s documentation is pretty straight forward” — and indeed you are correct. But, it’s not that straight forward when writing a decoupled project. In the end, you’ll see how easy is to set up a REST endpoint and connect it to VueJS.</p><h3>Setting up our Masonite project</h3><p>Installing Masonite is pretty simple. First, check that you are qualified with the framework’s <a href="https://github.com/MasoniteFramework/masonite#requirements">requirements</a>. The <a href="https://github.com/MasoniteFramework/masonite#installation">installation</a> parts suggesting the next commands:</p><pre>$ pip3 install masonite-cli :: (may need sudo if using UNIX) ::<br>$ craft new project<br>$ cd project<br>$ craft install<br>$ craft serve</pre><h3>Setting up the DB connection</h3><p>Since this is just a simple demo of Masonite and VueJS, we’ll go with SQLite as our DB engine. Once you crafted your project, go to the <em>.env</em> file in the root of your project, search the DB connection section and replace it with:</p><pre>DB_CONNECTION=sqlite<br>DB_HOST=127.0.0.1<br>DB_PORT=3306<br>DB_DATABASE=blog.db<br>DB_USERNAME=root<br>DB_PASSWORD=root</pre><h3>Modeling our data</h3><p>Let’s create our blog model which eventually stores our blog entries. For that, we have a simple <em>craft </em>command that will scaffold the files:</p><pre>craft model Blog -m</pre><p>Craft CLI created for us a file called “<em>Blog.py” </em>under the “<em>app”</em> directory with the migration file, due to the -<em>m flag,</em> which in my case is — <em>2019_12_05_204818_create_blogs_table.py.</em></p><p>Migration is what changes for us the DB structure. Unlike Django’s migration files, Masonite took and approach which gives us “up” and “down” methods:</p><ul><li>The up method designed to change the structure when creating new features in the project</li><li>The down method gives us the option to revert the changes</li></ul><p>I’m pretty sure Django has a way to revert migration but this approach is much insane to me because if something went wrong in production we can revert the changes easily.</p><p>Our blog will have a couple of fields: id, created and updated at, title, body and author id so we could know who wrote the blog:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa4af27a02426474bc85fb54718cfb2f/href">https://medium.com/media/fa4af27a02426474bc85fb54718cfb2f/href</a></iframe><p>Now, we need to set up our model file which will tells Masonite how to interact when pulling records. This will be done in the “<em>Blog.py”</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09baa583acb6303370b46ea66a16304c/href">https://medium.com/media/09baa583acb6303370b46ea66a16304c/href</a></iframe><p>A lot of the file is described in the documentation but I’d like to focus on the serialize method. The method tells orator how to format the entry when converting to JSON format(similar to Django serializers). In this case, we added the author’s name alongside the author ID.</p><p>Now, let’s seed some dummy data so we could see how our application response. As before we have a command for that:</p><pre><em>craft seed blogs</em></pre><p>This will create for us a file called “<em>blog_table_seeder.py”:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9808dd38cc746e6f42b7f7a8b7de25b/href">https://medium.com/media/b9808dd38cc746e6f42b7f7a8b7de25b/href</a></iframe><p>This will create 25 blog entries each time we’ll hit the seed command. But that’s not over yet, we need to register our migration. Go to <em>seeds/database_seeder.py </em>and paste the next code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06cc9356e6dc90bb10fa8a12bdcf0f08/href">https://medium.com/media/06cc9356e6dc90bb10fa8a12bdcf0f08/href</a></iframe><p>After registering our seed file, which is what the code above is doing, we need to describe it to Masonite. Go to <em>config/factories.py</em>, and paste the next code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fbb11d81ba39e45958136becd620a4a/href">https://medium.com/media/8fbb11d81ba39e45958136becd620a4a/href</a></iframe><p>I’ve added the function <em>blog_factory </em>and registered it with — <em>factory.register(Blog, blog_factory). </em>The blog factory pulls all the user’s IDs we have in the system, selects the first 5 and pulls a random user id just so our dummy data will have various blog authors but you can apply any other logic you desired.</p><h3>Setting up controller</h3><p>We need to create something that will serve the records from the DB. Don’t worry, use the next command:</p><pre><em>craft controller BlogController</em></pre><p>We will get a file named “BlogController”. The file should have a “show” method out of the box, which correlates to GET requests. Retrieving all the blog entries should look like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5662dab14f44b8f4e1b837ff3e6b173c/href">https://medium.com/media/5662dab14f44b8f4e1b837ff3e6b173c/href</a></iframe><p>Notice that there’s only one line in the show method:</p><pre><em>return Blog.all()</em></pre><p>sweet! The next part is to stitch Masonite’s router to the method we just wrote. Go to <em>routes/web.py</em> and add to the ROUTES list the next member:</p><pre>Get(‘/blogs’, ‘BlogController@show’)</pre><h3>Putting it together</h3><p>After we set up all the things, let’s assemble it! First, we need to migrate our DB structure with the command:</p><pre><em>craft migrate </em></pre><p>This will create for us the file “blog.db” and the next output:</p><pre>[OK] Migrated 2018_01_09_043202_create_users_table<br>[OK] Migrated 2019_12_05_204818_create_blogs_table</pre><p>Next, we will need to seed our data with the command:</p><pre><em>craft seed:run</em></pre><p>You’ll need to see something like that:</p><pre>Seeded: UserTableSeeder<br>Seeded: BlogTableSeeder<br>Database seeded!</pre><p>Awesome! things look good. Now, we need to serve our application which we can do it with the command</p><pre><em>craft serve</em></pre><p>You’ll need to see something like that:</p><pre>Starting monitor for PID 75689.<br>Serving at: <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000</a></pre><p>You made it! Go to <a href="http://127.0.0.1:8000/blogs">http://127.0.0.1:8000/blogs</a> and you should see you’re blogs entries:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*02kWurYezPu13sximlB29w.png" /><figcaption>List of blogs. Notice that we various of author names. Pretty authentic, no?</figcaption></figure><h3>Let’s talk about VueJS</h3><p>VueJS is a front-end framework that exists for a couple of years and even though it’s not coming from Google or Facebook, VueJS looks like a good alternative: very simple, the learning curve is fast, has good documentation and a vibrant community.</p><p>Another awesome thing is the Vue CLI which like craft does a lot of heavy lifting for us. Let’s install it<em>:</em></p><pre>npm install -g @vue/cli<br># OR<br>yarn global add @vue/cli</pre><p>Vue CLI will give us scaffold commands and provides us the option to install plugins to improve our workflow, serving for us the development version of our app or compiling it for deployment. Let’s set up the project folder:</p><pre>vue create masonite-blog-front</pre><p>What awesome with the CLI tool that you can choose how to set up your project environment — with Babel or without, with typescript support out of the box or not and more. After Vue CLI set up for us all the stuff let’s go to the folder and serve the app:</p><pre>cd masonite-blog-front<br>npm run serve</pre><p>You’ll get something like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ocg-pbREwViEz-rtjbZ6w.png" /></figure><h3>Change “some” files</h3><p>You can browse the folders we just created and see their structure. I’ll walk you through on how I usually change my VueJS app. First, go to the <em>src/App.vue </em>(from now on, any location I’ll specify will be relative to the “<em>src”</em> folder):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61a284c704003ba5c836d6f54221ce40/href">https://medium.com/media/61a284c704003ba5c836d6f54221ce40/href</a></iframe><p>I remove the navigation because it’s redundant for now. The next thing is to add the Blogs component which will display for us the blog entries. Create a file called <em>Blogs.vue</em> in the <em>components</em> folder with the next content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bd28f155067166701ace1335b5eb54a/href">https://medium.com/media/8bd28f155067166701ace1335b5eb54a/href</a></iframe><p>We’ll no longer need to display the hello world so we going to remove it. Go to the file “<em>views/Home.vue</em>” and change it to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f109ae4c35b9af778390dc516f0d8938/href">https://medium.com/media/f109ae4c35b9af778390dc516f0d8938/href</a></iframe><h3>The Blogs component</h3><p>Each component in the project we got from Vue CLI has three parts:</p><ol><li>Template — This is the view of the component. It will contain text, other components we depend on and directive for iterate over items list or register mouse events</li><li>Logic — This is where we going to put all the logic: set the state, communicating with the server, declare dependencies on other components, etc. etc.</li><li>Styling — This is where we going to add some vibrant to our component: colors, spacing, sizing, etc. etc.</li></ol><p>Let’s start with some CSS. I usually do that first because then I can really see how my component will look. Luckily, there’s built-in support in SASS syntax. If you don’t know what is it I’ll just tell you that it’s an easy way to write CSS but won’t dive into it right now. You just need to add it to the “<em>Blogs.vue</em>” file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b2e19fc7b98d1983ffd7df3d8ccca61/href">https://medium.com/media/8b2e19fc7b98d1983ffd7df3d8ccca61/href</a></iframe><p>Now, we going to add the skeleton of the blogs component. Replace the template section with the next code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a69ed63ea0182d5af8f224aee7e91a10/href">https://medium.com/media/a69ed63ea0182d5af8f224aee7e91a10/href</a></iframe><p>Wow! Look at the next result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*B2BMC40Ie2df-9pp8PN8hQ.png" /></figure><h3>Let’s start to write some JS</h3><p>Each component has a state — a local state — which holds data about the component logic which in our case is the list of blogs. If we want to be fancy we can add a mode which tells us if the loading has been completed but for now, a list of blogs is good enough.</p><p>We will start by adding the data method. This is the method which describes the state of the application:</p><pre>public data() {<br>    return {<br>        &#39;blogs&#39;: [],<br>    };<br>}</pre><p>After setting up the state of the app we need to interact with the server. For that, we need to know about the life cycle hooks of our component. There are several, but we will use <em>mounted: </em>the hook which invoked when the component has been mount(similar to React’s <em>componentDidMount</em>). We’ll take some async/await approach for this one:</p><pre>async mounted() {<br>    try {<br>        const response = await fetch(&#39;http://localhost:8000/blogs&#39;);<br>        this.blogs = await response.json();<br>    } catch (e) {<br>        <strong><em>console</em></strong>.error(e)<br>    }<br>}</pre><p>We used the fetch function that will interact with our backend and ask for the data from the <em>“blogs”</em> endpoint we created in the first part. Then we’ll parse the JSON response and assign it to the blogs in the state. If you’ll add the method and hope to see some results you’ll get nothing. Looking in the console you’ll find out the next error:</p><pre>Access to fetch at ‘<a href="http://localhost:8000/blogs&#39;">http://localhost:8000/blogs&#39;</a> from origin ‘<a href="http://localhost:8080&#39;">http://localhost:8080&#39;</a> has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.</pre><p>If you’re not familiar with the error you should have a look at the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">Cross-Origin Resource Sharing</a> which will elaborate on that. We need to fix it so let’s go back to the server for a moment.</p><h3>A small fix to the server… You’ll almost there!</h3><p>CORS… For me, it has always been an annoying issue I need to solve when hooking the server and the frontend together. According to MDN article, we need to add the header <em>Access-Control-Allow-Origin</em>, but… how? A middleware!</p><p>Middleware is similar to the life cycle hook but in a router scope. In the middleware, I can do all sorts of things that relate to the response: adding headers, maybe log something or even adding the user object we pulled from the DB after authenticating the user. Don’t worry we have a command for that:</p><pre><em>craft middleware Cors</em></pre><p>You&#39;ve got a file named “<em>CorsMiddleware.py</em>” in the “<em>middleware</em>” folder. Open the file and paste the next code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f21f492ef978c3a5972e73b111c0f8cd/href">https://medium.com/media/f21f492ef978c3a5972e73b111c0f8cd/href</a></iframe><p>Don’t forget to add it to the cors list. How? Just look at the <a href="https://gist.github.com/RoySegall/e3e184fa1a8566f37cb49c92a3a4a5da">documentation</a>. Now, restart the server with the command:</p><pre><em>creaft server </em></pre><p>and let’s go back to the frontend!</p><h3>Back to Vue</h3><p>After handling the CORS issue in the backend now, we can apply some last things in our component. If you want to see the content just print the <em>blogs</em> variable by adding <em>{{blogs}} </em>somewhere in the template.</p><p>Now, we need to iterate over the blog&#39;s records and print it. VueJS has a directive called v-for which iterate over an array. For more information just read the “<a href="https://vuejs.org/v2/guide/list.html">List rendering</a>” part in the VueJS documentation. The code should look like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ed0b2b3d0d6301b8169c68fea103663/href">https://medium.com/media/0ed0b2b3d0d6301b8169c68fea103663/href</a></iframe><p>and the result is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*6IisHNEXB3RL_fYsURylBQ.png" /></figure><p>If you want to look at the entire component just go to <a href="https://gist.github.com/RoySegall/9a86e5789a653512cc1e438481dbdd54">this gist</a>.</p><h3>Wrapping up our journey</h3><p>Wow... What a journey, right? We started with nothing at all, then in a very short time, we got our self a backend with blog entries. Then, without any problems, we created a full-fledge VueJS application with a bunch of features. But, what next? It’s up to you. You can start by learning Masonite architecture and improve what we created by:</p><ol><li>Creating more models and bind them together — a comment system might sound good but you’ll have to implement the authentication process which is a good practice for the frontend and the backend</li><li>Add more routes to the Masonite application and display a single entry of a given blog(this would be handy for understanding how to get parameters from a URI) and apply the same thing to the VueJS application</li><li>Add an admin section — moderate you entries(blogs, users, comments, etc. etc.)</li></ol><p>I hope you had fun in this blog post and I hope I inspired you with some new stuff on the way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8538064a054" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/introduction-to-masonite-and-vuejs-e8538064a054">Introduction to Masonite and VueJS</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Electron “Open With” for Mac OSX]]></title>
            <link>https://roysegall.medium.com/electron-open-with-for-mac-osx-f215a1fe2ce1?source=rss-37fdc129fe5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f215a1fe2ce1</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[electron]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Roy Segall]]></dc:creator>
            <pubDate>Fri, 24 May 2019 10:34:10 GMT</pubDate>
            <atom:updated>2019-05-24T10:34:10.347Z</atom:updated>
            <content:encoded><![CDATA[<h3>Prologue</h3><p>I love Apple products but mostly, what I use every day for making money, is an operating system. I love Mac OSX, I think it’s one of the best OS for web development. No, Microsoft Windows is not good enough IMO for web development. One of the things that doesn’t exist on the Mac OS is a proper image gallery.</p><p>Yes, in the new versions of Mac OS you can see images in a different way from the finder or maybe use the default image viewer, but that’s kind of lame. I tried to find something in the App Store but most of the other solutions felt to me like:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FAVUpXu_21HA%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DAVUpXu_21HA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FAVUpXu_21HA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c339aed8801f95352f92526d86a7c414/href">https://medium.com/media/c339aed8801f95352f92526d86a7c414/href</a></iframe><p>So, what are the options? Well, that depends - are you the guy who talks or are you the guy who takes action? I’m usually the guy that takes action and decided to create a desktop app for that. Don’t get me wrong, this awful situation in which there is no good image gallery is been like this for years but only now I decided to do something about it.</p><h3>Weapon of choice</h3><p>So, as a web developer, I’m going to use Electron and since I’m pretty much a VueJS guy and the combination of the two looks OK. Yes, I’ve seen posts about Electron which people wrote it’s bad and not the best solution. But, if we will look at the bigger picture — Electron and VueJS for a web developer should achieve a quick solution. Since we going to access local files we don’t need any kind of database or some HTTP request library (ahem, axios, ahem).</p><p><strong><em>A small disclaimer</em></strong>: I’m not going to build in this blog post the components nor the architecture. In this blog post, we going to see how to access only the files that were selected and handled by the “Open With” option:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*e35yLmVrOwBXbu85rEo07Q.png" /><figcaption>In case you don’t know what is the “Open With” — here is a reminder.</figcaption></figure><h3>It’s time to build an app</h3><p>So, let’s start and scaffold an app - We can use <a href="https://github.com/SimulatedGREG/electron-vue">electron-vue</a>. In the readme section we have an explanation on how to set it up but, let’s write it here, just to be clear:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7c6d4dc8ecce676a338416efe684579/href">https://medium.com/media/f7c6d4dc8ecce676a338416efe684579/href</a></iframe><p>The process above created for us a full fledge electron application with a nice design and information that isn’t so relevant for us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*cM3LNeNzP2K2JcBLI_Jz9g.png" /><figcaption>After setting up the app, we get this nice view.</figcaption></figure><p>Since we want to show the selected files we can remove a lot of code and keep a clean page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*i3evfqHMgtJEOJek2tTiBA.png" /><figcaption>For now, we will start with a welcome message.</figcaption></figure><p>The code should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3db112dfa2f1bfc53349f3ba0c1a065c/href">https://medium.com/media/3db112dfa2f1bfc53349f3ba0c1a065c/href</a></iframe><h3>Quick Electron architecture introduction</h3><p>There are two parts: the main file, which is in the <em>main.js</em>, AKA the main process, and the rendering part, AKA render process, which is the section that our Vue JS app lives in which in our case its the <strong>render folder</strong>. The main process gets info from the OS and then creates the main browser window that loads our vue JS.</p><h3>How to know which files were selected?</h3><p>We can use a channel that sends data from the main process to the render via <a href="https://electronjs.org/docs/api/ipc-main">Electron IPC</a>. Sounds good, what next? We need to know which file(s) were selected by the “Open With” option. We can do that by using the <a href="https://electronjs.org/docs/api/app#event-open-file-macos"><em>open-file</em></a> event.</p><p>Now you probably saying to your self — let’s connect between the events and we can move on, right? The short answer is — no, we cannot do that.</p><p>The answer is pretty complex so stay with me: The <strong><em>open-file</em></strong> event is being triggered very early in the bootstrap process of our Electron application and the process which loads the application itself, which called <em>ready</em>, triggered after that<em>. </em>Both of the events may not be aware of each other thus leave our application without the important data — which files were selected<em>.</em></p><p>There are a couple of solutions — you can set up a server that runs in the background and then we can pull it with an HTTP request. But that’s a lot of moving parts that we need to corporate and maintain.</p><p>A simple solution would be to write to a file. The <strong><em>open-file</em></strong> event is being triggered for each file so we would need to concatenate them into a single array:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de0855d492875ba5b857485691ad71df/href">https://medium.com/media/de0855d492875ba5b857485691ad71df/href</a></iframe><p>At the <strong><em>ready</em></strong> event we will write the array of the files into a file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de0855d492875ba5b857485691ad71df/href">https://medium.com/media/de0855d492875ba5b857485691ad71df/href</a></iframe><p>Now, we need to read the file in the main VueJS app. Our only component should only display the files in a list and nothing more:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c98b4f8f1e6c207d5bf8134fa9b439d9/href">https://medium.com/media/c98b4f8f1e6c207d5bf8134fa9b439d9/href</a></iframe><h3>Notify the OS that we can handle files</h3><p>We need to notify the OS that our application can handle images. We would do that in the <strong><em>package.json</em></strong> files under the <strong><em>build</em></strong><em> </em>section in the <strong><em>mac</em></strong><em> </em>property:</p><pre>&quot;build&quot;: {<br>  &quot;productName&quot;: &quot;open-with&quot;,<br>  &quot;appId&quot;: &quot;com.example.yourapp&quot;,<br>  &quot;directories&quot;: {<br>    &quot;output&quot;: &quot;build&quot;<br>  },<br>  &quot;files&quot;: [<br>    &quot;dist/electron/**/*&quot;<br>  ],<br>  &quot;dmg&quot;: {<br>    &quot;contents&quot;: [<br>      {<br>        &quot;x&quot;: 410,<br>        &quot;y&quot;: 150,<br>        &quot;type&quot;: &quot;link&quot;,<br>        &quot;path&quot;: &quot;/Applications&quot;<br>      },<br>      {<br>        &quot;x&quot;: 130,<br>        &quot;y&quot;: 150,<br>        &quot;type&quot;: &quot;file&quot;<br>      }<br>    ]<br>  },<br>  &quot;mac&quot;: {<br>    &quot;icon&quot;: &quot;build/icons/icon.icns&quot;,<br>    &quot;category&quot;: &quot;public.app-category.photography&quot;,<br>    &quot;fileAssociations&quot;: [<br>      {<br>        &quot;ext&quot;: [<br>          &quot;jpg&quot;,<br>          &quot;jpeg&quot;,<br>          &quot;png&quot;,<br>          &quot;PNG&quot;,<br>          &quot;tiff&quot;<br>        ],<br>        &quot;description&quot;: &quot;Image files&quot;,<br>        &quot;role&quot;: &quot;Viewer&quot;<br>      }<br>    ]<br>  },<br>  &quot;win&quot;: {<br>    &quot;icon&quot;: &quot;build/icons/icon.ico&quot;<br>  },<br>  &quot;linux&quot;: {<br>    &quot;icon&quot;: &quot;build/icons&quot;<br>  }<br>},</pre><h3>Proluge</h3><p>Next, we need to build our application using:</p><pre>npm run build # Or yarn run build</pre><p>The application will be compiled into the <strong><em>build</em></strong> directory and you’ll see the <strong><em>dmg</em></strong> file that you’ll install your app with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*V1IqQUJmRLkWWVFh32uiQg.png" /><figcaption>The install dialog</figcaption></figure><p>Now, when the user will use the “Open With” option the application will appear:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tCSSd3pjiV_uT1JMgtk-Gw.png" /><figcaption>The open-with application is there!</figcaption></figure><p>If you can’t see the application, you might want is to use the “<em>Other…”</em> option at the bottom of the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*cV2jPISlBib0oE5L8kk75A.png" /></figure><h3>Bonus</h3><p>Since you read all the blog post and got here, have a look at two repositories;</p><p>First, the repository with the example code you saw in this amazing blog post: <a href="https://github.com/RoySegall/electron-open-with-demo">https://github.com/RoySegall/electron-open-with-demo</a></p><p>Second, If you’re looking for the app you can get it here: <a href="https://github.com/RoySegall/imaginary">https://github.com/RoySegall/imaginary</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f215a1fe2ce1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>