teleren/devto huggingface dataset:
(Nvim) Lua for Javascripters: Module Exports
Tags: lua, libuv, javascript, neovim
Published: 2021-04-08 18:00:53

---
title: (Nvim) Lua for Javascripters: Module Exports
published: true
date: 2021-03-31 00:00:00 UTC
tags: [lua, libuv, javascript, neovim]
canonical_url: https://teukka.tech/posts/js-to-lua-modules/
---

## Goals
This aims to be quick reference guide on lua module exports compared to JavaScript module exports.

## Task
We want to export a series of module scoped functions in both JavaScript and Lua. This guide also show side by side comparisons on writing a file to a specific directory and deleting a file from the same directory.

In this quick tip, we will use CommonJS as the format for the JavaScript modules since it more closely resembles Lua modules in its construction.

To export modules in NodeJS we would write:

```js
// filesystemUtils.js

const util = require("util")

const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
const readDir = util.promisify(fs.readdir);
const deleteFile = util.promisify(fs.unlink);

function writeDataFile(name, data) {
  const dataDir = getDataDir();
  const filePath = `${dataDir}${name}.json`;
  return writeFile(filePath, JSON.stringify(data));
}

function deleteDataFile(name) {
  const dataDir = getDataDir();
  const filePath = `${dataDir}${name}.json`;
  return deleteFile(filePath);
}

module.exports = {
  writeDataFile,
  deleteDataFile
}
```

Where `writeDataFile` and `deleteDataFile` are the function being exported. We could them access them by requiring the `filesystemUtils` module:

```js
const fs_utils = require("./filesystemUtils")

fs_utils.writeDataFile("test")
fs_utils.deleteDataFile("test")
```


In Lua, the syntax is quite similar:

```lua
-- filesystemUtils.lua

local M = {} -- initialize an empty table (or object in JS terms)

-- re-assign functions for convienience
local uv = vim.loop

-- assign the function to a key of the same name in the table
function M.deleteDataFile(name)
  local dataDir = getDataDir()
  local filePath = dataDir .. name .. ".json"
  return uv.fs_unlink(filePath)
end

function M.writeDataFile(name, data)
  local dataDir = getDataDir()
  local filePath = dataDir .. name .. ".json"
  return uv.fs_open(filePath, function (err, fd)
      if (err) then return end
      uv.fs_write(fd, data, function(err, bytes_written)
        if (err) then return end
        uv.fs_close(fd, function(err)
          if (err) then return end
        end)
      end)
  end)
end

return M -- This line exports the table
```

We can then use these functions in other code:

```lua
local fs_utils = require("filesystemUtils")

fs_utils.writeDataFile("test")
fs_utils.deleteDataFile("test")
```

Using modules in lua helps keep the global scope clean and makes it easier to refactor and reorganize code.
Increase WordPress uploads limit in Docker
Tags: webdev, wordpress, docker
Published: 2021-04-01 10:38:36

---
title: Increase WordPress uploads limit in Docker
published: true
date: 2021-03-31 00:00:00 UTC
tags: webdev, wordpress, docker
canonical_url: https://thomasxbanks.com/articles/increase-wordpress-uploads-limits-in-docker/
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qtkolg3m8vomdkla28el.jpeg
---
I've recently moved over to using [Docker](https://www.docker.com/) to manage my WordPress builds. It has many advantages and, the more comfortable I get, relatively few disadvantages. Not sponsored or anything, it's just boss!

One thing I find happens **every single time** is trying to upload an image into the Media Library and getting the "filename exceeds the maximum upload size for this site" error.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ib368419f2j382lvut14.png)

