teleren/devto huggingface dataset:
MJSQ 101: IIFE, anonymous functions, native vs host objects
Published: 2020-02-05 06:55:32

## More JavaScript Questions 101(MJSQ 101): 

Continuing from my original [blog post]("https://dev.to/danvyle/more-javascript-fundamentals-101-4d5d"), more javascript 101 questions!:

## Explain why the following doesn't work as an IIFE: `function foo(){ }();`. What needs to be changed to properly make it an IIFE?

First you'll need to understand what an IIFE is. An **IIFE** (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.

```javascript  
(function () {
    var whoWonSuperBowl = "Kansas City Chiefs";
    return whoWonSuperBowl;
})();

//output: "Kansas City Chiefs"

```
`function foo() {} ();` is reading the two as separate: `function foo(){}` as a function declaration and then `()` as a function call. Since they are not grouped, the function throws an error: `Uncaught SyntaxError: Unexpected token`. 

To fix this, we can call on the grouping operator `( )` to group the function declaration and immediately invoke the function `(function foo(){ })()` or group the entire function together with `(function foo(){ }())` to create function expressions that can be immediately invoked.

## What's a typical use case for anonymous functions?

IIFE which was mentioned above:

```javascript
    (function() {
        //expression
    })();
```
As a callback where naming the function isn't necessary and it won't need to be used anywhere else(Yangshun's example):

```js
setTimeout(function() {
  console.log('Hello world!');
}, 1000);
```

## What's the difference between host objects and native objects?

**Native objects** are objects that are unique to the JavaScript language. Some examples include: String, Number, Array, Image, Date, Math, etc.

**Host objects** are objects that are supplied to JavaScript by the browser environment. Examples of these are window, document, forms, etc.

That's all for today, please leave any comments/questions/corrections in the comments. Thanks!


###### Sources:
Huge huge thanks to github user: yangshun for aggregating the most popular JS, CSS and HTML questions and giving us his answers to it. My weekly blog posts are to go over several questions at a time to reinforce my knowledge of fundamental javascript as I grow my expertise in it. Many of my blog will be paraphrasing if not direct quote from his github. Find his tech interview handbook [here]("https://github.com/yangshun/front-end-interview-handbook/blob/master/questions/javascript-questions.md#whats-the-difference-between-call-and-apply") and please support him!

And an additional thank you to Flatiron alum: Marissa O. who is a badass developer at Forbes magazine for directing me to his blog!

Other sources:

* https://developer.mozilla.org/en-US/docs/Glossary/IIFE
* http://lucybain.com/blog/2014/immediately-invoked-function-expression/
* https://www.quora.com/What-is-a-typical-usecase-for-anonymous-functions
* https://www.sitepoint.com/oriented-programming-1-4/
Hobby Project: Filter for Newest Articles
Tags: ranges
Published: 2020-02-05 06:52:32

If you read my previous post which focused on test data for this functionality, you may find the effort disproportionate. 

https://gitlab.com/jessephillips/devarticlator/-/compare/v0.0.6...v0.0.7

```diff
auto isNewerArticle(ArticleMe am, PullState ps) {
-    return null;
+    return am.id > ps.lastArticle;
```

That is the implementation. Given an article and the previous pull data, the newer articles are the ones with the greater ID number. 

This assumes articles are given newest first and that article IDs are given increasingly. However if the first isn't true I won't have reason to attempt short circuit.

------

```dlang
alias inPreviousPull = (x) => !x.isNewerArticle(lastPullState);

devreqArticleRange.until!inPreviousPull
  .structureArticles
  .saveArticles(savePath);
```

You won't find the above code in the changes, I've taken the unittest and pulled out the complete concept to save new articles.

If I abstract the dev api into a range, I'll be using a normal range sequence and combined with the components I've already tested.

What is miss here is storing and retrieval of this lastPullState.

------

I wrote the test first. I almost didn't because the implications was so simple, but it is good to see the test fail.
Why health is important for developers!
Tags: health, developers, fitness, dailyhabits
Published: 2020-02-05 06:25:00

Physical activity on a daily basis keeps you fit and healthy. There's a feel-good factor that comes with exercise and following the daily routine of going to the GYM.

I used to be a guy who used to sit on a chair for a longer duration of time, with no physical activity. Believe me, you will feel good for some time but afterward, when you gain a hefty amount of weight due to **no-physical-activity**, you screw up your health.

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


So last year, I decided to change my daily habits, I used to weight around 230 lbs, and it was not easy I must admit that. When you have a habit of bing eating, you tend to have a lot of craving for food, and an "Emotional bing eater" with no control over the eating habits. 

I started walking for around 10000 steps on a daily basis with control over my eating habits. I gradually reduced table sugar intake and switched to healthy foods like green veggies and fruits and after hard work and perseverance, my weight came down to 202 lbs in three months.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/26xxhrfzfoe9inz7h9yq.jpg)

