teleren/devto huggingface dataset:
Valid Anagram
Published: 2020-06-29 00:48:56

Here we have a new leetcode problem: 
Given two strings s and t , write a function to determine if t is an anagram of s.

Let's go over the definition of an anagram: a word, phrase, or sentence formed from another by rearranging its letters:
“Angel” is an anagram of “glean.”

So for a word to an anagram of another, they must use the same letters and also the same **amount** of letters. 

One solution is to compare both strings by turning them into arrays, sorting them, and comparing them one by one. However, this is very slow. The worst case scenario is the time complexity being O(n^2). 

Here's my solution: 
```js
const isAnagram = (s, t) => {
    if(!s || !t){
       return null
       }
    if(s.length !== t.length){
       return false 
       }
    
    let obj = {}
  
    for(let i = 0; i < s.length; i++){
        if(obj[s[i]]){
           obj[s[i]]++
           }
        else{
            obj[s[i]] = 1
        }
    }
    
    for(let i = 0; i < t.length; i++){
        if(!obj[t[i]]){
           return false
           }
        if(obj[t[i]] === 0){
           return false
           }
        if(obj[t[i]]){
           obj[t[i]]--
           }
    }
    return true
};
```

Step 1: Take all the letters from the first word and put them into a hash table, the keys being each letter, and the value being how many occurrences of each letter. 

Step 2: Run through the second word and run each letter from the second word to the keys of the hash table with three conditions placed in it. The first case tests to see whether the letter is in the object at all, and if it isn't would disqualify it from being an anagram. The second case checks to see if the value of the letter is greater than 0. If it is, that means there is an extra letter occurrence, which means it is not an anagram. The last condition tests to see if it the letter exists in the hash table. To account for that letter, we lowered the value for that letter in the hashtable. Therefore, the case where there are no more letters in the word we are comparing, and all values in the hashmap are 0 is the case where it is a valid anagram. 

This solution is O(n) + O(m). I've also put a condition before the main comparison starts to check if the lengths are equal.
Launching Angular app on emulator without Android Studio
Tags: tutorial, android, angular
Published: 2020-06-29 00:45:27

---
title: Launching Angular app on emulator without Android Studio
published: true
description: 
tags: #tutorial #android #angular
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/kdusohz7ktlctjpumd7c.jpg
---