Inevitably, I find myself sticking `docker wordpress increase upload limit` into Bing (yes, [Bing](https://www.bing.com/)). There are a few answers knocking around - some of which I can get to work, some of which I can't.

This is the solution that I find works for me. I'm posting it here to save myself an hour of Googling next time! 😅

## Step 1: `uploads.ini`

Firstly, create an `uploads.ini` file in your project. I like to keep mine in a specific `config` folder with my `.htaccess` file.

## Step 2: Add your options

In the `uploads.ini` file, add the following:

```bash
upload_max_filesize = 16M
post_max_size = 24M
```

Feel free to change the values to suit your needs.

## Step 3: Include your file

The file now needs mounting using [volumes](https://docs.docker.com/storage/volumes/).

If you're using `docker-compose`, it will look a little something like this:

```yaml
version: '3.1'

services:
  wordpress:
    image: wordpress:5.7.0-php7.3-apache
    restart: always
    ports:
      - 80:80
    environment:
    volumes:
      - ./config/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
      - ./www/themes:/var/www/html/wp-content/themes:delegated
      - ./www/plugins:/var/www/html/wp-content/plugins:delegated

volumes:
  wordpress:
```

## And that's it!

Start or restart Docker and you'll no longer get nasty errors when you try to upload that massive photo.

Just be aware that upload limits exist for good reason - nobody wants to have to download a tonne of 10Mb 1920&times;1080 images that are only going to be used as 300px thumbnails…
Using json-server for quick databases
Tags: javascript, beginners
Published: 2021-03-30 23:43:50

This time, I would like to introduce a very handy npm package for creating & using a simple JSON database called json-server. For the official documentation from the developer, you can check this [site](https://www.npmjs.com/package/json-server) out. 

------------------------------

To start off, let's install the package, first! Just like any other npm packages, you can simply install it using npm.
```
npm install -g json-server
```
Once you have the package installed, the next step is creating a json file with the name db.json with some data in it.
```json
{
   "address": [
      "name": "Jacob Hunsaker",
      "address": "Somewhere in United States",
      "phone_num": "123-456-7890",
      "email": "jacobjhunsaker@gmail.com",
      "id": 1
   ],
}
```
Once you have everything set up, you can now actually use json-server. You can start json-server by going to the directory that has db.json and typing the following in the console.
```
json-server --watch db.json
```
Now if you go to [http://localhost:3000/address/1](http://localhost:3000/address/1), you'll get the following in JSON.
```
"name": "Jacob Hunsaker",
"address": "Somewhere in United States",
"phone_num": "123-456-7890",
"email": "jacobjhunsaker@gmail.com",
"id": 1
```
Now in your front-end (Vue.js & axios in my case), you'll just need to GET/POST/PUT/PATCH/DELETE the data into http://localhost:3000/address. Since we're using json, we'll also have to add the headers to your PUT/PATCH request.
```javascript
const response = await fetch(
               `http://localhost:3000/address/${id}`,
               {
                  method: "PATCH",
                  body: JSON.stringify(updatedContact),
                  headers: {
                     "Content-type": "application/json; charset=UTF-8",
                  },
               }
            );
```
For a sample page, please check this simple [Github](https://github.com/mimanjh/addressbook) repository using Vue.js.

If there are things I could improve on, please don't hesitate to let me know! I'm all ears :)

-JH
[LinkedIn](https://www.linkedin.com/in/jacobjhunsaker/) | [Github](https://github.com/mimanjh)
Help on Android Urgent
Tags: android, java
Published: 2021-03-30 23:28:50

Hello guys i really need some help here i'm working on a project and i was following a course on udemy but it's specific to android oreo version so some features are not working there and now i need a lot of advanced stuff to learn about android developement guys suggest me any course or a youtube chanell or udemy course to learn android develepoment
Centering content in the middle of a page
Tags: beginners, webdev, codenewbie, css
Published: 2021-03-30 23:22:37

Have you ever needed to center an element to the middle of a page? I would proceed to explain the simple way you can achieve that :)

![Challenge Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fklsfow0di05bzyifxsp.png)

The image above was gotten from a chellenge on [Frontend Mentors](https://www.frontendmentor.io) where you sign up and take challenges and try to make your solution look as close to the design as possible.

As you can see from the image above, the container of the whole content is centered in the page. This is what my solution currently looks like

![Unfinished Solution](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8yav15zfn56mb655fwzw.png)

As you can see, it's perfect with the exception of the container being in the center of the page. We will proceed to make it centered now.

![Absolute position styling to parent class](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/12nfw64ewpqejzjccghb.png)

Setting the position of the container to absolute takes it out of the flow of the document. Next thing to do is to set the top and left properties to 50% each.

![set top and left properties to 50%](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1fqmcnldse3z9v4u3wz.png)

The reason we did that was to set the container to 50% from the top of the page and 50% from the left. Our container now looks like this 

![challenge after adding 50% to left and top](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cnxprofhe9hrl2rc459z.png)

what actually happens here is that the origin of the container is its top left position, looking objectively at our solution would show you that the top left corner of our container is actually at the center of the page.

To make our container body appear at the body instead of just the top-left corner, we add a final style property.

![Final code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vu3997e3c4q8xz4jd0mx.png)

What the transform translate property does is to move the container and in general, it acts relative to the body of the container so the (-50%,-50%) moves the container backwards half of it's width and height, so originally if we had our width set to 600px, -50% moves it backward 300px and same goes for the height.

Our container should now look like this

![Final challenge look](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/otme47vcnj43c75i2da8.png)

So, with just 4 style properties, we were able to style our container and center it on our page. I hope you have a better understanding of how centering an element works now.

Here's a link to the [github repo](https://github.com/Ayoazeez26/bootstrap-grid-challenge)
Best (Mini-Projects) for Beginners with Java or other languages
Tags: beginners, javascript, programming, go
Published: 2021-03-30 23:02:23

Hey Guys, These are some projects I made, and some are under constructions with Java, I found it useful for improving your java programming skills, Enjoy...
<br>
Beginners projects (java core):
1- Math App that add numbers with GUI
2- Digital Clock
3- word count
4- Calculator (terminal or GUI)
5- BMI Calculator
<br>
Automation:
1- Keyboard and mouse Operations
2- sending email to multiple recipients
3- playlist of audio files with java
4- Cpu and Memory system spec. Check
5- create and merge multiple PowerPoints
<br>
I believe those are enough. I know too many are easy but they will give you a better understanding of programming :) BTW, it's better to save this message to come for it later
Alias Alias e mais Alias
Tags: shell, unix, profile, productivity
Published: 2021-03-30 22:47:24

Atualmente uso uma estação de trabalho linux, já usei Macs e já usei Windows e hoje posso dizer que a principal vantagem do ambiente Linux/Unix puro é a vantagem da configuracao do profile. Não que você não consiga algo similar em ambiente Windows. Mas a praticidade não é nem de longe igual.

Hj também uso o Oh-my-zsh com uma infinidade de plugins das quais não na maioria acabo não utilizando mas que estão ali e tudo facilmente configurável sem ter que recorrer a qualquer instalação duvidosa, e que na verdade permite que você instale tudo a partir do seu home e não comprometa as configurações do SO.

Resumindo a história meu objetivo é adicionar aqui os principais alias que acabo utilizando no dia-a-dia para ter uma referência pessoal e também um repositório público. Vou tentar anexar uma miníma.

aqui no caso uma referência rápida para editar o meu proprio profile.


```
alias ez="code ~/.zshrc"
```

E aqui uma referência rápida para reload da configuração ajustada (esse no caso preciso ajustar, pois do jeito que está ele ainda simplemente reexecuta o arquivo o que pode me gerar alguma duplicidade de caminhos no path ou alguma configuração errada caso eu fosse alterar alguma configuração externa ao arquivo, mas como eu não costumo fazer isso acaba não sendo um problema 😅)

```
alias rz="source ~/.zshrc"
```
Be confused!
Tags: haskell, opinion
Published: 2021-03-30 22:29:25

---
title: Be confused!
published: true
tags: haskell, opinion
canonical_url: http://bode-sh.vercel.app/en/2021/Be-confused/
---

I’m finally looking a bit deeper into Haskell. When I first saw the syntax, I didn’t know how to feel about it, but since someone told me about the concept of purely functional languages I was really curious to get to know them.

So, the choice fell on a [pandoc filter](https://pandoc.org/filters.html) to get into the language.  
That should be a fun but challenging and (hopefully) useful little excercise to get into the language.  
As I then was fighting with the, at first quite odd, syntax, wrinkles on my forehead - deeper than the rabbit holes I tend to fall into when I tackle a new topic - a thought wandered through my hea.  
What is it that keeps me interested in programming or even some tools and languages that are maybe a bit uncommon at best (this is written in vim) even when I’m most of the time confused as hell and feel like I don’t understand a thing?  
Are there some unexplored masochistic tendencies I should look into?  
Or is it just the challenge that I want to take?

I realized: The confusion is the fun part!

# Why so serious?

A spectator may conclude, that it’d be better off looking for different hobbies.  
Frustration is kind of a key part when I’m doing the things I like and some problems can really get on my nerves. But in the worst cases I just take a break and get something to eat. That always helps.  
Normally I swear like dock-worker from 1900s and munch on my teeths as if they are my lunch from the day before yesterday: chewy, lukewarm and barely edible.  
But I know that I just have to stare and swear long enough and one lucky night at 4am my jaw will drop and I will crumble my hair because the solution was either so obvious, outright stupid or ingenious.

So of course one of the most important things for hobbies (or probably life in general) is in my opinion that you can enjoy them, no matter how infuriating they are from time to time. But…

# Embrace the dumbness

The second thing - which ultimatly was the thought that inspired my to write this - is that confusion is the best indicator for the lack of understanding.  
And that’s what makes me continue.  
Because it puts me in a position where I can easily learn something new.  
When you’re convinced to know something, you (probably) first need to be proven wrong to open up to new thoughts (which isn’t inherintly bad. Of course should you reflect on your own thougts and understandings, but it’s also good to be confident in the things you know).  
When you know you don’t know what’s going on… You know that there is something to learn.

# Conclusion

So.

What’s the takeaway from this?

I realized, that confusion is a key part of what I love about learning. If I feel like I have a problem that has (probably) a solution, but I’m confused I don’t quit right away. It often keeps me going!

Let me know if you feel the same or if you hate confusion and I’m a total lunatic. :)
I want to write  with a scientific paper  don't know how to start  !!!
Tags: discuss, devops, cloudskills, career
Published: 2021-03-30 22:27:00

I like to work in these fields (devops methodology, api development, ci / cd, function as a service), and I want to contribute with a scientific paper. Is it possible for anyone here to tell me the latest findings of researchers in one of this fields or about anything I can work on in the areas I mentioned
Automated publishing to npm with GitHub Actions? Yes please!
Tags: javascript, github, devops
Published: 2021-03-30 22:15:13

Last year I wrote a post on [how to deploy to npm/NuGet/GitHub Packages with GitHub Actions](https://dev.to/aaronpowell/deploy-to-github-packages-with-github-actions-1274) and now you can watch it [in video form!](https://www.youtube.com/watch?v=WC-nsUmAeH0).

It's easy to setup and just gives that piece of mind when it comes to releasing a new version. Check out how below.

{% youtube WC-nsUmAeH0 %}
Battleforte Game Update: Special Tree for Backers/Supporters
Tags: indiedev, gamedev, game, environment
Published: 2021-03-30 21:38:43

Something #Majestic has begun taking root in #Battleforte's first map! #Backers/#Supporters will gain the right to be eternally engraved into this #Cuuby #Willow #Tree! Oh & here's sneak peek at the Map! #indiedev #gamedev #environment #unrealengine #madewithunreal #cartoon #wip

Ta-daaahh! Made a few more tweaks to 
@Quixeltools Mixer #Materials & #Cartoon #Shader, our wolf is pretty happy and #Battleforte now has extensively lush green grass -- The kind you wanna sink your feet into! #indiedev #gamedev #environment #unrealengine #madewithunreal

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zd7g82fb92ihhhbnltta.gif)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gmbx8205kkc9l166x43d.png)
TUI select fn
Tags: bash
Published: 2021-03-30 21:14:20

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/va7hx7fkv12mchnms18g.png)

Those of you familiar with **bash**'s *select* builtin know that the automated layout of choices is a nice feature. Last week while prototyping some SQL I became frustrated with *select*, mostly because you must type in a number and then press the Enter key.  Remembering the TUI interfaces of the 1980's, I set about writing *hkselect*, a hotkey driven replacement for *select*. Here are the main features:

* Automated layout of choices.
* Assign item hotkey with &.
* Automatic hotkey assignment if & is missing.
* Bind escaped keys to callback functions.
* Transparently caches layout information and composed labels.

Full project is [here](https://github.com/jrbrtsn/bash_plus_plus)

Below is an example **bash** program with a functioning hotkey TUI that includes callbacks for F1, F2, and F3:
{% gist https://gist.github.com/jrbrtsn/532dfc136383ce299efcbd0a44db9eac %}
Docker wale tank
Tags: docker, earthly, go, containers
Published: 2021-03-30 21:09:03

So I found this thing called earthly 
You can find the repo here:
https://github.com/earthly/earthly

🌍 Earthly is a build automation tool for the container era. It allows you to execute all your builds in containers. This makes them self-contained, repeatable, portable and parallel. You can use Earthly to create Docker images and artifacts (eg binaries, packages, arbitrary files).
How I Optimize PNGs
Published: 2021-03-30 20:43:21

---
title: How I Optimize PNGs
published: true
date: 2021-03-30 20:43:16 UTC
tags: 
canonical_url: https://codelab.farai.xyz/scribbles/optimizing-pngs/
---

_[How I Optimize PNGs](https://codelab.farai.xyz/scribbles/optimizing-pngs/) was first published on [Farai's Codelab](https://codelab.farai.xyz/)._
* * *

Here’s how I optimize images in three steps:

1. **Resize the image using [ImageMagick](https://imagemagick.org/index.php)** to the desired sizes. The size I usually convert to is a 240px width image for small screen devices like [feature phones](https://en.wikipedia.org/wiki/Feature_phone) that fit the media query of `(max-width: 400px) and (-webkit-device-pixel-ratio: 1)`.
  - If it’s a non-photogenic image inside a JPEG, I convert the image sizes to PNG using it.
  - If I’m converting an SVG, I use [Inkscape](https://inkscape.org/) (specifically [inkscape-cli](https://wiki.inkscape.org/wiki/index.php/Using_the_Command_Line)) since it’s very good at rendering SVGs.
2. **Use [CompressPNG.com](https://compresspng.com) to restrict the color palette** as much as I can using a slider. This makes a massive difference in file sizes.
3. Finally, I then **use [ZopfliPNG](https://github.com/google/zopfli/blob/master/README.zopflipng) to recompress the PNG** for a slight size reduction. PNGs use some sort of DEFLATE compression algorithm to compress all the image data—Zopfli is a <q>very good, but slow</q> implementation of DEFLATE. It’s a ~7% reduction which is just a handful of kilobytes.
4. Depending on the file size reduction and quality, I might also **convert it to WebP or AVIF**. This isn’t as common since PNGs ae really good at non photographic images.

This process is based on my naive understanding of how PNGs work. I want to make a comprehensive post on how PNGs work and on how to use that understanding to better compress PNGs. There’s a lot about the compression techniques, color indexing, sampling and the like.

## Glossary

<dfn>non-photographic image</dfn>—not a photo like illustrations, graphics and diagrams.
* * *

Thanks for reading! If you liked this post, consider [supporting my work](https://codelab.farai.xyz/support/) by:

- sharing my work,
- refering me for a job (or hire me for freelance work),
- sponsoring me on [Patreon](https://patreon.com/faraixyz),
- [buying Me A Coffee](https://www.buymeacoffee.com/faraixyz),
- [buying Me A Ko-Fi](https://ko-fi.com/faraixyz),
- [sending me a tip on Paypal](https://paypal.me/fgandiya),
- ~~[buy something on Amazon with my affiliate link](https://amazon.com/?tag=faraixyz03-20) (I’ll earn a commision on this as an amazon affiliate)~~,
- or [buy a domain on Namecheap with my affiliate link](https://shareasale.com/r.cfm?b=467188&u=2110247&m=46483&urllink=www%2Enamecheap%2Ecom%2F&afftrack=).