Occasionally I used to opt for a cheat meal which is fine, but I made sure that I note down my daily calorie intake. I used the [Healthifyme App](https://www.healthifyme.com/) which was of great help and still using.

**A good health should be a lifestyle, not a goal because health is wealth !!**

*Happy learning and stay healthy !!*
Is React Native worth using for Mobile Development?
Tags: youtube, discuss, reactnative, career
Published: 2020-02-05 05:44:14

This video will be more a discussion in response to a recent video made by the TechLead. I wouldn't normally do this sort of video but I felt I had to say something. I quite like React Native and the community. 

I hope you can leave some comments below about what you think in regards to App Development.

React Native is a mobile application development framework that allows you to create cross-platform apps for both iOS and Android. Recently there has been discussion about its future and if it should continue being used.

I've done this video to talk more about React Native in general development for small to medium businesses. About day to day use for people in startups and for those even trying to learn something new.

Some of the benefits include:
* Easy of use for those coming from the web and use tags and javascript
* Easier to get started if you know react, without having to relearn fundamentals
* Less cost for development for Small to Medium Businesses
* Code can be shared between the web and for mobile, especially for functions such as stores
* One single team, one lot of documentations
* Great community that is constantly trying to improve
* More jobs available for those working in React Native

Hopefully, it clarifies why I believe its a good platform.

{% youtube na9MoW1E6nQ%}

TechLeads Video: Why React Native is garbage.
https://www.youtube.com/watch?v=NxJCSI7a8wk
Application Programming Interfaces
Published: 2020-02-05 05:36:38

An application programming interface (API) is an interface or communication protocol between different parts of a computer program intended to simplify the implementation and maintenance of software.

An API may be for a web-based system, operating system, database system, computer hardware, or software library.

An API specification can take many forms, but often includes specifications for routines, data structures, object classes, variables, or remote calls. POSIX, Windows API and ASPI are examples of different forms of APIs. Documentation for the API usually is provided to facilitate usage and implementation.

More recently, the term has been often used to refer to a specific kind of interface between a client and a server, which has been described as a “contract” between both - such that if the client makes a request in a specific format, it will always get a response in a specific format or initiate a defined action.[1] This is a specialized form of API, sometimes defined as a Web API.
HOPL is coming out of hibernation
Tags: languagelearning, hopl, languagehistory
Published: 2020-02-05 04:20:01

[HOPL](http://hopl.info) (History of Programming Languages) is mostly up again. 

We had to move from one database (Access) to another (SQLServer). There are a variety of SQL language defects that need to be discovered and fixed. 

Please visit the site and break it (there's a metric buckette-load of breakables.) Breakages are usually marked by the words "Internal error". Please send the full text of the error along with the URL string from the browser address bar.

Send your bug reports directly to us at hopl.acquisitions@gmail.com . Please put "[HOPL] Bug report" in the subject line. Contributor username's along with a count of submissions will be acknowledged on our Facebook presence, [HistoryOfProgrammingLanguages](https://www.facebook.com/HistoryOfProgrammingLanguages/).

If you're a language developer, please consider making an acquisition submission to [HOPL](https://docs.google.com/forms/d/e/1FAIpQLSdK18ejypu0-3VpIbFjSuOlz9Aw4dCuD0JPQsN_vpnx6uYCoA/viewform) (link takes you to our acquisition form). We've made the editorial decision not to include [esolangs](https://esolangs.org/wiki/Main_Page), preferring instead to focus on languages of wider applicability, both implemented and research (e.g. [ISWIM](https://en.wikipedia.org/wiki/ISWIM).)
Parsing saml namespace prefixes
Tags: node, xml, saml
Published: 2020-02-05 04:19:50

Introduction

This is about authentication / authorisation while building your web apps. 

I included single-sign-on feature in my web application. Then, after integrating my app with SSO, I performed login operation and saw this saml response after authentication.

<sh:root>
  <sh:book> </sh:book>
  <sh:genre> </sh:genre>
  <sh:id> </sh:id>
  <sh:book> </sh:book>
  <sh:genre> </sh:genre>
  <sh:id> </sh:id>
  <sh:book> </sh:book>
  <sh:genre> </sh:genre>
  <sh:id> </sh:id>
</sh:root>

####Apologies.. I don't know how to include html tags in this post :P

How do I handle this? I need a JSON/ object to fetch the concerned values.

I followed these steps to convert it to a json object:
1) Decoded the saml response to xml.
2) Then, parsed xml to object/ JSON to fetch required fields.

For decoding the saml response, I used "saml-encoder-decoder-js" npm package and for parsing xml to object I went for "xml2js".

Usage:
```javascript
let decoder = require('saml-encoder-decoder-js'),
  parseString = require("xml2js").parseString,
  stripPrefix = require("xml2js").processors.stripPrefix;

app.post('/login/callback', function(req, res) {
 
    const xmlResponse = req.body.SAMLResponse;
    decoder.decodeSamlPost(xmlResponse, (err,xmlResponse) => {
      if(err) {
        throw new Error(err);
      } else {
        parseString(xmlResponse, { tagNameProcessors: [stripPrefix] }, 
                    function(err, result) {
          if (err) {
            throw err;
          } else {
            console.log(result); //End result
          }
        });
      }
    })
    res.redirect('http://localhost:3000');
  }
);
```

Note: stripPrefix to get rid of namespace prefix.
to fetch "root" from "sh:root".

##### So, the end result gave me the json I was looking for.

Hope, you find this article worthy enough to have a glance.

Cheers !!!
Groovy2系(Gradle)はコメント中の\uもUnicodeエスケープされる
Tags: groovy, gradle, android, unity3d
Published: 2020-02-05 04:05:00

---
title: Groovy2系(Gradle)はコメント中の\\uもUnicodeエスケープされる
published: true
description: 
tags: Groovy, gradle, Android, Unity
date: 20200205T04:05Z
---

Groovy2系の文字列リテラルは`\u0000`のように`\u`に続けて4桁の数字でUnicodeエスケープされます。
このUnicodeエスケープは文字列リテラルだけではなく困った事にコメントにも適用されます。なので例えば以下のようなコメントを書くとエラーになります。

```groovy
// C:\upload
```

この動作は以下のバグレポートによるとバージョン2系のパーサーはunicode readerでソースコードを読み込むので発生するとコメントされていました。つまり文字列やコメントだけではなくコードすべてに対してUnicodeエスケープしているという事です。

- [Certain string(s) in comments cause General error during parsing: Did not find four digit hex character code.](https://issues.apache.org/jira/browse/GROOVY-8395)

バージョン3系ではパーサーが新しくなりコメントに`\u`を含めることができます。またドキュメントから見つけられなかったのですがスラッシュ文字列とドルスラッシュ文字列も`\u`はUnicodeエスケープされなくなりました。

- [Release notes for Groovy 3.0](http://groovy-lang.org/releasenotes/groovy-3.0.html)

とは言え、まだリリースされていないので今はどうにかしてコード中から`\u`を取り除く必要があります。

そもそもの発端はUnityでAndroid用にカスタム build.gradle テンプレートを利用して`DIR_UNITYPROJECT`をプロジェクトフォルダの絶対パスに置換する機能を使った時に`u`で始まるフォルダがあった事が原因でWindowsでエラーが起きた事でした。
Unity2019.1以降なら`DIR_UNITYPROJECT`を置換する時にパス区切り文字をエスケープして`\\`で出力するのでこの変数で問題は起きないようです。

- [Android の Gradle](https://docs.unity3d.com/ja/current/Manual/android-gradle-overview.html)
- [[ANDROID][WINDOWS] TEMPLATE VARIABLE DIR_UNITYPROJECT ON WINDOWS DOES NOT ESCAPE '/' CHARACTERS](https://issuetracker.unity3d.com/issues/android-windows-template-variable-dir-unityproject-on-windows-does-not-escape-slash-characters)
Why I'm moving AlOficial.com from Laravel to Nuxtjs and still been React Lover.
Tags: laravel, react, vue, nextjs
Published: 2020-02-05 03:54:14

After two years of developing with React, Nextjs, Gatsby ... I still work with Laravel for some projects where ShareHosting is the optimal solution for small things. One of this project is AlOficial.com, a web for Venezuela to check the value of the dollar against the local currency, after a few days I decided to do a mayor upgraded, using node.js and also React Native app to monetize. 

This was my developer quest:

## Why node.JS

Let's be honest, JS is like sex, once you use it, you never want to use other things. It is so flexible that PHP becomes a little bit frustrating. Don't get me wrong, Laravel is a great tool, it to develop everything you want using all the resources that shared hosting can give you. But still, Javascript wins.

That why I deploy my project in a shared hosting that allows node.Js apps. I began to my deployment with Laravel, and it worked well but the web has still some needed of magic javascript touch.

## First Try, Laravel + React

React is my prefered tool to work, and now Laravel allows to make your front end using React, but there is always a catch. React on Laravel is not the same as you work with "create-react-app", you can, however, create your project on React then use Laravel API to communicate with your app and voila... everything things ok...

But No, AlOficial requires something very important to be monetized, and that is SEO (search engine optimization) so we come back to the begging, I needed something whit SSR (server-side rendering).

## NextJs and GatsbyJs

I have read how powerfull was NextJs, and I was very interested to use in full server project. NextJS makes your code easier and cleaner. Then I saw Gatsby whit a wonderful collection of templates that I even use for my website. I was just ready to do my evil plan when... my hosting server had a small rule... Only work with NodeJS 8 and 9... and NextJS and GatsbyJs require 10. My evil plan was gone.

## The Rise of Vue... or Nuxt...

In my mind, I was only thinking about how to solve two problems: 1) I need a Native app to monetize AlOficial and 2) I need to remake your web... Then I think about other possibilities... I learned about Vue when I was Freelance and maybe I can solve with Nuxt (NextJs version of React). So then I began with AlOficial transformation, hoping to end it well.
Tip to get collection data in run time using spatie/media-library in Laravel
Published: 2020-02-05 03:05:05

Sample i want to check if its `singleFile`

In Model

```php

    public function registerMediaCollections()
    {
        $this->addMediaCollection('homepage')
            ->registerMediaConversions(
                function (Media $media) {
                  // ...
                }
            );

        $this->addMediaCollection('page-large')
            ->singleFile() // < ----- this need to check
            ->registerMediaConversions(
                function (Media $media) {
                  // ...
                }
            );
    }
```
In blade:

```php
<?php /** @var \App\Models\CMS\Slider\Slider $model */ ?>

@php $model->registerMediaCollections() @endphp

@if(
    collect($model->mediaCollections)
    ->where('name', $model->collection_name)
    ->first()->singleFile
)
    <input-field name="image" type="image" checked/>
@else
    <input-field name="images" type="images" checked/>
@endif

```
Marketing
Published: 2020-02-05 02:49:51

https://codepen.io/aksaaron/full/QWwYgxd
https://codepen.io/aksaaron/full/MWYLvYG
https://codepen.io/aksaaron/full/abzXweP
http://aksaaron1.e-monsite.com/pages/merek.html
http://aksaaron1.e-monsite.com/pages/brand.html
http://aksaaron1.e-monsite.com/pages/nama.html
https://www.producthunt.com/posts/bisnis
https://www.producthunt.com/posts/branding
https://css-tricks.com/forums/users/delisalisa342/
A dime worth of ideas.
Published: 2020-02-05 02:49:03

---
title: A dime worth of ideas.
published: true
description: They say an idea is worth a dime a dozen. Here's twelve then.
tags: 
---

They say an idea is worth a dime a dozen. Here's twelve then.

1. Conveyor belt tapas. Don't limit your thinking to sushi.
2. Distributed ledger for caucuses.
3. Restaurant finder app that minimizes total travel time for distributed groups. Solve "We should all go here.", "It's too far"
4. Siesta Wednesdays
5. Puppy Therapy as a Service
6. Site to allow simplified graph generation. Make it easier to visualize what dependencies look like.
7. Gamify restaurant loyalty. Complete quests to eat all salads. Unlock and upgrade bonus sauces. Buy loot crates to enable rare side dishes. Complete streaks to unlock extra savings. Compete with other eaters for prizes.
8. Pop Up Video for State of the Union Address.
9. Taking it a little easier on all the Cascade Hops there brew masters. Come on.
10. Savory shave ice?
11. Kitchen spoons in colors of cooking, good roux, golden brown of bread, translucent onions, cooked green beans, cooked shrimp. #brown
12. Just be a little nicer, give people the benefit of the doubt.
13. BONUS: GymBus™ - Don't just sit there, work out on your way to work! (liability concerns in progress)

Follow me for more "ideas".
Dealing with Deprecation & iOS Headers
Tags: ios, swift, github, oauth
Published: 2020-02-05 02:38:21

---
title: Dealing with Deprecation & iOS Headers
published: true
description: Updating my iOS app to get off deprecated GitHub API's
tags: ios, swift, github, oauth
cover_image: https://images.unsplash.com/photo-1506464617922-278b3a865309?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3750&q=80
---
Recently, I started getting emails from GitHub letting me know that my GitHub OAuth app was accessing GitHub API's using a deprecated authentication method.

{% twitter 1224527769046077440 %}

My app, [OctoNote](https://apps.apple.com/us/app/octonote/id1433164731), uses the GitHub gists API to store and manage notes as GitHub gists. I had originally [set up OAuth](https://ajkueterman.dev/posts/ios13-authentication-services-changes/) for OctoNote using an `access_token` as a URL query parameter, which is [no longer supported](https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters).

Instead, we need to add the token as an [`Authorization` header](https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters) on the request. Doing so in iOS is easy, just specify the value of the token and the name of the Header field (in this case `Authorization`) on your API call requests.

```swift
request.setValue("token \(token_val)", forHTTPHeaderField: "Authorization")
```

After doing this, your regular calls to the GitHub API's should still work as expected, but you should no longer get deprecation notices from GitHub! :tada:
JavaScript Challenge #4
Tags: javascript, java, challenge, c
Published: 2020-02-05 02:25:57

let m x n array is given below

[  1  2  3  4
          5  6  7  8
          9 10 11 12
         13 14 15 16
         17 18 19 20 ];

***Expected Output: If you give array [i,j] => i.e 10, it will print the square of numbers for example***

         5  6  7
         9  10 11
        13  14 15


***Understand the problem and solve it. make your solution on comments..***
Lesson 14 Discussion
Published: 2020-02-05 02:22:29

1. Why do you think arrays in Swift only support a ​collection of objects of the same type?
- If you create an array, and assign it to a variable, the collection that is created will be mutable. If you assign an array,  its size and contents cannot be changed.

How can you access objects within an array one at a time?
- going over arrays one element at a time is something that is a very common exercise , and to do that you’d run a counter over the length of the array and pick out each element one at a time.


How might you check if an array is empty?
- to check if an array is empty, use Swift function "isEmpty" on the array. To check if an array is empty. The function returns a bool value. If the array is empty, "isEmpty" returns true, else false.
How to Hire a Freelancer
Tags: career, productivity
Published: 2020-02-05 02:14:58

Hiring is always hard. There're lots of risks involved. The person may not know enough to deliver. He or she may have a bad attitude and more.

In this article, we'll look at the steps to hire the person online.

# Prerequisites

You have to determine the work you want to get done and the price that you're willing to pay.

Finding the right person for the right price is easy with sites like Tychoo or Fiverr since they're listed right on the freelancer's profile.

Also, you got to see what they can do before signing up for these sites and reaching out.

Milestones and deliverables must be clear so whomever you hired will do what you want them to do.

The length of the contract also needs to be determined so that you won't have to pay for extra freelancing time that you don't want to pay for.


# Step 1 - Sign Up

Sign up for a freelancing like Tychoo or Fiverr to find the freelancers that you're looking for. Browse for the person with the skills you want, and then reach out.

# Step 2 - Reach Out to the Person You Want Directly.

Reach out to the person that you want to hire and interview them. You can do that with chat and video conferencing.

# Step 3 - Interview

Book an interview and chat with them. Also, give them some tests.

Listen to what they say, check their test answers, and see if they're a fit for you.

# Step 4 - Assess Their Knowledge and Personality

Think hard comparing what you want and what they can give according to your communication between you and them.

# Step 5 - Hire the Right Person

You don't have to hire right away. There're lots of freelancers on Tychoo and Fiverr. You can also turn people until you find the right person for the job.

Even after you hired someone, if he or she isn't a good fit, you can find someone else on Tychoo or Fiverr.