Previously we went through [launching Android emulator without installing Android studio](https://dev.to/koscheyscrag/how-to-install-android-emulator-without-installing-android-studio-3lce). In this note we will launch Angular application on that emulator.

First, what we need to do is we have to install build tools by `sdkmanager` in order to be able to build applications : 

```bash
sdkmanager "build-tools;29.0.3"
```

Also we can add `%ANDROID_HOME%\emulator` and `%ANDROID_HOME%\platform-tools` as the entries into `Path` variable to improve the experience. It will allow us to run `emulator` and `adb` commands from any directory in command line. Just use `Start -> Edit the system environment variables -> Environment variables... -> Path -> New` for doing that.

**Prepare a NativeScript project for running** 

If you haven't install `nativescript cli` yet, you can do it by executing the following command:

```bash
npm install -g nativescript
```

Next, create new project from scratch:

```bash
tns create HelloWorld --template tns-template-blank-ng
cd HelloWorld

```

This is just an example of angular application for running. You can use your own app for this. 

**Run the emulator**

Type the following to see a list of available emulators:

```bash
avdmanager list avd
```

We'll see something like:

```
Available Android Virtual Devices:
    Name: test_avd_29
    Path: C:\Users\Andrei_Fedotov\.android\avd\test_avd_29.avd
  Target: Google APIs (Google Inc.)
          Based on: Android 10.0 (Q) Tag/ABI: google_apis/x86_64
  Sdcard: 512 MB
```

Next, let's run the emulator:

```bash
emulator -avd test_avd_29
```

Okay, emulator is working. What we are gonna be doing next is we are just gonna be launching the app on that emulator.

To see a list of available emulators we can use `adb`:

```bash
$ adb devices
```

Output:

```bash
List of devices attached
emulator-5554   device
```

Or we can use `tns` :

```bash
tns device
```

Output:![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/44uj6o2kg2v6xyuznyb1.png)



By using one of above commands we can know a Device Identifier for launching the app on emulator.

Next, let's use the following command to launch the app:

```bash
tns run android --device emulator-5554
```

After building we'll see the app launched

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


**Troubleshooting**

If you're receiving the error `Failed to open /qemu.conf, err: 2`, try to create this file by executing `echo # > c:\qemu.conf` and launch `cmd` as administrator.

**Cheers!**
Apple ARM කියන්නේ මොකක්ද?
Tags: arm, apple
Published: 2020-06-29 00:28:16

කාලෙකට පස්සේ නිදහසේ article ලියන්න වෙලාවක් හම්බුනා. WWDC දි දැකපු මං කාලයක් තිස්සේ දකින්න ආස කරපු , මං හිතන්නේ මට  වැඩිපුරම බලපාන , මට වැදගත් එකම news තමයි Apple Silicon කියලා කියන්නේ.

## මොකක්ද ඉතිං මේ Apple Silicon කියලා කියන්නේ?

Apple Silicon එහෙමත් නැත්නම් මේ වෙනකොට තියෙන A12Z Bionic කියලා කියන්නේ ARM Cortex based processor.

දැං හිතෙනවා නේද *මොකක්ද මේ ARM කියන්නේ* කියලා? හරි ඒක කියන්න කලින් මුලින්ම පොඩි කතාවක් කියන්න තියෙනවා.

Instruction set architecture (ISA) මූලික වශයෙන් ආකාර තුනක් තියෙනවා.

- Reduced Instruction Set Computer (RISC)
- Complex Instruction Set Computer (CISC)
- Scalable Processor Architecture (SPARC)

අද අපි අපේ පරිගණක වල භාවිතයට ගන්න Intel process වල තියෙන x86-64 / x64 architecture කියලා කියන්නේ CISC පාදක කරගත්තු architecture.

හරි ඒ කතාව එතනින් ඉවරයි. දැං අපහු බහිමු silicon කතාවට.

## එතකොට Apple Silicon වල විශේෂත්වය මොකක්ද?

Apple Silicon කියලා එන්නේ අද අපි mobile device වලට වැඩිපුරම පාවිච්චි කරන ජාතියේ process ක්. එහෙමත් නැත්නම් කියන්න පුළුවන් RISC පාදක කරගත්තු AArch64 architecture තියෙන ARM process .

## හරි දැං බලමු ARM කොහොමද Intel වලට වඩා හොද වෙන්නේ කියලා.

ARM , Intel වලින් වෙනස් වෙන්නේ ARM RISC , Intel CISC . ඉතිං ඒ ඒ process ඒ ඒ architectures වලට අදාල ගුණ පෙන්වනවා. RISC වලයි CISC වලයි තියෙන ප්‍රධානම වෙනස තමයි RISC වලට වැඩි commands ප්‍රමාණයක් දෙන්න වෙනවා CISC වලට වඩා වැඩක් කරගන්න ගියාම.

**දැං හිතන්නේ එහෙනම් යකෝ RISC කොහොමද CISC වලට වඩා speed වෙන්නේ කියලා නේද?**

Speed වෙන්නේ CISC වල එක command දුන්නම ඒක සේරම වැඩ ටික කරලා එනකම් අනිත් command ඉනට අත තියාගෙන බලන් ඉන්න ඕනි හැබැයි RISC වල එක command කරන්නේ එක වැඩක් විතරක් නිසා ආයි බලන් ඉන්න දෙයක් නෑ ආපු අනිත් පැත්තට වැඩේ කරන්න පුළුවන් command වලට.

**දැං හිතෙනවා නේද අප්පට හුඩු අපිටත් ARM process වැඩ කරන්න තිබුනා නං කියලා?**

බය වෙන්න එපා ඒක මේ කපේට වෙන දෙයක් නෙමෙයි. මොකද Windows ARM try කරපු හැම සැරේම වැඩේ fail උනා.

ඇත්තම කිව්වොත් Mac OS කියන්නේ *BSD OS නිසා ARM වලට compile කරන්න පුළුවන් උනාට windows එහෙම කරන්න බෑ එයාලා emulator හදලා ඒකේ ඇතුලේ දුවන්න හදන්නේ.

ඔය වැඩෙන් අගතියට පත් වෙන අතින් පාර්ශවය Linux community . Linux ආපු කාලේ ඉදන් ARM වලට support කලාට hardware manufactures ලා hardware හදන්නේ නෑ මොකද windows users ලට ARM පාවිච්චි කරන්න බැරි නිසා.

**ඔයාලා දන්නවද?** *Apple ලගේ " Developer Transition Kit " හැර වෙන හරිහමන් ARM box නෑ කියලා general use වලට තියා development වත්.*

**තාම ඉවර නෑ තව පොඩි සිද්ධියක් තියෙනවා කියන්න.**

Process speed රදා පවතින්නේ transistor size (transistor කියලා කිව්වාට ඒක ඇත්තටම MOSFET) මත ඉතිං process මේ වෙනකොට 7nm සීමාවට ඇවිත් තියෙන්නේ Intel ලට 5nm හදන්න පුළුවන් උනත් කවදාවත් 4nm - 2nm සීමාවට එන්න බෑ මොකද ඒ සීමාවට එනකොට **Quantum tunneling** කියන සංසිද්ධිය ට මුහුණ දෙන්න වෙනවා ඉතිං 3nm transistor කවදාවත් හදන්න පුළුවන් දෙයක් නෙමෙයි. බැරිවෙලාවත් එහෙම හැදුවොත් ඒක Quantum processor වෙනවා. සරලවම කිව්වොත් තව අවුරුදු දෙකකින් විතර පස්සෙ Intel process වල දියුණු කරන්න පුළුවන් උපරිම ලක්ෂ ට එනවා.

*දැං ඉතිං තියෙන්නෙ ඉනට අත තියාගෙන ඊගාවට මොකක්ද වෙන්නේ කියලා බලාගෙන ඉන්න එක*.

ඇත්තම කිව්වොත් ඊගාව MacBook නෙමෙයි Apple ලාගේ පලවෙනි ARM lap.

{% twitter 1275345955106283520 %}

>> Don't forget to say hello to the search box for further details.
Easily Rerun EC2 UserData
Tags: aws, scripting, bash
Published: 2020-07-06 13:38:50

---
title: Easily Rerun EC2 UserData
published: true
date: 2020-06-29 00:00:00 UTC
tags: aws, scripting, bash
canonical_url: https://elliotdenolf.com/posts/easily-rerun-ec2-userdata
---

EC2 UserData code blocks only run when an EC2 starts up for the first time by default. Rerunning this code can be useful for troubleshooting purposes. However, the way to do this is not very straight forward. Let's go through how to view, verify, and execute your EC2's UserData.

First, we must log into our EC2 using SSH and our .pem file.

```bash
> ssh -i "my-cert.pem" ec2-user@my.machine.ip
```

> This article will not go into the details of how to SSH into a machine, you can learn how to do this from the [AWS Documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html).

Next, we must elevate to the root user.

```bash
> sudo -i
```

An EC2's UserData can be accessed at the url: `http://instance-data/latest/user-data`, so we can use curl to redirect this to a file in order to inspect it.

```bash
> curl http://instance-data/latest/user-data > user-data.sh
```

We can then inspect the file using `cat` or `vim`.

```bash
> cat ./user-data.sh
```

We can then modify the permissions and execute it.

```bash
> chmod +x user-data.sh
> ./user-data.sh
```

### Other Variations

We can run the script in one single command if we don't want to inspect it first by piping it directly.

```bash
> curl http://instance-data/latest/user-data | sh
```

Another option is if you'd like to see each line written to STDOUT as it runs, we can enable this by adding `set -ex` to the top of our `user-data.sh` script before executing it.

### Links

- [AWS: Retrieving Instance Metadata](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html)
- [AWS: Accessing Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html)
- [Bash set command](https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html)
Learning Golang (some rough notes) - S01E03 - Maps
Tags: go, learning
Published: 2020-07-01 12:43:18

---
title: Learning Golang (some rough notes) - S01E03 - Maps
published: true
date: 2020-06-29 00:00:00 UTC
series: Learning Go
tags: go, learning
canonical_url: https://rmoff.net/2020/06/29/learning-golang-some-rough-notes-s01e03-maps/
---

👉 [A Tour of Go : Exercise - Maps](https://tour.golang.org/moretypes/23)

> Implement WordCount

This is probably bread-and-butter for any seasoned programmer, but I enjoyed the simple process and satisfaction of breaking the problem down into steps to solve using what the tutorial had just covered. Sketching out the logic in pseudo-code first, I figured that I wanted to do this:

- For each word in the phrase:

  - Check if the word exists in the map already

      - Create it if it doesn’t

  - Add one to the map value

Using `Printf` it was useful to check on how it was executing.

```golang
func WordCount(s string) map[string]int {
	w := make(map[string]int)

	for i, v := range strings.Fields(s) {
		fmt.Printf("Index: %d value %v\n",i, v)
		if _, o := w[v]; o == true {
			fmt.Printf("\tExisting map found for %v with value %d\n",v,w[v])
			w[v] = w[v] + 1
		} else {
			fmt.Printf("\tCreating new map for %v with value 1\n",v)
			w[v] = 1
		}
	}

	return w
}
```

I liked that the tutorial uses tests to check what you’ve done, and shows the expected output:

```
PASS
 f("I am learning Go!") = 
  map[string]int{"Go!":1, "I":1, "am":1, "learning":1}
PASS
 f("The quick brown fox jumped over the lazy dog.") = 
  map[string]int{"The":1, "brown":1, "dog.":1, "fox":1, "jumped":1, "lazy":1, "over":1, "quick":1, "the":1}
PASS
 f("I ate a donut. Then I ate another donut.") = 
  map[string]int{"I":2, "Then":1, "a":1, "another":1, "ate":2, "donut.":2}
PASS
 f("A man a plan a canal panama.") = 
  map[string]int{"A":1, "a":2, "canal":1, "man":1, "panama.":1, "plan":1}
```

Looking at the pseudo-code and what Golang will handle for you automagically it can be reduced to this:

- For each word in the phrase:

  - ~~Check if the word exists in the map already~~

      - ~~Create it if it doesn’t~~

  - Add one to the map value (implicitly create the map entry if it doesn’t already exist)

```golang
func WordCount(s string) map[string]int {
	w := make(map[string]int)

	for _, v := range strings.Fields(s) {
		w[v] = w[v] + 1
	}

	return w
}
```

Note: the underscore character, representing a required variable that you’re not going to use, is pretty useful.
What happened to weekends?
Tags: 100daystooffload
Published: 2020-06-28 21:21:12

It's Sunday evening as I write this, and as another week beckons I find myself reflecting on another weekend that passed by so quickly. I've noticed weekends to be the hardest part of living through this pandemic, and cannot work out why.

I know a lot of people relish the idea of a busy, social weekend, but that's not me. Indeed, I don't feel like my weekends have changed that much at all. But they feel entirely different. For one, they are a time best described as recovery. Waking up on a Saturday morning I usually feel like I'm horrifically hungover, despite not drinking the night before. Can I really have worn myself out so much during the preceding week? It doesn't seem likely but, perhaps when taking exercise into account and a struggle to incorporate proper rest and relaxation into my normal day, maybe I am just exhausted.

The second problematic aspect of the weekend is the apparent potential that I seem to waste. Two whole days to do all those things I had to leave aside during the week –and yet by Sunday evening I don't seem to have achieved much at all.

It might just be how I frame the weekend. Take this one, for example. I wanted to do several things although not many of them were clearly defined:

* Work on my struggling Go learning/side project
* Run/hike
* Work on one of my lockdown jigsaw puzzles
* Chores
* Catch up with the variety of reading that accumulated over the week

I managed to run on Saturday and hike on Sunday. I did a few chores. I did quite a bit of reading. I worked on some Go, got stuck, got frustrated, stopped. I made good progress on the jigsaw, and I also did a fairly decent survey of solar panels for [OpenStreetMap](https://www.openstreetmap.org/). So why do I feel disappointed? I have no idea.

*I'm publishing this as part of 100 Days To Offload. You can join in yourself by visiting [https://100daystooffload.com](https://100daystooffload.com).*
I wrote a simple trivia hosting platform 
Tags: php, vue, sql, codeigniter
Published: 2020-06-28 23:36:50

With covid 19 moving pub trivia to zoom. Hosts had no way of accepting responses.

I saw Google forms. Spreadsheets, texting, even emailing in a picture of your hand written score sheet. 

I created the simplest solution to this and it seems to have taken off. 

Anyone can sign up for free here: triviarat.com 

:)
What learning content do you enjoy most?
Tags: discuss, help, webdev
Published: 2020-06-28 23:29:38

---
title: What learning content do you enjoy most?
published: true
description: A general discussion to better understand which content to create
tags: discuss, help, webdev 
//cover_image: https://direct_url_to_image.jpg
---

It's been a week since I started making some genuine contributions to dev.to! I ended up crunching through 19 articles last week, but will likely start slowing down my before/after work write ups as we are heading into the busy period at work.

The best decide what sort of content to create, I am hoping to reach out and find what is the most useful.

**When it comes to articles on the platform, what types of articles do you prefer (one or more acceptable)?**

1. Short tips and tricks
2. A walkthrough of interesting solutions to projects
3. Longer, fleshed-out articles on a particular topic
4. A series of short-articles on a topic
5. A dive into open-source projects and libraries

Is there another type I haven't mentioned above that you would also enjoy?

**As for how you best consume content, which is your preferred medium?**

1. Articles
2. Videos
3. Podcasts

Everyone at work tells me I could have been an Australian voice actor in another life, so would be happy to start putting my voice to work if others people prefer the videos and/or podcasts!

**Is there an area of interest you would like to learn more about?**

1. Frontend web development
2. Mobile development
3. Building APIs
4. Exploring databases
5. Infrastructure
6. Fun IoT projects around the house

Any other thoughts or suggestions appreciated! Would be very keen to start making content tailored to others.
Automatically backup and upload to S3
Tags: amazon, postgres
Published: 2020-06-28 23:29:20

---
title: Automatically backup and upload to S3
published: true
description: Backup your DB to a file and then upload it to Amazon's S3
tags: amazon, postgres
cover_image: https://images.unsplash.com/photo-1551313158-73d016a829ae?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1322&q=80
---
_Puedes leer este artículo en castellano [aquí](https://amatos.dev/db-backup-s3/)_
## Why?
Because who doesn't need a database backup? ;)

## Background
For my personal project, FacturApp, I use PostgreSQL because it's awesome and also because is free. From time to time I need to restore the prod db to my local instance to have _true_ data and make tests more reliable.

Because I love automation, I decided to have a daily backup _just in case_ and when I need to have the current data, I would just download the file from S3.

## How?
### Steps
The TLDR part would be
1. Find the container's ID
2. Save current time in a variable called _now_
3. Save the db backup using the _now_ variable for the name
4. Upload backup to S3
5. Locally delete files older than 30 days

### The Code
```
#!/bin/bash
docker_id="$(docker ps -aqf 'name=postgres')"
echo "${docker_id}"
now=`date +%Y%m%d%H%M%S`
docker exec ${docker_id} /usr/local/bin/pg_dump -U theuser -Fc thedb > /root/backups/facturapp_${now}.backup
# Upload file to S3
/usr/local/bin/aws s3 cp /root/db_daily/facturapp_${now}.custom s3://db-backup-bucket/facturapp_${now}.custom --sse AES256
# Deleting old files
find /root/db_daily -type f -mtime +30 -exec rm {} \;
```

### Automate it!
The final step would be to create a cron job by running `crontab -e` and adding something like 
`0 0 * * * /root/dailybackup >> /root/logs/backup.log`
to have to script running each day at midnight.

And that's how I save a backup to an S3 bucket every day at midnight :)

_The `/root/logs/backup.log` part is just in case you want to save the log for each time the script runs._
Javascript Fundamentals Series: Blocks
Tags: javascript, tutorial, beginners
Published: 2020-06-28 22:28:23

---
title: Javascript Fundamentals Series: Blocks
published: true
description: Javascript Fundamentals Series, tutorial about blocks in javascript. 
tags: javascript, tutorial, beginners
series: javascriptFundamentals
---

In this series, I'm going to explain the fundamentals of javascript. 

In this post, we are going to learn more about Blocks.

## Blocks

Let's read the definition by [Mozilla - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block)

> A block statement (or compound statement in other languages) is used to group zero or more statements. The block is delimited by a pair of braces ("curly brackets") and may optionally be labelled

In other words, a `block` is everything between `{}`

```javascript
{ // block started
   var foo = "bar";
} // block ended

console.log(foo); // logs "bar"
```

It is important to mention that the block doesn't create a scope, so in our small example, `foo` variable is still accessible from outside the block, that is why we could log the variable with `console.log(foo);`. We'll see later in this post more about the scope.

This example is also valid:

```javascript
function demo() {
   // first block
   { 
      var foo = "bar";
   }

   // second block
   {
      console.log(foo);
   }
}
```

Now, whenever we invoke `demo()`, we'll see that "bar" is logged in the console. Give it a try :muscle:! 

It is worth mentioning, that we hardly ever gonna see this kind of snippet in a real-world app, please don't write functions with multiple blocks like I just did. *This was only for demonstration purposes.*

So, if blocks are not used as in the example above, why we need them? Well, the blocks are also the way we have to declare several statements "attached" to a conditional, loop, etc. 

```javascript
if (condition) {
  // this is a block
}

while (condition) {
  // this is a block
}
```

That’s it! If you have any doubt don’t hesitate to leave your comments or ask me ​​via [Twitter](https://twitter.com/jpblancodb).

In the next post of this series, we're going to learn about functions :sunglasses:. Stay tuned!
Hexo Quickstart project released
Tags: hexo, static, githubpages, template
Published: 2020-06-28 21:45:35

---
title: Hexo Quickstart project released
published: true
description: A template project including a simple GH Pages deploy flow
tags: hexo,static,githubpages,template
cover_image: https://github.com/MichaelCurrin/hexo-quickstart/raw/master/sample.png
---

Heard of [Hexo](https://hexo.io) before? It is a JS-based static site generator focused on supporting your blog.

Today is the first time I set up a site. I am familiar with Node.js and Jekyll, so I set myself a challenge to learn a new static site generator tool, or at least enough to get by.

Here it is:

- https://github.com/MichaelCurrin/hexo-quickstart

It includes instructions in the docs, a live demo on Github Pages and you can use the project as template to make your own.

Actually, the main reason I wanted to learn to use Hexo was to use this impressive futuristic theme that has a space age or video game feel:

- https://github.com/klugjo/hexo-theme-alpha-dust

![sample image](https://camo.githubusercontent.com/8003b755db1ccbdba1ba84c7943813ab81ddbb12/687474703a2f2f7777772e636f6465626c6f63712e636f6d2f696d672f6865786f2d7468656d652d7468756d626e61696c2f416c706861447573742e6a7067)

Once I had a base project setup, it was easy to add the theme as a **submodule** in the `themes` directory and then configure the `theme` value in my `_config.yml`. Though I ended up sticking to the default `landscape` theme for my quickstart though to keep it vanilla.

Is anyone else using Hexo? Any reasons to use it for blogging? Or to ditch it and focus on Jekyll or Hugo... or Gatsby or VuePress... there are so many to choose from.