teleren/devto huggingface dataset:
What is Function Expression in Javascript
Tags: javascript, webdev, computerscience, functional
Published: 2020-02-07 08:54:15

To understand Function Expression lets explore functions in Javascript first. 

## Functions

In general, Functions are **subprograms** which may, or may not take parameters(input) and return a value. 

----

![Function](https://firebasestorage.googleapis.com/v0/b/hackinbits.appspot.com/o/function_expression_pic1.png?alt=media&token=b368170c-a628-42ec-894b-cf266c836d75)

----

## Functions in Javascript

A javascript function does the same thing. It takes parameters as input and returns a value. 

```javascript
function addTwoNumbers(a, b) {
	return a+b;
}
```

Javascript function definition starts with the function keyword, followed by:

- name of the function
- parameters if any, wrapped with parenthesis and separated by a comma
- the function body - series of statements inside curly brackets { }.

```javascript
function greetings(name) {
	alert('Hi' + name);
}
```

If you have experience in other programming languages, the above function definitions will look very familiar to you.

## Function Expression

**Functions are first-class objects** in Javascript. For that reason, they can be assigned to a variable as an expression, passed as a parameter, and much more.

A function expression is defined by assigning a function definition to a javascript variable.

```javascript
var addTwoNumbers = function (a,b) {
	return a + b;
}
addTwoNumbers(2, 3);
```

### Anonymous Function Expression

In the previous example, the function assigned to variable "addTwoNumbers" has no name. Therefore, it is called an anonymous function. 

```javascript
var multiplyTwoNumbers = function (a,b) {
	return a * b;
}
multiplyTwoNumbers(2, 3);
```

 Anonymous Function Expressions are used to create callback functions. We will save **callback** for another time.

### Named Function Expression

To create a named function expression, assign a function with a name to a variable.  In this case, the scope of the function name is the function itself. 

```javascript
var newSeries = function fibonacci(num) {
  if (num <= 1) return 1;

  return fibonacci(num - 1) + fibonacci(num - 2);
}
```

Named Function Expressions are useful for creating recursive functions. 


Function Expression is quite useful in the real world. It is also used to create a coding pattern called IIFE(Immediately Invoked Function Expression). We will discuss the IIFE in the next article.

**Originally Published on [hackinbits.com](https://hackinbits.com).**
If you like this article, please upvote and share it.
How to add Emoji's in your website, using HTML, CSS or JavaScript
Tags: emoji, webdev, html, tutorial
Published: 2020-02-07 08:46:10

Emoji's first appeared in 1997 on Japanese mobile phones. They are the descendants of the Emoticons; which are those basic text-based imitation of emotions ;-)  – _Yes, this is an actual example_.

Emoji's grew in popularity years after years by being included in more and more computer, mobile devices, applications, games etc. They are so popular nowadays that they account for a part of the popular culture.

We are using those communication helpers, especially in the younger generations. But how do they work? To stay light, let's say that Emoji's are characters; very much like letters, punctuation marks or symbols.

> ### 👽 📞 🏠
> Can you find this movie?

How did I integrate those Emoji's into my article? How could I do it anywhere on the web?

We will see different techniques available in HTML, CSS and JavaScript. They rely on two methods; copy-pasting and codepoint. 
First [find your Emoji](https://emojipedia.org/), then follow the steps in the language you want.


## HTML
The most straightforward way. You can paste the previously chosen Emoji.

```html
<p>🔥</p>
```


Your other option is to use the codepoint of the Emoji and replacing `U+` with `&#x`.

```html
<p>&#x1F525</p>
```


## CSS
In CSS you need to use the `::before` or `::after` pseudo-element coupled with the content property where you paste the Emoji as the value.


```css
/* You need an HTML element with the class 'element' */
.element::before {
  content: "🔥";
}
```


The same way, you can use codepoint replacing `U+` with `\0`.


```css
/* You need an HTML element with the class 'element' */
.element::before {
  content: "\01F525";
}
```


## JavaScript
In JavaScript you need to specify the `innerHTML` by pasting the Emoji.

```javascript
/* You need an HTML element with the class 'element' */
document.querySelector(".element").innerHTML = "🔥";
```


Similarly, you can use the String method `fromCodePoint` mixed with the codepoint value where you replace `U+` with `0x`.

```javascript
/* You need an HTML element with the class 'element' */
document.querySelector(".element").innerHTML = String.fromCodePoint(0x1F525);
```


## Live example on Codepen
Isn't an example worth a million words? 😄
{% codepen https://codepen.io/beumsk/pen/RwNQdJz %}

All major Browsers support the Emoji's so there is no excuse.
Try it yourself and use Emoji's all over the web! 

Keep playing to learn! 🔥

If you find value in what I offer don't hesitate and [buy me a coffee](https://www.buymeacoffee.com/beumsk) 😇

_The movie described with Emoji's is E.T._

Note: There are plenty of options to have Emoji's integrated that I am not covering in this article. Icon fonts or SVG's are examples, it's up to you to decide what you will use.
Using CSS box-shadow(s) to create 3D Depth, Transitions and Neomorphism
Tags: webdev, css, html, beginners
Published: 2020-02-07 08:27:17

This video will share some ways to use CSS box-shadows to add more depth to elements on the page, and animate hover transitions and more.

{% youtube RdXfKCwE2Uc%}

This includes things like:

* Introduction to Box Shadows in CSS
* Using Box Shadows to add depth
* Transition the shadow on hover both towards and away from the screen
* Neomorphism and how it works

*My favourite type of box shadow:*

<pre>
box-shadow:0px 15px 10px rgba(0,0,0,0.15);
</pre>

This video will expand on what we learn about transitions in the previous post. If you want to read that, I will provide it in the links below.

## Want to see more:
I will try to post new great content every day. Here are the latest items:
* [4 Simple CSS Hover Transitions for your Elements Background](https://dev.to/adriantwarog/4-simple-css-hover-transitions-for-your-elements-background-4mlg)
* [How to implement Dark Mode with CSS new media call: prefers-color-scheme](https://dev.to/adriantwarog/how-to-implement-dark-mode-with-css-new-media-call-prefers-color-scheme-3h65)
* [Why you should Whiteboard your Design & Development, UI & UX](https://dev.to/adriantwarog/why-you-should-whiteboard-your-design-development-ui-ux-5g12)
* [Creating a Mobile Design and Developing it](https://dev.to/adriantwarog/creating-a-mobile-design-and-developing-it-5c4o)

PS. Does anyone know how to add colors to 'pre' code on dev.to?
The "I *dislike* recursion" notes
Tags: computerscience, codenewbie
Published: 2020-02-07 08:17:58

Writing these notes while I cringe and procrastinate. Yes, recursion is useful, so is my pet cat. Covers the general concept of recursion.

### Definition 

A recursive function, is a function that **calls itself** till a certain condition is met. A break criteria is necessary so that the function does not call itself infinitely.

So you can express operations in terms of itself.

A simple example is:


```
#include <iostream>
 
using namespace std;
 
void recurse (int count) // Each call gets its own count
{
  cout<< count <<"\n";
 
  recurse ( count + 1 );
}
 
int main()
{
  recurse ( 1 ); //First function call, so it starts at one        
}


```

### 2 parts of a recursive function 

1. Base case (the condition that stops the recursion process)
2. Recalling condition (the condition that causes the function to call itself)

### Example

The classic example is calculating the factorial of a number.

```
#include <iostream>
using namespace std;
//Factorial function
int f(int n){
   /* This is called the base condition, it is
    * very important to specify the base condition
    * in recursion, otherwise your program will throw
    * stack overflow error.
    */
   if (n <= 1)
        return 1;
   else
       return n*f(n-1);
}
int main(){
   int num;
   cout<<"Enter a number: ";
   cin>>num;
   cout<<"Factorial of entered number: "<<f(num);
   return 0;
}


```
Derek Banas: Design Patterns Video Tutorial
Tags: patterns, architecture, oop
Published: 2020-02-07 07:45:02

The set of the lecture describes different software design patterns. Software design patterns are standard solutions to frequent problems in software design. They are used as a reference for the design of new systems and communication among software developers.

The course requires an understanding of UML diagrams. A significant disadvantage of the collection is too concreted examples and lack of explanations on plain English.

# For beginners: 
It allows developers to leverage an experience gained by software developer’s community. The knowledge emphasises extra attention to the design of software components.

# For experienced:
Each lecture of the series can act as an independent studying unit. Therefore it can be used to refresh rarely used patterns for an interview or utilisation on a tricky occasion.


The videos are available on [YouTube](https://www.youtube.com/playlist?list=PLF206E906175C7E07)
Rust in web applications
Tags: discuss, rust
Published: 2020-02-07 07:29:28

---
title: Rust in web applications
published: true
tags: discuss, rust
---

Hello everyone,

I have been thinking about using rust in web development for the past 2 months but in light of the recent events surrounding actix, I am wondering if is it worth it to commit a whole project to a single library.

Since the standard library is focus on low level programming and all the library available on cargo seems to rely on a huge amount of other external library. How do you assess the potential threat to the security or longevity of your project ?

For me, node modules or python libraries were already a pain to check against security and company policies. But in my perspective the problem is even worse for rust.

I’m a huge fan of the language, and follow very changes, but I keep coming back to go when it comes to write a simple service, without over head.
Tips of Command Line
Tags: cli, bash, zsh
Published: 2020-02-07 07:21:21

---
title: Tips of Command Line
published: true
description: Tips of Command Line
tags: CLI,Bash,Zsh
---
# 1. !!
Got permission error. like this
```
chmod +x /usr/local/bin/ecs-cli
chmod: Unable to change file mode on /usr/local/bin/ecs-cli: Operation not permitted

```

Solution is just add sudo.
```
sudo chmod +x /usr/local/bin/ecs-cli

```
And you don't have to type `chmod +x /usr/local/bin/ecs-cli` again.  
Type `!!` . Like this

```
sudo !!
```

!! means one before command executed.

2. To be continued ..
Repeated Substring Pattern
Tags: javascript, java, c, challenge
Published: 2020-02-07 06:50:28

Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.

***Example 1:***

Input: "baba"
Output: True
Explanation: It's the substring "ba" twice.

***Example 2:***

Input: "xyx"
Output: False

***Example 3:***

Input: "xyzxyzxyzxyz"
Output: True
Explanation: It's the substring "xyz" four times.
My Solution:

***JavaScript:***

var repeatedSubstringPattern = function(s) {
     return s.repeat(2).slice(1,-1).includes(s);
 }; 

***Java:***

class Solution {
     public boolean repeatedSubstringPattern(String s) {
         for(int i=s.length()/2;i>=1;i--){
             if(s.length()%i == 0){
                 int j = i;
                 String sb = s.substring(0,j);
                 while(s.indexOf(sb,j) == j) j= j+i;
                 if(j==s.length()) return true;
             }
         }
         return false;
 }
 }

Happy Coding! 😇   please share your approach on comments...
Is Web Development Windows 3.1?
Tags: discuss, webdev
Published: 2020-02-07 06:28:57

In the early days of Windows there was a very particular way to code your graphical interface. This was because all of Windows was single threaded. Your application could utilize all the processing time and thus prevent other windows to be unintractable.

The win16 api expected you to call into a special management function to release control so other window processing could take place. The win16 api had some tricks up its sleeve, as it would call this manager method for you when asking it to do something. This way there was less likely to be a rogue app.

Now days you're Windows app will need to us threading in order for your application to allow for it not to "hang". But the rest of the system carries on. 

My question then, is Web development like this old Win api? Are we using async, promises everywhere to keep our entire web page functioning rather than our component?
Local HTTP Server
Tags: todayilearned
Published: 2020-02-07 06:10:58

---
title: Local HTTP Server
published: true
description: 
tags: TIL
---

```
npx http-server -a localhost
```

[Simple One-Line Local HTTP Servers - sweetmeat - Medium ](https://medium.com/sweetmeat/simple-one-line-local-http-servers-8adb57d93ec3)
Which design tool do you recommend in 2020?
Tags: ux, design, discuss, webdev
Published: 2020-02-07 05:09:39

I prefer [**Figma**](https://www.figma.com/).

Main advantages are it's a **cloud-based design tool** and it is similar to **Sketch** in functionality and features. And a better way to design, prototype, and gather feedback all in one place with Figma.

Please feel free to share your thoughts and opinions. 

Highly appreciated 🙏🙏🙏

Till then,
**Keep on Hacking, Cheers**
Need some help and talent
Published: 2020-02-07 05:05:23

Hi all,

My name is afshin and I need help.

I’m from Boston Massachusetts. My boss have sent me on a quest and I’m not sure where to start 🙂

We are looking for 3 people with three different great talents.

First person:
 we are looking for someone who can add a page to our website with capability of giving users username and password to login and grab certain reports we have coatumized for them at any shape or form. Each report will get its numbers from some data base.

Second person: 
We are looking for someone to create us a data base environment where data can come in and leave as please to our website as need it. 

Third person:
We need someone to program a software where it can go to a certain accounting software and grab some data 30 days back and populate thise numbers day by day into data base.

Can I get some help? Is there people in here where I can get help from? Or start this project? Maybe point me to right direction if this is not the right place?
Feb. 7, 2020: What did you learn this week?
Tags: weeklylearn, discuss, weeklyretro
Published: 2020-02-07 05:00:02

It's that time of the week again. So wonderful devs, what did you learn this week? It could be programming tips, career advice etc.

![A comic sloth riding a flying book saying "Knowledge is powah!"](https://media.giphy.com/media/XZasQbAd9RGzy2rGhZ/giphy.gif)

Feel free to comment with what you learnt and/or reference your TIL post to give it some more exposure.

{%tag todayilearned %}

And remember, if something you learnt was a big win for you, then you know where to drop it as well.👇👇🏻👇🏼👇🏽👇🏾👇🏿

{% link https://dev.to/jess/what-was-your-win-this-week-1pb2 %}

![A show host dancing a winning dance in their seat](https://media.giphy.com/media/l3q2Z6S6n38zjPswo/giphy.gif)
Fragment Caching vs. Low Level Caching in Ruby on Rails
Tags: rails, caching, performance
Published: 2020-02-07 04:03:16

Let's say we've got some view in a Ruby on Rails app that takes some `SampleObject` instance variable and renders out partials based on `external_components`, which is a method we define on `SampleObject` that performs some long-running task to return the data for the partials. 

We might write our view like this:

```erb
<% @sample_object.external_components.each do |component| %>
    <%= render component %>
<% end %>
```

## Fragment caching 

Our first intuition might be to use [fragment caching](https://guides.rubyonrails.org/caching_with_rails.html#fragment-caching) to speed up the partials a little. You can use fragment caching on the partial like so: 

```erb
<% @sample_object.external_components.each do |component| %>
  <% cache component do %>
    <%= render component %>
  <% end %>
<% end %>
```

This will yield some benefits because it caches the render output of the `component` partial. 

But if `@sample_object.external_components` takes some non-trivial amount of time to run its operations, we haven't quite solved all our caching problems. The call to that method happens outside of the cache. Every time we render this view, we'll invoke `external_components` and slow things down, even with the cached partials. 

## Low-level caching

The `SampleObject` class defines the `external_components` method like this: 

```rb
class SampleObject < ApplicationRecord
    def external_components 
        # Some long running task that returns `components`
    end
end
```

This is a great candidate for [low-level caching](https://guides.rubyonrails.org/caching_with_rails.html#low-level-caching). 

We can rewrite `external_components` like this: 

```rb
class SampleObject < ApplicationRecord
   def external_components 
     Rails.cache.fetch("#{cache_key_with_version}/components", expires_in: 12.hours) do
     # Some long running task that returns `components`
    end
  end
end
```

Now any call to `external_components` will be cached for twelve hours, which is great because we can reuse it elsewhere across our application and also rest assured that the result will be cached as desired. 

## Caching in Development

When I was putting this together in my own application at work, I was having difficulty benchmarking the difference between my cached and non-cached responses. 

I had forgotten that the Rails cache is off by default in development. So my caching wasn't doing anything. 

If you want to see the difference in a development environment, you can [turn on the Rails dev cache](https://guides.rubyonrails.org/caching_with_rails.html#caching-in-development) like so:

```sh
rails dev:cache
```
Signature Digitale et UTX Pool sur la Blockchain
Tags: wavesplatform, signature, digitale, utx
Published: 2020-02-07 03:35:52

Nouvelle vidéo sur notre chaîne Youtube demain pour comprendre la #signature #digitale et l'UTX Pool.

Abonnez-vous et soyez les premiers informés de la mise en ligne!

Pour toutes nos vidéos c'est ici :
https://www.youtube.com/channel/UC2DS9ktTKWGW3NHHV2Ja3_A

#waves #developpeur #smartcontract

Suivez nous et posez toutes vos questions sur :

Telegram : https://t.me/wavesdappsFR
Twitter : https://twitter.com/WavesDevFr
Android's Fundamental Components
Tags: android, beginners
Published: 2020-02-07 03:25:31

I've been through some job interviews and one of my common mistakes was not to study important concepts before it. My mind works more in a practical way than in an abstract way so I avoided, unconsciously,  this concepts. 

So, this article, is about important concepts that you have to know as android developer or that you have to learn if your are starting a career as android developer.

I'll try something new to explain those concepts.

Let's start:

View

<figure>
  <img src="https://i.ibb.co/jLSYrbn/views.jpg" alt="views-sktech" border="0"></a>
  <figcaption>Fig. 1</figcaption>
</figure>

Activity

<figure>
  <img src="https://i.ibb.co/BzHVmLP/activity.jpg" alt="views-sktech" border="0"></a>
  <figcaption>Fig. 2</figcaption>
</figure>

Fragment 

<figure>
<img src="https://i.ibb.co/yQc96pL/fragment.jpg" alt="views-sktech" border="0"></a>
  <figcaption>Fig. 3</figcaption>
</figure>

Intent

<figure>
<img src="https://i.ibb.co/K9ygB3L/intent.jpg" alt="views-sktech" border="0"></a>
  <figcaption>Fig. 4</figcaption>
</figure>

Content Provider

<figure>
<img src="https://i.ibb.co/XpXT1YD/content.jpg" alt="views-sktech" border="0"></a>
  <figcaption>Fig. 5</figcaption>
</figure>

Service

<figure>
<img src="https://i.ibb.co/F0qtXTs/service.jpg" alt="views-sktech" border="0"></a>
  <figcaption>Fig. 6</figcaption>
</figure>

AndroidManifest.xml

<figure>
<img src="https://i.ibb.co/gVFDfj7/manifest.jpg" alt="views-sktech" border="0"></a>
  <figcaption>Fig. 7</figcaption>
</figure>
How to Avoid Tedious CSS and XPath Queries in End-to-End and Component Tests
Tags: softwareengineering, programming, tdd, javascript
Published: 2020-02-12 21:32:50

---
title: How to Avoid Tedious CSS and XPath Queries in End-to-End and Component Tests
published: true
date: 2020-02-07 03:04:13 UTC
tags: software-engineering,programming,tdd,javascript
canonical_url: 
---

[![](https://cdn-images-1.medium.com/max/2600/0*jNu6u0bH5uvLmdzr)](https://medium.com/better-programming/how-to-avoid-tedious-css-and-xpath-queries-in-end-to-end-and-component-tests-732c5b86f2f6?source=rss-3a534b5053e6------2)

Five tips to improve your front-end tests

[Continue reading on Better Programming »](https://medium.com/better-programming/how-to-avoid-tedious-css-and-xpath-queries-in-end-to-end-and-component-tests-732c5b86f2f6?source=rss-3a534b5053e6------2)
What would be the best night time to code?
Tags: discuss
Published: 2020-02-07 02:55:32

I have this situation, my full time job consumes most of the morning, so I have availability at night to work remotely, also at that time (much better at dawn) is when I have a better 3G connection.

In your experience as developers, what would be the best practice, getting up at 2 am or going to bed a little later?