Posts

Showing posts from June, 2020

Lint on Save With VS Code Official Golang Extension

Image
The post Lint on Save With VS Code Official Golang Extension appeared first on Qvault . Go has hard opinions about how you should style and format your code. The big upside of this is that you don’t need to spend hours setting up tools like ESLint, Prettier, JSLint, etc. That said, in order to take advantage of the styling and listing tools available in the toolchain, you need a dev environment that makes them easy to use. VS Code – Lint on save I’m currently a VS Code fan. I don’t like to think about code styling. I like to type a bunch of code with incorrect spacing and press (ctrl+s) or (cmd+s) to save my code and auto-format it. First, make sure you have the latest version of Go installed on your machine (as of time of writing, 1.14) Next install the Official Golang VS Code Plugin Next open your settings.json file in VS Code. These settings can be specific to in a single project, workspace or your entire machine. Add the following settings: { "go.lintOnSave...

Make, New and Literals Cheat Sheet – Slice and Map Initialization in Go

Image
The post Make, New and Literals Cheat Sheet – Slice and Map Initialization in Go appeared first on Qvault . There are quite a few ways to create new maps and slices in Go. Which one is best? Or perhaps better asked, which one is best in your situation? Let’s take a look. Slices var varStyle []string literalStyle := []string{} newStyle := new([]string) makeStyle := make([]string, 0) var varStyle []string is the idiomatic way to declare an empty slice. The slice is actually nil , which means it will be null when marshalled to JSON and will succeed nil checks. literalStyle := []string{} should probably only be used when the literal is going to start with values in it , as in literalStyle := []string{“cat”, “dog”, etc} . Otherwise prefer make() newStyle := new([]string) returns a pointer to the slice. Same as ptrStyle := &[]string{} . Only use if you want a pointer. makeStyle := make([]string, 0) is the same as the literal style, but is preferred for idiomatic reasons...

An Intro to Quantum Mechanics; Google’s Claim to Quantum Supremacy

Image
The post An Intro to Quantum Mechanics; Google’s Claim to Quantum Supremacy appeared first on Qvault . The science that deals with the description of the motion and interaction of subatomic particles is known as Quantum Mechanics. Traditional computers utilize the physics of electricity, the flow of electrons controlled by switches, to control their logic. Quantum computers rely instead on the physical properties of electrons, photons, and other tiny bits of matter which are subjected to the laws of quantum mechanics. This kind of tiny matter is best described in states called amplitudes (which can act as particles and waves). A particle can have two different amplitudes at the same time, which is a state called superposition. A particle can also be entangled, meaning a change in one particle instantly changes the entangled counterpart. The amplitudes of particles can also cancel one another out like opposing waves in water would. The smallest particles in nature don’t really exist...

How to Get Consistent Line Breaks in VS Code (LF vs CRLF)

Image
The post How to Get Consistent Line Breaks in VS Code (LF vs CRLF) appeared first on Qvault . Ever had the problem where you submit a pull request and the diff is waaaaay bigger than it should be? The code looks identical but GitHub is telling you that it’s all different! This is typically due to a difference in line endings. Unix systems (Linux and Mac) default to the LF (line feed) character for line breaks. Windows on the other hand is “special” and defaults to CR/LF (carriage return AND line feed). The Quick Fix If you are here to quickly fix a single file that you are having problems with, you are in luck. At the bottom right of the screen in VS Code there is a little button that says “LF” or “CRLF”: Click that button and change it to your preference. Voila, the file you are editing now has the correct line breaks. The Big Fix If you want new files to automatically have the correct line endings, then you can set the following setting in the top level of your setting...

Simple Setup – Vue Linting in VS Code

Image
The post Simple Setup – Vue Linting in VS Code appeared first on Qvault . I’m a gopher by nature, so I expect consistent styling and linting in my codebases. More importantly though, I don’t like to think about styling. I like to type haphazardly and then have my editor apply styling automatically on save ( ctrl+s , cmd+s ). If you are the same way, hopefully this will help you in your next Vue.js project. VS Code – Download and Plugin Download VS Code After downloading VS Code, we are going to use 2 plugins. Vue 2 Snippets and Eslint . Vue 2 Snippets will basically just provide some Vue specific auto completes, but Eslint will do the more important work of linting our code. You will also want to add the following to your project using our package manager’s devDependencies if you don’t already have them: yarn add eslint --dev yarn add eslint-plugin-import --dev yarn add eslint-plugin-node --dev yarn add eslint-plugin-promise --dev yarn add eslint-plugin-standard --dev ...

Go-CoNLLU – Some Much Needed Machine Learning Support in Go

Image
The post Go-CoNLLU – Some Much Needed Machine Learning Support in Go appeared first on Qvault . Python is commonly seen as the AI/ML language, but is often a dull blade due to unsafe typing and being slow, like really slow. Many popular natural language processing toolkits only have Python APIs, and we want to see that change. At Nuvi , we use Go for the majority of our data processing tasks because we can write simple and fast code. Today we are open-sourcing a tool that has helped make our ML lives easier in Go. Say hello to go-conllu . What is CoNLL-U? The Conference on Natural Language Learning (CoNNL) has created multiple file-formats for storing natural language annotations. CoNLL-U is one such format and is used by the Universal Dependency Project , which hosts many annotations of textual data. In order to use these corpora, we need a parser that makes it simple for developers to utilize the data. Universal Dependencies How Does Go-Conllu Help? Go-conllu parses ...

Go’s WaitGroup == JavaScript’s PromiseAll??

Image
The post Go’s WaitGroup == JavaScript’s PromiseAll?? appeared first on Qvault . In applications that are i/o heavy, it can get clunky to synchronously execute high-latency functions one after the other. For example, if I have a web page that needs to request 7 files from the server before it can show the page, I need to asynchronously fetch all those files at the same time. The alternative will take much too long. This is where PromiseAll and WaitGroup come in. Let’s take a look at an example of synchronous* JavaScript code: const fetch = require('node-fetch') async function runSync() { const resp = await fetch('https://qvault.io') let text = await resp.text() console.log(text) const resp2 = await fetch('https://github.com') text = await resp2.text() console.log(text) const resp3 = await fetch('https://gitlab.io') text = await resp3.text() console.log(text) } runSync() *Note: Due to some technicalities wit...