<?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 Almenon on Medium]]></title>
        <description><![CDATA[Stories by Almenon on Medium]]></description>
        <link>https://medium.com/@almenon214?source=rss-1a9e511fa74c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4FAOBq9qVna6uHkxaolTtA.png</url>
            <title>Stories by Almenon on Medium</title>
            <link>https://medium.com/@almenon214?source=rss-1a9e511fa74c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 19:17:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@almenon214/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[How I rearchitected my app by turning it off and on again]]></title>
            <link>https://medium.com/@almenon214/how-i-rearchitected-my-app-by-turning-it-off-and-on-again-45ca1b3866ff?source=rss-1a9e511fa74c------2</link>
            <guid isPermaLink="false">https://medium.com/p/45ca1b3866ff</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Almenon]]></dc:creator>
            <pubDate>Sun, 24 Nov 2024 00:16:37 GMT</pubDate>
            <atom:updated>2024-11-24T00:16:37.659Z</atom:updated>
            <content:encoded><![CDATA[<p>I made an open-source free <a href="https://marketplace.visualstudio.com/items?itemName=almenon.arepl">VSCode extension</a> that lets you program Python in ‘real-time’, with variable values displaying and updating as you code. It’s somewhat like <a href="https://quokkajs.com/">Quokka</a> or <a href="http://lighttable.com/">LightTable</a> but for Python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7UMQnidr0Q5B2PS4B9axNw.gif" /></figure><p>The frontend is written in Typescript, with a simple HTML generator and a modified form of <a href="https://caldwell.github.io/renderjson/">renderjson</a>. The backend is a Typescript package that communicates with a Python core with something a tad unusual: A fourth standard I/O channel. You’ve probably heard of stdin (standard in), stdout (standard out), and stderr (you can guess), but have you heard of stdTove, the little-known but legendary channel written by Tove Torvalds, wife of Linus Torvalds, open-source-hacker, and a six-time Finnish national karate champion? Probably, not, because I just made it up¹. Turns out you can have an arbitrary number of I/O channels, and name them whatever you like!</p><p>Why on earth would you do that, you might ask? The Python core executes the user’s code, which probably already writes to stdout. When the program finishes I send the variables back to the frontend, but I don’t want to get the state of the variables mixed up with the print output. I use a fourth channel so I can keep my variables uncorrupted by print results. Speaking of which, I use Jsonpickle to serialize (‘pickle’) the variables for sending over I/O. NodeJS batches I/O in 64KB chunks, which breaks JSON parsing, so I wrote a <a href="https://github.com/extrabacon/python-shell#newlinetransformer">NewLineTransformer</a> so I can parse the full message at once.</p><p>But all this and much more is really just cruft around the heart of AREPL: Python’s exec function. Basically, AREPL is this:</p><pre>locals = {}<br>code = input()<br>exec(code, locals)<br>print(locals)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*CGyeIt_O8TT3nMJSufdEYg.png" /></figure><p>Each run the <em>locals</em> variable is reset so that AREPL can quickly evaluate your code while you’re typing without side-effects. Unfortunately, this idea didn’t quite pan out. Side-effects include:</p><ul><li>Filesystem changes, HTTP calls, and other external changes</li><li>Global variables in imported Python files</li><li>ContextVars</li><li>Event loop status</li><li>Persistent (‘static’) variables in Python C/C++ extensions</li></ul><p>I leave the first bullet point, external side-effects, up to the user to avoid. This sounds scary, but personally I find that I rarely run into issues with it. If code has irreversible side-effects, like deleting a file, I just don’t run it in AREPL. The vast majority of the time I’m testing snippets of code without external side-effects. Still, I offer a setting AREPL.whenToExecute to turn off real-time mode if they wish. I also have a special #$end comment that can <a href="https://github.com/Almenon/AREPL-vscode?tab=readme-ov-file#end">come in handy</a>.</p><p>The other side-effects are AREPL’s responsibility to deal with. I tried fixing it with various methods, like <a href="https://github.com/Almenon/AREPL-backend/blob/a55aa7f0827fe890675215e937badcf24878ee79/python/arepl_python_evaluator.py#L228">resetting the Python imports before each run</a> (took a while to get this one working), or resetting the event loop, or resetting the context, but with each bug I fixed another would pop up. I decided to take a entirely different approach.</p><p>To fix the side-effects I would just restart the whole Python process after each execution! This nuclear approach had the benefit of not just solving all the existing bugs, but totally eliminating any other side-effect bugs that might have existed. The downside was the extra CPU and delay needed for a restart. A restart would take just a second, but even that would cause the user to notice.</p><p>To prevent the user from waiting I started three Python processes. By alternating between them there was almost always a free process that was able to take the users code without delay. Extra CPU usage was negligible. Extra processes just wait on stdin. Memory usage? Not negligible, but still small. For those DevOps folks out there, it’s like I took a webserver, ran it in HA², and put it behind a LB³. The actual algorithm was slightly more complex, and refactoring was more difficult than anticipated, but that’s basically it. Turns out I could fix a slew of bugs just by turning it off and on again!</p><p>The moral of the story is sometimes what seems like a crazy idea is actually possible. Back when I first thought of AREPL the idea seemed crazy, but it was surprisingly easy to get a prototype going. I was skeptical I could restart the entire backend without a massive performance hit, but that worked out too. Next time you have a crazy idea, try it out! It will be harder than you had planned, but that’s okay. Maybe with some little tweaks, it will work just as well or better than you imagined ✨</p><p>¹ Partly made up. Linus really is married to a six-time Finnish national karate champion.</p><p>² HA: Hostile Apples</p><p>³ LB: Local Baloney</p><p><strong>Scratch:</strong></p><p>As with all major refactors, I ran into some snares, including a bug in Python itself, but in the end I got it working.</p><p>I didn’t expect to be able to execute code in real-time so easily, yet all it took was some logic around exec to get a prototype working.</p><p>If you ignore modification of state in external datastores, this looks immune to side-effects, as the locals is reset to an empty dictionary each time. Unfortunately, just importing a library can cause a side-effect,</p><p>The downside is extra resource usage, but I find the upside of extra reliability and speed is worth it. Even my old 2016 computer can handle it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45ca1b3866ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is enterprise-grade IaC?]]></title>
            <link>https://medium.com/@almenon214/devops-squared-e8607ba07f1c?source=rss-1a9e511fa74c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8607ba07f1c</guid>
            <category><![CDATA[platform-engineering]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Almenon]]></dc:creator>
            <pubDate>Sun, 14 Jan 2024 20:27:23 GMT</pubDate>
            <atom:updated>2024-02-03T19:18:41.072Z</atom:updated>
            <content:encoded><![CDATA[<p>In my current project I am a DevOps-DevOps Engineer, or DevOps² for short. This means I work on accelerating the rest of the DevOps team. Standardizing development practices, writing deployment pipelines, and spinning up meta-tooling. Normally DevOps does this naturally in the process of helping Engineering teams conquer their tech debt. But it turns out if you get DevOps busy enough, even the helpers need helpers. We are like any other team. The more that is demanded of us, the less time we have for tech debt. The longer this lasts, the slower our velocity gets.</p><p>Enter the DevOps². My current project is making our IaC (infrastructure as code) enterprise-grade®™. This term means nothing by itself, but it will sound very impressive to whoever you are speaking too. You could choose a different term, just don’t overdo it and describe your proposed architecture as “sushi-grade”, “S-tier Salami”, or “Kobe Beef-level Configuration Orchestration”. The important thing is it meets these four aspects:</p><ol><li>Modularity. Code should be packaged in modules, both for reusability and organization</li><li>Consistency. Linting and CI/CD tools like Github Actions should enforce standards for the codebase.</li><li>Deployment. There should be an easy way of deploying changes from one environment to the next. Common configuration should be shared. Code in one environment should be similar to the next environment.</li><li>Multi-account strategy. The code should be able to be deployed to multiple accounts in an automated fashion.</li></ol><p>Most IaC frameworks, in combination with CI/CD, support this functionality. The problem is the word “support.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PvcKhssowEZRZMCRr7NlEw.png" /></figure><p>The work to achieve this functionality can be significant.</p><ul><li>A thousand tutorials exist on <em>getting started</em> with IaC, but tutorials on enterprise-grade architecture are few and far between.</li><li>Sometimes you have to adopt external tooling like AWS CDK or Jsonnet, adding an extra layer of complexity to your stack.</li><li>If you dislike complexity, simplified external tooling like Terragrunt or Helmfile exists. But these are very opinionated, so you lose flexibility.</li><li>You will need to make opinionated choices about naming standards and styles. But engineers have strong opinions about little things like tabs vs. spaces. Big things like changing a <em>naming convention</em>? Oh boy. You better start locking your doors when you sleep at night.</li><li>Chicken-and-egg problems. You want to create state storage for your IaC. Like a good DevOps engineer, you want to automate this for each account. To automate this, you use an IaC tool that requires state. You want to create state storage for your IaC². Like a good DevOps engineer…</li></ul><p>To top it all off, when you finally finish your project, you will be faced with the daunting task of migrating all the old resources to the new style. Easy — unless you are facing pressure to complete other projects and tasks simultaneously, which is likely the case.</p><p>It doesn’t have to be like this. I would like to see more built-in tooling for enterprise architecture, like how Django comes with an admin website. Or at the very least, documentation that makes it clear <em>from the start</em> that an enterprise architecture exists, is different than the normal architecture, and can be accomplished by following X and Y steps.</p><p>Imagine if:</p><ul><li>Helm had good built-in functionality for overwriting community charts</li><li>Terraform made it clear that using a single state for your account will eventually slow things down.</li><li>Terraform offered several different examples of how to maintain separate states across multiple accounts.</li><li>Atlantis had built-in linting, security analysis, and cost estimates.</li><li>CDK8s had an example of multi-cluster architecture in their <a href="https://cdk8s.io/docs/latest/examples/">examples section</a></li></ul><p>The community could improve significantly around enterprise architecture. But let’s be fair — so we could we. If we thought about the future more often, we could see the scaling problems coming in advance and act proactively to address them. When it comes to build out a new IaC architecture, put your DevOps² hat on. If you can, put more time into getting it enterprise-ready. That saying that premature optimization is the root of all evil? It’s true when you can just rewrite a few functions, <em>but less true when you have to re-architecture your entire repository</em>.</p><p>Take the time to get it right from the start. A quick job will result in a shoddy system that will be awkward to explain to the new hire. A longer job will result in a quality product you’ll be proud of. You won’t regret it.</p><p>Some practical tips:</p><ul><li>Set scheduled reminders for upgrades and end-of-life’s. <a href="https://endoflife.date/">https://endoflife.date/</a> has a calendar feed you can subscribe to at the bottom.</li><li>For every third mistake you make, put a linting rule in place to catch it automatically,</li><li>Combine Helm with Helmfile.</li><li>Terragrunt’s has a <a href="https://github.com/gruntwork-io/terragrunt-infrastructure-live-example">enterprise example</a>. Go Terragrunt!✨</li><li>Naming standards can seem silly at first, but they will pay off later when you’re writing automation that iterates across a standard set of names. It will also pay off you’re constructing permissions, so you can do something clean like read access to &lt;teamname&gt;-* instead of the terrible LOD (List Of Doom): read access to projectX, Daniel&#39;s Y, XKCD-&lt;team&gt;, &lt;env&gt;-eaglehawk, bobs-burgers-123151525111</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8607ba07f1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to walk Datadog without running out of money]]></title>
            <link>https://medium.com/@almenon214/how-to-walk-datadog-without-running-out-of-money-e4b0232a7f25?source=rss-1a9e511fa74c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4b0232a7f25</guid>
            <category><![CDATA[fintech]]></category>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Almenon]]></dc:creator>
            <pubDate>Thu, 14 Dec 2023 01:59:00 GMT</pubDate>
            <atom:updated>2024-02-17T17:35:41.255Z</atom:updated>
            <content:encoded><![CDATA[<p>So you’re interested in adding a APM, logging, or monitoring tool to your tech stack. Maybe you’re tired of maintaining Elasticsearch. Maybe you just don’t like Dynatrace. Whatever the case, you’ve heard of a new dog in data town: <a href="https://www.datadoghq.com/">Datadog</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/0*wasxCkMn3g0tsluT.png" /><figcaption>Cute, but wait till you see the price tag</figcaption></figure><p>You create an account and try it out. Setting it up on Kubernetes with helm is a breeze. All your logs and data are automatically forwarded. It’s easy and fast to query your data, and you can make stylish chart by the dozens. You love the UI and more importantly, the power-user shortcuts. The breadth and depth of features makes Datadog feel like the AWS of the monitoring world. Soon you’re hooked. What could go wrong?</p><p>You sign a contract, forward your production data to DataDog, a few hiccups, but things work out pretty well. That’s when you see your first real bill.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*_t-v7VXIGLg-jFGDzCWdJA.gif" /><figcaption>Oh no.</figcaption></figure><p>You remember all the <a href="https://chrisshort.net/the-aws-bill-heard-around-the-world/">articles</a> of <a href="https://renovacloud.com/awss-free-tier-scaring-the-crap-out-of-newcomers-with-large-bills/?lang=en">people</a> running up <a href="https://dev.to/ericjeker/comment/119k6">gigantic</a> AWS bills by accident? Well, Datadog’s got the same problem. A simple configuration error could set you back a grand, easy. Hitting the max spend on your credit card? Yep, I’ve seen that. If you misunderstand the billing model, or assume “monthly contract” means “monthly discount”, the bill could be far more than expected.</p><p>As one reddit user says:</p><blockquote>wingerd33: “The Datadog pricing model is actually pretty easy. For 500 hosts or less, you just sign over your company and all its assets to them. If &gt;500 hosts, you need to additionally raise VC money.”</blockquote><p>Let’s go through some Datadog offerings:</p><h3>Logging</h3><p>Pay for the number of log lines and the storage size of your logs. You can make this cheaper by lowering your retention window and archiving older logs in a S3 bucket. In my experience developers rarely need logs older than two weeks. The catch is that sometimes people will write inefficient log archive queries (“rehydration” queries) that can cost hundreds of dollars in re-ingest. Make sure to pair log archiving with training on how to use and query it. Set a <a href="https://docs.datadoghq.com/logs/log_configuration/archives/?tab=awss3#define-maximum-scan-size">max scan size</a> setting, which has the added bonus of mandating the developers run scan size estimates.</p><p>You can also try to save money by setting log exclusions in Datadog’s website. The catch is you still pay for storing excluded logs, but better than paying for both storage and log lines. If you <em>really </em>want to save money, you can exclude logs before they hit Datadog by raising your log level or <a href="https://docs.datadoghq.com/agent/logs/advanced_log_collection/?tab=configurationfile#filter-logs">configuring your Datadog agent</a>.</p><p>I <em>highly</em> suggest setting up an monitor to alert you when there’s a spike in logs. It’s fast and easy to create. See <a href="https://docs.datadoghq.com/logs/guide/best-practices-for-log-management/#alert-on-unexpected-log-traffic-spikes">https://docs.datadoghq.com/logs/guide/best-practices-for-log-management/#alert-on-unexpected-log-traffic-spikes</a></p><p>A possible cause of excess logs is long stack traces. I suggest avoiding these by using JSON logging, so stack traces come as a single line. As a bonus, JSON is automatically parsed by Datadog.</p><p><a href="https://edgedelta.com/">Edge Delta</a> offers a service that claims to reduce Datadog logging cost. I haven’t tried it, but it looked interesting.</p><h3>Custom Metrics</h3><p>Datadog charges you your average usage for custom metrics. Simple, but you can still get a unexpected bill. Why? A custom metric is defined as a “a unique combination of a metric’s name and tag values”. If you have two metrics, but each metric has a tag with 1000 values, you’re really looking at 2000 billable metrics. It gets better: If each metric has another tag (A/B), then you have 2*2000=4000 custom metrics. If the extra tag was not just A/B but a 1000 possible values, then you have 1000*1000=1,000,000 metrics. All this from just two metric names! It gets even more complex than this — I suggest reading the <a href="https://docs.datadoghq.com/account_management/billing/custom_metrics/?tab=countrate#counting-custom-metrics">full article</a>.</p><p>To be fair to Datadog, this is not a Datadog-specific billing issue. You could run into this cardinality problem with any Prometheus-style database.</p><h3>Infrastructure Monitoring</h3><p>This is very simple. Take the p95 percentile of the lower 99% of your host-hours above the high-water mark line, add in the baseline commitment, rank from most primes to least, and finally take the eighth highest measurement, unless you’re on the MHP plan, in which case you should baste the skin of every third EC2 host and multiply your Kubernetes nodes by 15. Simple.</p><p>But seriously, it can be a bit complicated. Let’s start with the basics.</p><blockquote>Each hour, Datadog records the number of unique hosts you are monitoring in the Infrastructure service.</blockquote><p>Don’t skim this. Really think about it. What are the implications of this?</p><p>The key word here is the word <em>unique</em>. This is even worse than taking the <em>max, </em>and has very unfortunate implications in certain scenarios. Let’s say you have one host up for one hour. The pricing would be 1*.03/hr = 3 cents. Now let’s say you have host A up for 20 minutes, host B for 20 minutes, then host C for 20 minutes. You only have one host up at a time, effectively it is the same as before. However, the pricing would be 3*.03/hr = 9 cents. We just tripled in price!</p><p>If you have a static set of EC2 servers, you probably went ‘okay, big deal. Who cares about this weird scenario?’ But if you’re running Kubernetes or other auto-scalers, you might have just gone ‘aaaaaaaaahhhhhhhhhhhh’. Nodes in Kubernetes are constantly at peril of being replaced, coming up, or going down. As a consequence, there’s a good chance your host cost will be higher than you expect. Keep this in mind as we go through the two different plan types.</p><p><strong>High-water Mark</strong></p><p>With the high water mark plan you are billed based on the 8th-highest hour in a list of hours sorted by number of hosts. The idea is you avoid outliers, but sometimes the outliers last longer than 8 hours, and your eighth highest hour is generally pretty expensive, so this plan may have severe drawbacks.</p><p><strong>Commitment</strong></p><p>With the monthly commitment plan you commit to a certain amount of hosts at a discounted price, while paying regular rates for any hosts above that. A 9-hour long spike would just incur regular rates for those 9 hours, instead of ruining your entire month like in the high-water mark plan. As a consequence, you have the potential of saving tens of thousands of dollars on this plan. However, this plan still has drawbacks. Take the following graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/0*kBIkL9LFc3B8qUAI.png" /></figure><ul><li>The blue line is the number of hosts</li><li>The red line is what you committed to</li></ul><p>If you average out the blue line, it approximates the red line, so you might think you have satisfied your commitment and will pay everything at reduced rates. That is not the case. You will <em>always</em> pay for the committed amount. You will pay for the red line, plus the blue line when it goes over the red line. Additionally, when the blue goes over you pay on-demand rates.</p><p>Important note: When I say ‘on-demand’ rates, I mean ‘expensive’ rates.</p><p>In conclusion, do not average out your hosts and think you matched the commitment. Accounting will expected to have been done with the lump sum payment for the committed amount at the start of the month or year,. They will not be happy to randomly receive on-demand charges. This brings us to <em>another</em> plan type.</p><p><strong>The Secret Plan Type</strong></p><p>This is a invite-only plan. I could tell you about it, but then I would have to kill you.</p><h3>APM</h3><p><strong>A</strong>pplication <strong>P</strong>erformance <strong>M</strong>onitoring bills both on hosts and number of spans. The host billing model is similar to the infrastructure host billing model. Spans is relatively straightforward — you pay for each function call (“span”) recorded in the APM Trace, with 1 million free spans for each host. This sounds like a lot of free spans, but trust me, it’s not. A program can easily make thousands of function calls for the processing of a single web request, and you may get thousands of those requests, so 3000x3000 = 9,000,000 and hey look you’re 9 times past your free spans already. Make sure your developers don’t go wild with adding spans and keep a close eye on your span count or <a href="https://docs.datadoghq.com/account_management/billing/usage_monitor_apm/">setup a automated monitor</a>.</p><h3>And More</h3><p>There’s many more Datadog’s offerings, each with their own quirks. One simple way you can reduce the price of a offering is by committing to a monthly or yearly contract. This <strong>does not</strong> apply to all offerings. Ask your sales representative for the exact discount on each product you commit to. If you’re a moderately sized company committed to a plan, you should be assign a CSM. They are less biased towards selling you products than sales representatives, so they can offer you great insight on your DataDog usage and billing strategy.</p><h3>Q: I’m lazy, can I just give Datadog their monthly wheelbarrow full of cash instead?</h3><p>Yes, and this is not actually a stupid question. If you make enough money you don’t need to worry about the bill. Your time is better spent on improving your company’s product. Unfortunately, the ‘right’ amount of money to spend is very hard to nail down.</p><ul><li><strong>Honeycomb</strong> estimates 30% of your cloud spend is normal. If you’re skeptical about this, you’re right to be cautious. This is a biased figure as Honeycomb wants you to spend more money on them.</li><li><strong>Random Redditors </strong>estimate 5–10% is normal.</li><li><a href="https://www.finout.io/"><strong>finout.io</strong></a> say their customers (likely medium to large companies) do 2–6% of their cloud spend.</li></ul><h3>Q: What if I just… don’t use Datadog?</h3><p>Sure, you could do that. It may even work out well for you. There’s a lot of good competition out there, like Grafana Labs and Lightrun. On the open-source side, Loki+Prometheus is a great choice. But keep in mind these three warnings:</p><ol><li>Other paid solutions can be expensive too. At the end of the day, all the companies are trying to get your money. I’ve personally also seen high costs with Dynatrace, Splunk, and Elastic. I’m not trying to call out those companies specifically, the point is you should <em>always</em> be on your guard.</li><li>Self-hosted solutions require more maintenance. Deploying a simple stack can be done in a day, but getting that stack HA, bug-free, and integrated with all your services can take months. If you go this route, make clear to leadership that you will need more time or headcount. To get your price estimate, add together infrastructure cost <em>and </em>labor cost. Multiply your hourly wage by 1.2 or 1.4 to get the actual cost to the company, as your hourly wage does not include the bonuses and healthcare and taxes that your company pays.</li><li>Datadog is simply one of the best solutions out there, and you pay accordingly.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4b0232a7f25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn Unicode in y Minutes]]></title>
            <link>https://medium.com/@almenon214/learn-unicode-in-y-minutes-60a8b2cef1d9?source=rss-1a9e511fa74c------2</link>
            <guid isPermaLink="false">https://medium.com/p/60a8b2cef1d9</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[unicode]]></category>
            <dc:creator><![CDATA[Almenon]]></dc:creator>
            <pubDate>Tue, 12 Dec 2023 06:49:36 GMT</pubDate>
            <atom:updated>2024-01-06T04:57:01.414Z</atom:updated>
            <content:encoded><![CDATA[<p>This post gives an overview of Unicode, along with a do-it-yourself example, practical tips, and illustrations. Let’s dive in!</p><p>Text has a binary representation in memory. a is 0110 0001, but let’s use hexadecimal (base 16), for convenience. a is 61, b is 62, and so on. The basic set of English letters and symbols is called ASCII, and a table that maps the character to hexadecimal (hex) number can be found <a href="https://www.asciitable.com/">here</a>¹.</p><p>However, most of the world does not speak English. They have different characters like the á in Spanish, seen in the word papá. This á is necessary to distinguish between papá (dad) and papa (potato). If we forced Spanish speakers to use ASCII, an innocent statement like “I want to stab my potato before putting it in the microwave” could be interpreted as the alarming sentence “I want to stab my dad before putting it in the microwave.” Or take the word “shi”, which in Chinese could refer to <a href="https://ninchanese.com/blog/2022/05/09/the-lion-eating-poet-the-meowsome-one-sound-poem-you-can-only-read/">so many things you could make a poem out of it</a>. If you used English characters for foreign languages, it could be very confusing to interpret even with context.</p><p>Back in the early ages of computers, everyone decided to prevent this confusion at once! Dozens of different standards were developed to represent non-ASCII characters. There was Windows-1251, GB2312, Shift JIS, <a href="https://stackoverflow.com/questions/8509339/what-is-the-most-common-encoding-of-each-language">and many more</a>. Each standard had its own set of characters that it supported and it could be incompatible with other standards! This lead to mistakes and corrupted text. A character in one standard could appear as a totally different character in another standard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*hBImmKIvpUVYYt99wBEFbQ.png" /><figcaption><a href="https://en.wikipedia.org/wiki/Mojibake">https://en.wikipedia.org/wiki/Mojibake</a></figcaption></figure><p>Fortunately, a standard was developed to encompass <em>all</em> the languages, Unicode! Most websites are in Unicode, specifically UTF-8, which we will get into later. UTF-8 is also the default on Mac, Ubuntu, and Windows 11³. In Unicode every character, symbol, and emoji has a number, even poor unused 🚡 (U+1F6A1) emoji and the ancient <a href="https://en.wiktionary.org/wiki/%F0%92%81%8F">𒁏</a> (U+1204F) symbol. This number (the ‘code point’) is the same across all platforms. Unfortunately, this number is more of a philosophical ideal than reality. When it comes to the physical hardware, we still need a way to encode this number into binary. And here we run into differing standards yet again. Unicode can be encoded either as UTF-8, UTF-16, or UTF-32.</p><p><strong>UTF-8: </strong>A variable-length encoding, where we encode text with 1 to 4 eight-bit blocks. In other words, 1–4 bytes.</p><p><strong>UTF-16: </strong>A variable-length encoding, where we encode text with 1 to 2 sixteen-bit blocks. In other words, 1–2 bytes.</p><p><strong>UTF-32:</strong> A fixed-length encoding, where we encode text with 32 bits (4 bytes).</p><p>Before we dive into these, let’s do a little exercise. Write the below and save it to a file.</p><blockquote>hi papá 😀</blockquote><p>Let’s say someone sent you this file. How would you tell the encoding?Sometimes files have a <a href="https://en.wikipedia.org/wiki/List_of_file_signatures">file signature</a> at the start. This may indicate the file type, or if it’s a <a href="https://en.wikipedia.org/wiki/Byte_order_mark">BOM</a> (byte-order-mark), it may indicate the encoding. You could write code to check the BOM, but you can also use tools that will guess for you:</p><p><strong>Windows: </strong>Open the file in Notepad and click save as. The guessed encoding is near the save button.</p><p><strong>Mac: </strong>Run file -I &lt;filename&gt;</p><p><strong>Linux</strong>: Run file &lt;filename&gt;</p><p>Now, what to do if there is no BOM? This may happen often!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/0*dj4RR6AzagkSvqr0.jpg" /></figure><p>The best you can do is to guess². UTF-8 is generally a good guess, but this may still go wrong, which can lead to � or other random characters. For example, 鿰肘 (“Elbow”) in UTF-16 becomes 😀 in UTF-8.</p><p>Now let’s do one more exercise. Make sure the previous file is saved as UTF-8. Install a hex editor⁵. If you use VSCode, there’s a <a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode.hexeditor">hex editor extension</a>. Open the file up in the tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*6clma5zKhX6wu03U4htxXQ.png" /><figcaption>The two dots to the right of ‘p’ is á and the four dots are 😀</figcaption></figure><p>Now you can visually see the hexadecimal used to store the Unicode letters in memory. You can see that the length of the character in memory is different depending on what it is. Keep in mind hex 20 is a space.</p><p>There are four categories of UTF-8 characters⁴, but for this example let us put the text into three categories:</p><p><strong>ASCII text:</strong> 2 hexadecimals (1 byte). Example: a (61)</p><p><strong>Text with accents:</strong> 4 hexadecimals (2 bytes). Example: á (C3 A1)</p><p><strong>Emojis &amp; More: </strong>8 hexadecimals (4 bytes). Example: <strong>😀 </strong>(F0 9F 98 80)</p><p>This is why “hi papa 😀” is only 9 characters long, yet takes up 13 pairs of hexadecimals (13 bytes). The á and emoji adds an extra 4 bytes. If you take a second look at the picture above (or better yet, install a hex editor!) it should start to make more sense.</p><h3>Encodings</h3><p>We might operate in pure Unicode during our program, but we need to encode the text when writing out to a file. Each encoding has a different storage size for each ‘block’. UTF-8 is more memory efficient, but UTF-32 is directly indexable. UTF-16 is the worst of both worlds. It came about for historical reasons and we will ignore it.</p><p><strong>UTF-8</strong>:</p><ul><li>Text takes one to four bytes, depending on character. This makes it very efficient at storing text.</li><li>p][a][p][á][ ][😃],would be stored as: [.][.][.][..][.][....]</li><li>p (1) + a (1) + p (1) + á (2) + ‘ ‘(1) + 😀(4) = 10 bytes</li></ul><p><strong>UTF-32</strong>:</p><ul><li>Text always takes four bytes.</li><li>p][a][p][á][ ][😃],would be stored as: [....][....][....][....][....][....]</li><li>p (4) + a (4) + p (4) + á (4) + ‘ ‘(4) + 😀(4) = 32 bytes</li></ul><p>UTF-32 takes up much more memory, but you can easily index it, iterate over it, and get a sensible character length. Counting the number of characters is faster as well. Contrast this to UTF-8, where a single character could have a length of 1–4 depending on the type.</p><p>Unicode is enormously complex, with odd terms you would expect to see in magician’s spellbook, like ‘astral planes’, For more on Unicode, <a href="https://dmitripavlutin.com/what-every-javascript-developer-should-know-about-unicode">this</a> is an excellent reference. Some other things to keep in mind:</p><ul><li>Default encoding behavior depends on the language and even the context inside that language. Behavior may be different if you’re dealing with hardcoded strings, file I/O, or transcoding. For example, see <a href="https://stackoverflow.com/questions/49991870/python-default-string-encoding">this stackoverflow</a> for Python.</li><li>Python gotcha: sys.getdefaultencoding() is not actually the operating system encoding, but in fact <a href="https://github.com/python/cpython/blob/88bac5d5044e577825db1f9367af908dc9a3ad82/Python/sysmodule.c#L913"><em>is literally hardcoded</em></a> to return utf-8. To get OS encoding, use locale.getpreferredencoding()</li><li>Python gotcha: Strings act like the theoretical platform-independent Unicode characters until encoded. Therefore, you can directly index, iterate over, and get a sensible length out of a Python string. However, they may take up more memory than a string in another language. When writing a string into a file the string needs to be encoded, so a knowledge of unicode details will still come in handy.</li><li>Javascript gotcha: Happy that the vast majority of websites use UTF-8? Think character encodings will never apply to you? Well, be prepared, because JS strings use UTF-16. You’ll definitely want to read <a href="https://dmitripavlutin.com/what-every-javascript-developer-should-know-about-unicode/">this reference</a>.</li><li>Rust gotcha: The length function returns the length in bytes, not in characters.</li><li>You can use a tool like <a href="https://unicode.scarfboy.com/">https://unicode.scarfboy.com/</a> to help you look up Unicode characters</li></ul><p>As you can see, there’s all sorts of tricky little details. If you’re still unclear, maybe you want to read this article again, but like, a version with better writing? And more in depth? And maybe let’s make the background a stunningly bright yellow? Don’t worry, <a href="https://tonsky.me/blog/unicode/">I got you fam</a>⁶.</p><p>¹ Make sure to look at the ‘Hx’ (hexadecimal) column.</p><p>² When I say ‘guess’, you could manually pick an encoding and try it out, but there are libraries that will use sophisticated analysis to guess for you, like charset-normalizer.</p><p>³ On Windows 10 and earlier you might see ISO-8859–1 (ANSI, aka Windows-1252) encoding, or maybe something else.</p><p>⁴ For a more detailed categorization, see <a href="https://en.wikipedia.org/wiki/UTF-8#Encoding">https://en.wikipedia.org/wiki/UTF-8#Encoding</a></p><p>⁵ Hex editors can also be used to read very large files that would hang in a normal editor, so it comes in handy from time to time</p><p>⁶ Can’t take the yellow? Open up the developer tools and try out document.body.style.backgroundColor = &#39;white&#39;</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60a8b2cef1d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tableau on Kubernetes: How not to design a Kubernetes offering]]></title>
            <link>https://medium.com/@almenon214/tableau-on-kubernetes-how-not-to-design-a-kubernetes-offering-b18decf30c18?source=rss-1a9e511fa74c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b18decf30c18</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[tableau]]></category>
            <dc:creator><![CDATA[Almenon]]></dc:creator>
            <pubDate>Sat, 04 Feb 2023 05:47:35 GMT</pubDate>
            <atom:updated>2023-02-04T05:47:35.570Z</atom:updated>
            <content:encoded><![CDATA[<p>Tableau announced that you can run their server on Kubernetes <a href="https://www.tableau.com/blog/deploy-tableau-server-linux-docker-container">back in 2021</a>. Now that it’s been a few years, let’s take a look and see how it is to setup.</p><p><strong>The Docker image</strong></p><blockquote>Tableau Server in a Container ships as a tarball download</blockquote><p>Okay, so we have to build the docker image ourselves, presumably using the downloaded docker file. Not a big deal, a single dockerfile is usually very simple.</p><blockquote>which includes shell scripts that give you the ability to create Tableau Server Docker container images in your local environment</blockquote><pre>➜  ~ tree Downloads/tableau-server-container-setup-tool-2022.3.1 <br>Downloads/tableau-server-container-setup-tool-2022.3.1<br>├── EULA<br>│   ├── COPYRIGHTS.rtf<br>│   ├── Commercial_EULA.txt<br>│   └── NOTICES.txt<br>├── README.txt<br>├── build-image<br>├── build-upgrade-image<br>├── build-utils<br>├── configure-container-host<br>├── customer-files<br>│   └── setup-script<br>├── image<br>│   ├── Dockerfile<br>│   ├── docker<br>│   │   ├── alive-check<br>│   │   ├── config<br>│   │   │   ├── bootstrap<br>│   │   │   ├── config.json<br>│   │   │   ├── tabsvc.yml<br>│   │   │   └── tsm-commands<br>│   │   ├── install-process-manager<br>│   │   ├── rpasswd<br>│   │   ├── run-tableau-server<br>│   │   ├── server-ready-check<br>│   │   ├── single-service<br>│   │   │   ├── clone_artifact_modifier<br>│   │   │   ├── independent-backgrounder-additional-config.yml.tmpl<br>│   │   │   ├── init<br>│   │   │   └── tsm_docker_utils<br>│   │   │       ├── README<br>│   │   │       ├── after-install-common<br>│   │   │       ├── after_install_service<br>│   │   │       ├── configure_service.bash<br>│   │   │       ├── graceful_shutdown.bash<br>│   │   │       ├── initialize_notify_dir<br>│   │   │       ├── install_service.bash<br>│   │   │       ├── run_container<br>│   │   │       ├── shared_utils.bash<br>│   │   │       └── status_check.sh<br>│   │   ├── stack-traces-from-coredumps<br>│   │   ├── start-process-manager<br>│   │   └── upgrade<br>│   │       └── upgrade-tableau-server<br>│   ├── independent.dockerfile<br>│   ├── init<br>│   │   ├── fake-chrpath-1.0-1.x86_64.rpm<br>│   │   └── setup_default_environment.bash<br>│   ├── shared_ind.dockerfile<br>│   └── upgrade.dockerfile<br>└── reg-info.json</pre><p>👀 A bit more than I was expecting, but let’s continue. Exact setup steps can be found <a href="https://help.tableau.com/current/server-linux/en-us/server-in-container_setup-tool.htm">here</a>. I’ll summarize the setup for this blogpost, but if you’re intending on actually building the image you should read the link in detail.</p><p>Tableau may not already have the drivers we need to connect to our data sources, so after we check the <a href="https://www.tableau.com/support/drivers">driver page</a> we should put the driver installation code in customer-files/setup-script. The image won’t have admin rights by default, so you may want to install other tools ahead of time as well. Remember to use -y to install without prompting if you run this in your CI!</p><p>You will need to complete the registration form, which is straightforward.</p><p>After that you will need to download the Tableau server rpm, which will be copied into the image.</p><p>Now Let’s build it:</p><pre>$ ./build-image --accepteula -i ../tableau-server-2022-3-2.x86_64.rpm<br>./build-utils: line 53: declare: -A: invalid option</pre><p>Ooops. This is a common MacOS error, and <a href="https://www.ianoutterside.com/bash-invalid-option/">easily fixed</a>. You may need to run bash build-image instead of ./build-image after you update bash. Let’s run this again:</p><pre>$ ./build-image --accepteula -i ../tableau-server-2022-3-2.x86_64.rpm<br>#12 25.27 Error: <br>#12 25.27  Problem: conflicting requests<br>#12 25.27   - package fake-chrpath-1.0-1.x86_64 does not have a compatible architecture</pre><p>This is probably because I’m running this on arm64 architecture machine. It works on a x86 machine. Now that we have the image, let’s check the size:</p><pre>$ docker image ls | grep -i tableau<br>tableau      9.12GB</pre><p>Wat. (・_・;)</p><p>Best practice is to slim the container size as much as possible, and I’m talking down to an ideal of ~5MB with distroless containers. It’s okay if you don’t shrink that far, of course, but 10 gigabytes is…. something else. Generally speaking, the larger the container, the larger the surface area for vulnerabilities. A security scan against this thing is not pretty, although to be fair, they rarely are. The other downside here is this image is so large that you may need to update your Kubernetes node volume size. A few cached versions of this could overflow your storage.</p><p>Let’s dive into why this container is so large. Literally, let’s dive into it via <a href="https://github.com/wagoodman/dive">https://github.com/wagoodman/dive</a> 😉. It shows us what layers contribute what portion to the image size.</p><ul><li>The base OS is ‘only’ 204MB.</li><li>A tableau setup script installing dependencies adds 174MB.</li><li>The rpm file copied into the image is ~3 gigs</li><li>When the rpm file is installed, it adds a whopping ~6 gigs</li><li>Other scripts add a small amount of space</li></ul><p>The rpm file is leftover after installation and presumably no longer needed, so if Tableau employed one of the tricks in <a href="https://stackoverflow.com/questions/26306059/docker-in-dockerfile-copy-files-temporarily-but-not-for-final-image">https://stackoverflow.com/questions/26306059</a> they might be able to save ~3 gigs. Switching to a smaller OS or minimizing dependencies could also save a bit of space. But I digress.</p><p><strong>The Kubernetes Deploy</strong></p><p>Now that we have the image, let’s deploy it via <a href="https://github.com/tableau/tableau-server-in-kubernetes">this repo</a>. The first thing we see here is “support level: community supported.&quot; Not good, but Tableau on docker <em>is</em> supported, and Kubernetes runs on docker†, so you can make your case to the support agent and maybe you’ll get lucky. If you think you’ll skip the support agent by posting a GitHub issue, don’t bother. The repo is not actively changed or watched over.</p><p>The repo doesn’t have a helm chart for us to use, but it does have a yaml file. Unfortunately, it’s not deployable out of the box. The CPU and memory requirements are far too low, which I can say from experience leads to a very slow and eventually failing install. You’ll need to up it to around 16 CPU and 64Gi memory. Unless you have a beefy computer, this isn’t something I’d bother trying to run locally. I would also up the EBS storage to the hundreds of gigs, as Tableau will quickly fill that space up with log files. Finally, they chose a deploymentrather than a statefulset , which is odd given that Tableau is a stateful service that relies on a EBS volume. Indeed, they literally recommend using a statefulset in their readme.</p><p>Now you can deploy it. It will take a long time for the pod to start, but once it does you can exec into it and run tsm status -v to see that status of the service. It will report back 20 or so different microservices.</p><p><em>Oh no</em></p><p>This explains why the container is that big — a natural consequence of trying to pack an entire business architecture into a single container. It makes the system a pain to debug. Each service is its own knowledge domain, with it’s own log file and peculiarities. Because there’s multiple log files they can’t write everything to stdout, so kubectl logs pod/tableau will not show you everything. You have to either exec into the pod and filter through logs with your unix skills or setup a forwarder for all the log files. You will also want to setup log rotation to avoid the logs eating up all the space in the EBS volume. I think you can guess at this point that multiple services in a single container is a antipattern, similar to having a large image, although in some ways there are one and the same problem. If you split up the services into one per container you would naturally have smaller images and all logs going directly to stdout.</p><p>At this point you may be going — “Okay, so a bit complicated, but back in the good ol’ days I used to cd around the server and grep through logs all the time, what’s the big deal?” From a classic sysadmin perspective you are correct, this is not that bad. Where my frustration came from is that I had gotten so used to the wonderful world of out-of-the-box helm charts with simple ephemeral containers that I forgot my days manually managing EC2 servers. If you come into Tableau prepared and with the right perspective, I’m sure your experience will be better.</p><p><strong>Maintenance</strong></p><p>Once the service is deployed it’s relatively stable. Changing the configuration is a pain, because certain options require the server to reboot, which takes about 10 minutes. We also ran into a memory leak, which you can solve naively by rebooting or take to Tableau support. My experience with Tableau support was a mixed bag. Expect them to call you back a day or month later. For backups you can either use the tsm utility to backup to different file storage location or backup the associated EBS volume using your preferred method.</p><p>To upgrade you need to build a special upgrade container and run that. Take note that the hostname must remain the same. It’s a pain compared to the dead-simple upgrade of ephemeral containers, but it works.</p><p><strong>Conclusion</strong></p><p>Deploying Tableau on Kubernetes is not fun, but it’s doable. For small to medium organizations they recommend using their hosted solution, for good reason.</p><p><strong>Foototes</strong></p><p>† Technically, Kubernetes can use any <a href="https://kubernetes.io/docs/setup/production-environment/container-runtimes/">CRI runtime</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b18decf30c18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ubuntu on Windows for Masochists on Windows]]></title>
            <link>https://medium.com/@almenon214/ubuntu-on-windows-for-masochists-on-windows-acaaf5705b2c?source=rss-1a9e511fa74c------2</link>
            <guid isPermaLink="false">https://medium.com/p/acaaf5705b2c</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[windows-subsystem-linux]]></category>
            <category><![CDATA[wsl]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Almenon]]></dc:creator>
            <pubDate>Sun, 10 Mar 2019 05:03:38 GMT</pubDate>
            <atom:updated>2021-03-13T15:52:08.696Z</atom:updated>
            <content:encoded><![CDATA[<h3>Ubuntu on Windows for Die-hard windows fans</h3><p>For the past couple years I have worked entirely in the microsoft stack. Typescript. C#. VB. MSSQL. IIS. Azure. and the list goes on…</p><p>But now I’ve joined a new company and they don’t use windows <em>at all. </em>It’s a total paradim shift. JS isntead of TS. Python instead of C#. Postgres instead of MSSQL. Ngenix and AWS instead of IIS and Azure.</p><p>I could say bye to windows. With thermite and a raft I could give my PC a decent viking burial. Then I would use a macbook air and sit in a coffee shop and say goodbye to ☕ENTERPRISE DEV☕ and become ⚡ROCKSTAR HACKER⚡.</p><p>But you know what? Over the years I’ve become a bit fond of windows. Its clunky. Its slow. But I grew up with it, damn it. So……</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*Y51dkUin1gi-anWdgFVOsg.png" /><figcaption>Pictured: not what actually happened</figcaption></figure><p>Enter WSL, the <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">Windows Subsystem for Linux</a>, also known under its much more akward acronym, <a href="https://www.reddit.com/r/bashonubuntuonwindows">BOUOW</a>. With this bad boy you can have a full blown ubuntu system <em>in the same environment as windows!</em> Hooray! Problem Solved!</p><p>But not so fast. You still have to learn all the new linux concepts and commands. And get ready for a clown car full of bugs….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*b52xZO2oYZ1ltIlTwQmPqQ.png" /><figcaption><a href="http://pbfcomics.com/comics/honk/">http://pbfcomics.com/comics/honk</a> other comics may be NSFW</figcaption></figure><p>For starters, let’s assume you installed ubuntu, upgraded it, and have the terminal up and ready to go. Or have shelled out a few bucks for <a href="https://www.microsoft.com/en-us/p/wlinux/9nv1gv1pxz6p?irgwc=1&amp;OCID=AID681541_aff_7593_1291904&amp;tduid=%28ir__r3gf2fplu0kfr06u0cigmvmrvu2xm2ozg1wgnbco00%29%287593%29%281291904%29%28%29%28%29&amp;irclickid=_r3gf2fplu0kfr06u0cigmvmrvu2xm2ozg1wgnbco00&amp;activetab=pivot:overviewtab">wlinux</a>. Next you should find a basic linux terminal tutorial and follow that, getting used to cd’ing to directories, ls’ing to see items, the basic stuff. Once you’ve mastered the basics you can put some handy dandy aliases in your .profile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea084852b941aceab395b1666e8ffd89/href">https://medium.com/media/ea084852b941aceab395b1666e8ffd89/href</a></iframe><p>Restart your terminal and test out a alias or two to make sure they work.</p><p>Then add a softlink to your windows drive. For me I used the below command:</p><pre>ln -s dev /mnt/c/dev</pre><p>Now you can <em>cd</em> into your windows dev folder.</p><p>But be warned, because WSL / windows interopability is still pretty buggy. I suggest keeping the two systems as seperate as possible, even if it means re-installing stuff on your ubuntu subsystem.</p><p>If you want to interact with windows from ubuntu regardless, keep these things in mind:</p><ol><li>If you try doing git status on a windows repo, it will report all the files as modified. To fix this set the following in your repo:</li></ol><p>git config --local core.autocrlf true<br>git config --local core.filemode false</p><p>2. If you ever need to use chmod or deal with permissions in the windows filesystem follow this stackoverflow: <a href="https://superuser.com/a/1343737/890079">https://superuser.com/a/1343737/890079</a></p><ul><li>see <a href="https://blogs.msdn.microsoft.com/commandline/2018/02/07/automatically-configuring-wsl/">this blog post</a> for more details.</li></ul><p>3. you can invoke windows utilities through <a href="https://stackoverflow.com/questions/515309/what-does-cmd-c-mean">cmd /C</a>. For example, cmd.exe /C echo hello world . Or you can invoke utilities directly by specifying .exe, like so: ipconfig.exe | grep IPv4 | cut -d: -f2</p><p>4. Vice-versa, you can invoke linux utilities on windows through wsl <em>command.</em></p><p>5. Docker doesn’t work well in WSL, along with some other miscellaneous feature and apps that don’t function properly.</p><p>Last of all, if you’re new to linux you probably want a handy reference to look up documentation on linux utilties. There is the <em>man</em> command, of course (<em>man ls to see ls docs) </em>but it can be a lot to read. I would suggest also downloading <a href="https://github.com/chrisallenlane/cheat">cheat</a>. cheat <em>command</em> will give you plenty of useful examples that you can use to quickly get up to speed. For starters, try out cheat grep</p><p>So to sum it all up, is WSL worth the hassle? If you’re going to be using WSL primarily, no. I regret not just setting up a ubuntu dual-boot straightaway, and that’s what I eventually ended up doing. But if you are working a minority of the time in WSL or just playing around with it, then I would heartily recommend it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acaaf5705b2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AREPL stats for 2018]]></title>
            <link>https://medium.com/@almenon214/arepl-stats-for-2018-18f36fd7a476?source=rss-1a9e511fa74c------2</link>
            <guid isPermaLink="false">https://medium.com/p/18f36fd7a476</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[application-insights]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[arepl]]></category>
            <category><![CDATA[telemetry]]></category>
            <dc:creator><![CDATA[Almenon]]></dc:creator>
            <pubDate>Sat, 02 Mar 2019 20:23:35 GMT</pubDate>
            <atom:updated>2019-12-23T00:31:05.345Z</atom:updated>
            <content:encoded><![CDATA[<p>See last post for june <a href="https://medium.com/@almenon214/arepl-stats-for-june-5e0c87636c3">here</a></p><p><strong>Q: How many people use AREPL now?</strong></p><p>Around 40 a week. This has increased <em>significantly</em> from last time, largely due to increased <a href="https://www.google.com/search?q=seo">SEO</a> by altering my title. Just a two-word change to my title (AREPL <em>for python</em>) caused the popularity to skyrocket. In fact, AREPL is now the <a href="https://marketplace.visualstudio.com/search?term=python&amp;target=VSCode&amp;category=All%20categories&amp;sortBy=Relevance">#2 extension</a> when searching for python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xzcJEt_uD0o9OXWbInlgTw.png" /><figcaption>I changed the title shortly before the giant mountain of new users at the end!</figcaption></figure><p><strong>Q: What nationality are the users?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*5bhHJosA-U02Mvpxju0LFA.png" /></figure><p>This is <em>a lot</em> more diverse than last graph! Seriously, <a href="https://medium.com/@almenon214/arepl-stats-for-june-5e0c87636c3">read my last post</a> and the difference is insane. US has gone from being the majority of the users to a small minority, and <em>not even the largest minority at that</em>. China and UK are both expected presences — but Brazil beating India and Japan really suprised me. That might be a outlier — brazil useage has gone down in 2019. I havn’t heard of brazillians having a big tech sector but brazillians feel free to correct me!</p><p>Looking at this graph makes me realize how US-centric I am. In retrospect, US being the minority is obvious. Also, special shout-out to the one user in Syria! Civil war ain’t gonna stop you from programming!</p><p><strong>Q: How often does a person use AREPL each week?</strong></p><p><em>for July, August, and September:</em></p><p>Heavy users: 32 <strong>(1%) </strong>have used it ten<strong> </strong>or more times. This is about <strong>once a week</strong> or more.</p><p>Light users: 227 <strong>(60%)</strong> have used it two to ten times. That’s a <strong>couple times a month</strong> at most.</p><p>Once only users: 121<strong>(32%)</strong> have used it <strong>only once</strong></p><p>The 1% conversion rate from newcomers to heavy users could definitely be improved. It’s not terrible — google drive only has a .5% conversion rate from free → paid users, for example. But compare that with spotify, and you can see that I have a lot of catching up to do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mk0SFolf-8bHFLfWhtjBQg.jpeg" /><figcaption><em>image from </em><a href="https://www.process.st/freemium-conversion-rate/">https://www.process.st/freemium-conversion-rate/</a></figcaption></figure><p>AREPL in 2018 was still very buggy — I’m hoping to see a rise in % heavy users with my bugfixes in 2019.</p><p><strong>Q: Has the error telmetry been helpful so far?</strong></p><p>Yes! The telemetry recorded a spike in the number of errors (specifically, people with the wrong python path configured) when I did one of my releases. Unfortunately, I thought this was due to the overall increased useage. It turned out that the mac version was broken due to a casing bug. After I fixed that the number of errors went down.</p><p><strong>Q: Any new telemetry logging?</strong></p><p>I’m now logging settings so I can if people actually use the settings I offer. For the most part, no. I see that printResultPlacement, showFooter, and whenToExecute are sometimes changed but that’s about it. The only setting that gets frequently changed is python path — but that’s to be expected.</p><p>Some final notes:</p><p><strong>Q: Where do I install AREPL?</strong></p><p><a href="https://github.com/Almenon/AREPL-vscode">Almenon/AREPL-vscode</a></p><p><strong>Q: How can I add application insights to my own extension?</strong></p><p><a href="https://medium.com/@almenon214/adding-telemetry-to-your-vscode-extension-f3d52d2e573c">Adding telemetry to your vscode extension</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18f36fd7a476" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The shape of the code]]></title>
            <link>https://medium.com/@almenon214/the-shape-of-the-code-e748b4ad211?source=rss-1a9e511fa74c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e748b4ad211</guid>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Almenon]]></dc:creator>
            <pubDate>Sat, 03 Nov 2018 01:04:06 GMT</pubDate>
            <atom:updated>2018-11-03T01:04:06.102Z</atom:updated>
            <content:encoded><![CDATA[<p>Code has a shape. For a small script, it might be a simple arrow. Stuff goes in, stuff goes out. A large script might be a mess of spaghetti, arrows going every which way. Intersections, crossings, dead ends, all forming a scary mess. As the code grows and grows the knots get tighter and tighter, until eventually it becomes impossible to untangle. “<a href="https://stackoverflow.com/questions/35772001/how-to-handle-the-signal-in-python-on-windows-machine/35792192#comment81619892_35792192">Abandon all hope ye who enter here</a>” the comments warn, because a single change could cause the whole system to catch on fire. Due to lack of testing and pressure from on high, most code ends up like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/0*X_lD3536xChxcWFJ.png" /><figcaption><a href="https://xkcd.com/844/">https://xkcd.com/844/</a></figcaption></figure><p>But in good systems, it’s less of a knot and more of a grid. Input follows sensible proper paths and logical output is returned. From the output, more code can be applied with yet more logic. If the code is good, eventually another library picks it up as a dependency, and that library picks <em>that library</em> up, and you end up with gigantic skyscrapers of code. Prime example: <em>any</em> popular npm package. It’s like reading the <a href="https://biblia.com/bible/Genesis5">geneaology of Adam</a>: vscode uses gulp-chmod, which uses gulp-symdest, relying on vinyl-fs, in turn relying on glob-stream, which uses micromatch, but that uses braces, and that has expand-range, which of course uses fill-range, and randomatic, and finally is-number. It’s a tower.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aEOpjR4k6AJatx2PlXczCg.jpeg" /><figcaption>You best hope no-one hacks is-number, or else we’re all screwed</figcaption></figure><p>Or maybe the shape of code is a pyramid — vscode doesn’t have just one dependency, it has <em>tons </em>of dependencies. One library relies on many other libraries, which in turn relies on other libraries, so on, expanding exponentially.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hd1p9SEP797mkIx6_ZHpdA.jpeg" /><figcaption>If you printed out books of all the code in the world and stacked them up it would be at <strong>least</strong> this high</figcaption></figure><p>Exponentially…. That sounds like a tree! An upside down tree, sure, but this is computer science land. And as long as we are there why a tree? You can view code as a fractal — the more in depth you look into it, the more confusing it gets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SvLps04fNfuo411Ae24gVQ.jpeg" /><figcaption><em>psychedelic AND healthy!</em></figcaption></figure><p>But why a fractal brocoli? Maybe it’s a onion. You peel back one layer of code, and there’s another layer. A function in that layer calls a library in a deeper layer, which makes a web request to the backend which hands it off to a ancient stored procedure in the legacy database and pretty soon you have twenty files open in the editor and you’re cying just like you’re peeling a real onion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yVtxlzSSgw_KrBEavRqEWw.jpeg" /><figcaption>Onions: a powerful metaphor for both <a href="https://www.imdb.com/title/tt0126029/quotes"><strong>ogres</strong></a><strong> </strong>and <strong><em>code</em></strong></figcaption></figure><p>Personally, I like the idea of code as a star. GET IT? <a href="https://en.wikipedia.org/wiki/A*_search_algorithm">A STAR??</a></p><p>…. I’ll show myself out.</p><p>What’s your shape?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e748b4ad211" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keeping yourself motivated as a coder]]></title>
            <link>https://medium.com/@almenon214/keeping-yourself-motivated-as-a-coder-a16a6fcf49c7?source=rss-1a9e511fa74c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a16a6fcf49c7</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[self-discipline]]></category>
            <category><![CDATA[motivation]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Almenon]]></dc:creator>
            <pubDate>Sun, 23 Sep 2018 20:13:32 GMT</pubDate>
            <atom:updated>2024-01-28T06:26:50.457Z</atom:updated>
            <content:encoded><![CDATA[<p>Programmers probably have one of the most distracting jobs in existence. Their entire workday is spent in front of a computer — a literally endless source of entertainment and pleasure, a limitless virtual heaven. With literally just a click of a button, you could be in another world. You could be slaying dragons. You could be learning about the <a href="https://www.damninteresting.com/the-great-molasses-flood-of-1919/">great molasses flood of 1919</a>. You could literally be doing <em>anything. </em>So why do programmers spend their time programming, a hobby that could only be described as exciting by masochistic workaholics?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S15R5ty8G-kRGo-ghk2EGA.jpeg" /><figcaption>Pictured: sticky, sweet, syrupy disaster</figcaption></figure><p>Well, the vast sums of money that a software engineer gets is a pretty good reason. Another reason is that they probably are workaholics. You don’t see doctors spending all-nighters at hackathons for a 20$ Starbucks giftcard, or linguists designing <a href="http://lhartikk.github.io/ArnoldC/">languages composed of Arnold Schwarzenegger quotes</a> as a joke.</p><p>Or maybe they do it for the pride. Making open source projects gets you virtual street cred — the bigger the project, the better the cred. Guido, the creator of python, is practically a king. Before abdicating his throne he was called the BDFL, or <em>benevolent dictator for life</em>. Contributing to a project is a way of becoming something greater than yourself and leaving a lasting mark on society. Make a commit, and git will forever stamp you into history, a hash 785b312 saying <strong><em>I was there</em></strong><em>.</em> <em>xNinja47, 4/30/2005, changed 3 files for the better</em>.</p><p>Or it could just be for practical reasons — you need to keep your skills sharp, after all. And open source work looks good on your resume. Not everyone loves programming — for some it’s just a high paying job to slog through until they get home to their families and social life.</p><p>But if you’re reading this article, maybe you <em>don’t</em> have anything to motivate you. Maybe reddit sounds like a good idea. Stop! Don’t do it! No <a href="https://i.reddituploads.com/788c8a3ab05243d59259410aa0eb71f9?fit=max&amp;h=1536&amp;w=1536&amp;s=47f691afce2df783c20f31d702427957">funny cat pics</a>! No <a href="https://i.redd.it/vkyg59t2ddp01.jpg">cute bears</a>! Keep on writing this medium article! (<em>I may be speaking to myself here)</em>. So without further ado, here is some strategies to employ for keeping yourself in shape:</p><ol><li><strong>Start off small:</strong> Big things have small origins. My major open-source project started off as a small experimental prototype I put together in just a day or two. Walk enough small steps and you’ll walk a mile.</li><li><strong>Deadlines</strong>: set deadlines for yourself — GitHub <a href="https://github.com/Almenon/AREPL-vscode/milestones?state=closed">milestones</a> and <a href="https://github.com/Almenon/AREPL-vscode/issues">issues</a> are great for this. If you look at my projects I have <em>hundreds</em> of issues I create for myself to keep track of my work. Another benefit of writing issues is that you have written documentation to refer to when you go back to working on it. Or if you’re not on GitHub, you can simply set up calendar events. Maybe even tell your friends that you will get something done by a certain time — that creates commitment.</li><li><strong>Releases. </strong>Your project is a piece of crap. It barely functions, the architecture is horrible, and <a href="https://en.wikipedia.org/wiki/Impostor_syndrome">you don’t even really know what you’re doing</a>. The last thing you want to do is to expose your baby duckling to the public. But at a certain point you have to cut your losses — you can’t just keep on working on something forever, because then you’re going to have burnout. And you may be pleasantly surprised. Maybe people will like it. Worst case scenario, people will hate it, but in the process of shitting all over it they inadvertently give you helpful advice to fix it. In fact, in my experience the detractors are more helpful than the fans, because they will give you actual advice, not just “oh that looks cool”.</li><li><strong>Maximize Fun</strong>. Look for more pleasurable and fulfilling fun, rather than lazy and cheap entertainment. For example, it’s far too easy to <em>control-n</em> to open a new tab and type in the letter r to get the autocomplete for Reddit. That’s just 3 keys and a enter. Reddit is fun, I love it, but its filled with low effort reposts. Taking the time to watch a show or even a movie might be a better idea — you have a clear chance to stop (at the end) rather than scrolling through reddit’s infinite amount of content. Just make sure to turn off <a href="https://help.netflix.com/en/node/2102">Netflix’s autoplay</a>. And if you’re addicted to Instagram reels, turn on <a href="https://help.instagram.com/750317295927782/?cms_platform=www&amp;helpref=platform_switcher">break reminders</a>. It’s a lifesaver!</li><li><strong>Take walks.</strong> Rest your eyes. Think about how to approach the problem. If you’re me, try reading while walking. It’s not that dangerous — you’ve only bumped into a pole once or twice.</li><li><strong>Get the support of others</strong>. Join a slack/discord community. Make a program that other people use. Ask for advice from your friends. Go to programming meetups. Go to <a href="https://medium.com/@almenon214/pycon-2018-6b1c45889e3b">programming conventions</a> — it’s a great excuse for a vacation, and it’s a lot less dry than it sounds. Go past your normal boundaries — you might be surprised as to what you are capable of.</li><li><strong>Add </strong><a href="https://medium.com/@almenon214/adding-telemetry-to-your-vscode-extension-f3d52d2e573c"><strong>telemetry</strong></a><strong> or </strong><a href="https://medium.com/@almenon214/setting-up-email-alerts-for-your-vscode-extension-using-azure-d755651b2e0d"><strong>alerting</strong></a><strong> to your program</strong>. It might not be practical for a small application, but it is <em>extremely </em>useful as a motivating tool. Every day I get emails from around the world. People use <a href="https://github.com/Almenon/AREPL-vscode">AREPL</a> in <a href="https://medium.com/@almenon214/arepl-stats-for-june-5e0c87636c3">New York, Canada, Brazil, Chile. Europe, Japan, Israel, and Pakistan</a>. Every day it’s a different country. It’s significant to know that people are using what I make and relying on me to continue developing it. In a similar vein, I also get emails whenever my reddit bot posts. I can see if people upvote it or if there are problems with the bot I need to fix.</li></ol><p>Hopefully these tips are helpful to you. If they are, I’d love to hear it. Or maybe you have a tip of your own — either way, leave a comment below!</p><p><strong>2024 Update</strong></p><p>Ironically, I’m no longer motivated.</p><p>Tip #6 turned out to be a double-edged sword. By focusing on statistics, I became disheartened when the statistics <a href="https://dev.to/almenon/arepl-stats-2019-lgl">stopped improving</a>. I should’ve kept in mind the stories of the individual users. Even though the statistics were disappointing, I was still getting glowing 5-star reviews. Additionally, conducting user interviews is an important piece of product research. Looking at statistics alone will not tell you the full story.</p><p>However, there comes a point at which it’s okay to move on from your project. I put years of work into <a href="https://github.com/Almenon/AREPL-vscode">AREPL</a> and I gained a satisfying conclusion — a well-paying job as a result, stories to tell, and plenty of hard-earned experience. <em>Despite all this</em>, when I lost motivation, I felt like a failure for abandoning the project. I had grand dreams that were not met. But <em>it’s okay</em> to not meet your dreams. This sounds defeatist, but bear with me.</p><p>There’s a common quote¹ “Shoot for the moon. Even if you miss, you’ll land among the stars.” Disappointment is natural, but as long as you land among the stars, you should look on the bright side. Well, not literally, because you’d be looking at a Sun and instantly burn into a f***ing crisp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sMSkzyDPK2MvhkJMmFVcIw.png" /></figure><p>You know what? Let me start over. <strong>The point</strong> is that if you don’t meet your dreams, it’s natural to be disappointed for a bit, but it doesn’t mean you’re a failure. First of all, never judge yourself. Judge your project. Second of all, judge your project not on your dreams, but on the results. These results could even be intangible things, like experience gained, and even failure gives experience, so you’re almost guaranteed to have a positive result. So don’t worry about the future². Just do it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*4XnT5K7nHoZcqyYivHphew.png" /></figure><p>¹ What this quote doesn’t mention is the stars are trillions of miles away, so if you miss you are destined to a fate worse than death, a near-eternity of floating in an empty void. A more accurate quote would be “Shoot for the moon. If you miss, you’ll die. The moon has no air so you’ll probably die there too.” but for some reason I’m not able to sell any motivational posters for this.</p><p>² Unless you have leveraged several credit cards and your emergency cash to fund your startup idea, in which case you should really look at the statistics for startup survival. It’s not pretty.</p><p>³ I love how you can have the most random, specific idea and someone online will already have built a <a href="https://www.demirramon.com/generators/undertale_text_box_generator">generator for that exact purpose</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a16a6fcf49c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Converting python-shell to typescript]]></title>
            <link>https://medium.com/@almenon214/converting-python-shell-to-typescript-8768162d3a55?source=rss-1a9e511fa74c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8768162d3a55</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Almenon]]></dc:creator>
            <pubDate>Wed, 15 Aug 2018 16:01:41 GMT</pubDate>
            <atom:updated>2018-09-04T15:05:34.694Z</atom:updated>
            <content:encoded><![CDATA[<p>When I became a maintainer of python-shell I inherited an out-of-date codebase. Requires, vars, callbacks — all relics of a bygone era. Clearly it needed a upgrade. But first — a conversion to typescript. I liked using typescript in <a href="https://github.com/Almenon">my other projects</a><strong> </strong>so why not python-shell too? It offers many benefits, like increased development speed, type safety, and not having to gouge your eyes out after looking at JS code.</p><p>The Upgrade was easy at first. Simple types like strings, numbers, etc.. are automaticaly inferred in most cases, so all it takes to get a typed variable is to switch from var Foo=5; to let Foo=5;. For variables declared before initialization you do have to specify the type, but that is simple as declaring “mode:string”, or “parser:Function”.</p><h4>Types</h4><p>But typescript is more powerful than primitive types like that — you can type out the functional arguments and return values as well. The parser from before became “parser:(param:string)=&gt;any”. It is a function that accepts a string and returns any type. Or for the mode, “mode?: ‘text’|’json’|’binary”. A nullable variable that only accepts three possible strings. Typescript can get <a href="https://github.com/Microsoft/TypeScript/issues/14833">far more powerful</a> and specific than this, but this is as complex as I needed.</p><p><strong>Generics:</strong></p><p><em>toArray</em> took any object and converted it into an array. The result typing was simple:</p><pre>// I take in a nullable param of type T and return an array of T<br>// ex: null -&gt; [], string -&gt; string[], or string[] -&gt; string[]<br>function toArray&lt;T&gt;(source?:T|T[]):T[] { ... }</pre><p>There was also <em>extend</em>, which added arguments as properties to the object:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38041f6b3d7c7906faa0a4ed7c203fce/href">https://medium.com/media/38041f6b3d7c7906faa0a4ed7c203fce/href</a></iframe><p>I have no idea how to properly type this one beyond addings …args, so I just manually cast it to the result type whenever I called it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d56c43791f19ff18538ce9dbc68f8b2/href">https://medium.com/media/8d56c43791f19ff18538ce9dbc68f8b2/href</a></iframe><h4>Scope</h4><p>Typescript is public by default, so for certain variables that were locally scoped I had to specify private. The old python-shell was not a class, but a function, and within that function it assigned <a href="https://github.com/extrabacon/python-shell/blob/b34e125c0ad487298df11e612f40fad9623ff6cd/index.js#L45">this to self</a>, on old trick to keep state. Within that self it had several private variables, <a href="https://github.com/extrabacon/python-shell/blob/b34e125c0ad487298df11e612f40fad9623ff6cd/index.js#L226">some of them</a> obvious, due to _name convention, and others that you had to look at to doublecheck. And <a href="https://github.com/extrabacon/python-shell/blob/b34e125c0ad487298df11e612f40fad9623ff6cd/index.js#L127">one variable</a> was actually static. Unit tests helped a lot in figuring out the proper scope — I initially marked exitSignal as private, when it was actually public.</p><h4><strong>Imports</strong></h4><p>Instead of the old require() I used import {class} from ‘foo’. One question I ask myself whenever I import something is WHY SPECIFCY THE PACKAGE AFTER THE CLASS YOU’RE IMPORTING??? <strong>Every other language </strong>has the import first.</p><ul><li>Python: from foo import fooClass</li><li>C#: import foo.fooClass</li><li>Ruby: require ‘foo/fooClass’</li><li>Haskell: import Foo(fooClass)</li><li><a href="http://rigaux.org/language-study/syntax-across-languages.html#PckgMdlmprt">And many others</a></li></ul><p>There is probably a reason for this and I would love to know what it is.</p><p>Fortunately, vscode can auto-import packages, so in many cases you don’t have to bother writing out the import.</p><p><strong>Unit Tests:</strong></p><p>Converting the unit tests was easier than the code. In the process of upgrading the unit tests I made some interesting discoveries, too. For example, the unit tests were calling PythonShell.run with the wrong argument. I also found out certan types I had marked private (exitCode and exitSignal) should have been public.</p><p>You can see all of my unit test conversion in [<a href="https://github.com/extrabacon/python-shell/commit/59ae03491007e37c8e6f2a3066d08c761a224a95">this commit</a>]. Overall not much work needed to be done.</p><p><strong>Did typescript catch any errors?</strong></p><p>Yep! When adding the <em>checkSyntax</em> feature, I didn’t return my promise correctly. This lead to a confusing error saying that the promise wasn’t caught despite me having a .catch in the unit test. Typescript automatically infers the return type, so when I hovered over the function I saw that it returned Promise&lt;void&gt; instead of the expected Promise&lt;{}&gt;. From there I quickly realized my mistake and fixed it.</p><p><strong>Publishing to NPM:</strong></p><p>I bumbled my way though this. I suggest following a <a href="https://medium.com/cameron-nokes/the-30-second-guide-to-publishing-a-typescript-package-to-npm-89d93ff7bccd">guide</a> instead.</p><p><em>Attempt #1:</em> npm used my gitignore which had .js files ignored, leading to a publish without the crucial js files, as I quickly found out when <a href="https://github.com/almenon/arepl-backend">arepl-backend</a> failed with the newest versino.</p><p><em>Attempt #2:</em> Arepl-backend passed all tests with version 1.0.1. I’m good, right? Apparently not — users quickly reported problems due a missing declaration file. In my tsconfig I specified</p><pre>&quot;declaration&quot;: true</pre><p>and I republished it with index.d.ts to solve their issue.</p><p><em>Attempt #3: </em>Apparently you can’t include ts files in your publish if the ts file fails strict mode. I added js files back into my gitignore and specified the exact files I needed for publish in my package.json</p><p><strong>The End Result:</strong></p><p>Old index.js: [<a href="https://github.com/extrabacon/python-shell/blob/b34e125c0ad487298df11e612f40fad9623ff6cd/index.js#L127">commit</a>]</p><p>new index.ts: [<a href="https://github.com/extrabacon/python-shell/blob/master/index.ts">commit</a>]</p><p>Hardest part: trying to write the darn medium article</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8768162d3a55" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>