teleren/devto huggingface dataset:
Simple way of logging return values of any function
Tags: go
Published: 2021-11-27 08:26:33

---
title: Simple way of logging return values of any function
published: true
description: 
tags: go
//cover_image: https://direct_url_to_image.jpg
---
Have you ever had the need to log final return values before a function returns? One way is to obviously log them just before return. But, they don't work in all the cases. Let me show you why. 


First we'll take simple example of logging:

```go
func minAndMax(arr []int) (min, max int){
	min = arr[0]
	max = arr[0]
	for _, value := range arr {
		if value < min {
			min = value
		}
		if value > max {
			max = value
		}
	}
	log.Println("Returning", min, max)
	return min, max
}

func main(){
	var arr []int = []int{3,2,5,4,7,6}
	minAndMax(arr)
}
```

This works as expected. But, it still needs us to track the end of function.

Also, as said before it doesn't work always. Let's see what happens with this example:

```go
func changeBeforeReturn()(ret int) {
	a := 1

	defer func() {
		ret++
	}()

	log.Println("Returning", a)
	return a
}

func main(){
	v := changeBeforeReturn()
	log.Printf("%d", v)
}
```

You would expect the log in `changeBeforeReturn` to print __1__. But, your log in `main` method prints __2__!!😬😱😨

What happened? Well that's how the combination of defer and named return arguments works.

We can easily fix this, and the first issue of keeping track of last statement with a simple deferred printing statement using named return arguments:

```go
func changeBeforeReturn()(ret int) {
	a := 1

	defer func() {
		log.Println("Returning", ret)
	}()

	defer func() {
		ret++
	}()

	return a
}

func main(){
	v := changeBeforeReturn()
	log.Printf("%d", v)
}
```

This correctly prints __2__, not __1__. Do make sure to write this deferred function before any other one.

Hope it helps... ☺️
Smart contract revert error when calling payable function.
Published: 2021-11-27 08:20:16

I am using fantom testnet.
I called payable deposit function.
But smart contract can't accept FTM token.
I need help.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u7t61go9eoiwn5z8od9z.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o5rdhxh0xxlmqzpv6yuq.png)
1 Minute to Learn Grep Command in Linux with Examples
Tags: linux, systems, ubuntu
Published: 2021-11-27 07:47:40

Grep command is one of the best common ones for Unix users. If you use it well, you can improve your productivity using Linux. In this article, I will help you learn grep command in linux with simple examples. I believe that you can be a grep expert after reading this post.

Read more: [Learn Grep Command in Linux](https://linuxtus.com/learn-grep-linux-examples/)
‘Upgraded’ to Windows 10 on Dual Boot, and Can’t Boot to Ubuntu Partition!
Tags: ubuntu
Published: 2021-12-07 18:39:55

---
title: ‘Upgraded’ to Windows 10 on Dual Boot, and Can’t Boot to Ubuntu Partition!
published: true
date: 2021-11-27 07:25:45 UTC
tags: Ubuntu
canonical_url: https://stackallflow.com/ubuntu/upgraded-to-windows-10-on-dual-boot-and-cant-boot-to-ubuntu-partition/
---

<header>
<p><span style="font-size: 1.2em; color: initial;">boot</span><span style="font-size: 1.2em; color: initial;">dual-boot</span><span style="font-size: 1.2em; color: initial;">grub2</span><span style="font-size: 1.2em; color: initial;">partitioning</span></p>
</header>

I recently updated my windows 7 to 10, and destroyed grub in the process. I ran Boot-Repair on a live CD and managed to get the Windows Partition back. However grub still doesn’t come up for me.

The boot-repair url I received was [http://paste.ubuntu.com/12189762/](http://paste.ubuntu.com/12189762/).

Edit:

Oldfred helped me figure out the problem. I didn’t really understand how the partition worked. The extended partition wraps around both the linux and swap partition, but for some reason the linux partition was not showing up. I booted to a live disk and ran parted rescue:

```
sudo parted /dev/sda unit s print //this printed the current partition table

sudo parted
unit s
rescue
Start? //Here I entered in 1 sector after the extended partition
End? //Here I entered in 1 sector before the swap parition

```

After that I ran boot-repair again and was able to restore grub back in place! Everything is working great now. Hopefully this post can help someone else!

#### Best Answer

It is not grub that is missing, but your Linux partition.

```
 /dev/sda2 208,894 416,761,855 416,552,962 5 Extended
 /dev/sda5 400,158,720 416,761,855 16,603,136 82 Linux
 swap / Solaris

```

You have a missing partition one or two sectors after the start of the extended and a few sectors before the start of sda5 swap. It probalby was sda5, and swap was sda6 but since using UUID to boot does not matter. Many use testdisk or parted rescue and reinstall grub to MBR and system works.

Backup partition table before any changes, so you can get back to current if changes not correct

```
sudo sfdisk -d /dev/sda > PT_sda.txt

```

More details:

[Windows 10 upgrade led to grub rescue](https://askubuntu.com/questions/654386/windows-10-upgrade-lead-into-grub-rescue/655080#655080)

Use parted rescue to restore missing partition details in post #22

[http://ubuntuforums.org/showthread.php?t=1775331](http://ubuntuforums.org/showthread.php?t=1775331)

[http://www.gnu.org/software/parted/manual/html\_node/rescue.html](http://www.gnu.org/software/parted/manual/html_node/rescue.html)

The post [‘Upgraded’ to Windows 10 on Dual Boot, and Can’t Boot to Ubuntu Partition!](https://stackallflow.com/ubuntu/upgraded-to-windows-10-on-dual-boot-and-cant-boot-to-ubuntu-partition/) appeared first on [Stack All Flow](https://stackallflow.com).
Why Is the Installer Not Showing Any Partitions in Ubuntu?
Tags: ubuntu
Published: 2021-12-07 18:39:46

---
title: Why Is the Installer Not Showing Any Partitions in Ubuntu?
published: true
date: 2021-11-27 07:20:03 UTC
tags: Ubuntu
canonical_url: https://stackallflow.com/ubuntu/why-is-the-installer-not-showing-any-partitions-in-ubuntu/
---

<header>
<p><span style="font-size: 1.2em; color: initial;">partitioning</span><span style="font-size: 1.2em; color: initial;">system-installation</span></p>
</header>

I’m having a problem installing Ubuntu, and Kali as well. I downloaded the iso from the official site & tried installing using USB. I also tried desktop installation, but the problem is same.

It shows a single drive i.e. my total Hard Disk and if I select it, it asks me to create a new partition & shows total space as FREE.

It’s with all Ubuntu I downloaded, 11.10 Server, 12.10 and 13.04. I also tried to install BackTrack’s new version Kali Linux but again I got the same problem.

I hope I meet thier system requirements. Here’s my system details for your ease:

- OS: Windows 7 Ultimate
- Processor: Intel P4 2.80 GHz
- RAM: 3GB
- Hard Disk: 320GB
- No of Local Drives: 4  
(1 Primary, 3 Logical)
- Free Space: 195GB (about)
- Motherboard: G31
- Cache: 1MB  
Help me, please.

#### Best Answer

This symptom is usually caused by one of two problems:

- **Leftover software RAID data** — If the disk had been (or is being) used with software RAID, leftover RAID data can confuse the Ubuntu installer. You can usually fix this problem by typing `sudo dmraid -E -r /dev/sda`; however, you should be _very_ sure that you’re not currently using software RAID. If you erase RAID data when the system is actually using RAID, the result can be problems accessing your disk at all.
- **A damaged partition table** — The libparted library (upon which the Ubuntu installer relies) is extremely sensitive to partition table problems. If any exist, it usually reports the disk as being empty. My [FixParts](http://www.rodsbooks.com/fixparts/) program (part of the `gdisk` package in Ubuntu) will correct many of these problems in an automatic or semi-automatic mannger; see its Web page for details. Other problems may require more specialized and manual repairs. If you think this is the source of the problem and if FixParts can’t fix it or if you’re wary of using FixParts, post the output of `sudo fdisk -l /dev/sda`. (Add four spaces to the beginning of each line of that output to preserve columnar output.)

The post [Why Is the Installer Not Showing Any Partitions in Ubuntu?](https://stackallflow.com/ubuntu/why-is-the-installer-not-showing-any-partitions-in-ubuntu/) appeared first on [Stack All Flow](https://stackallflow.com).
How to Add Custom ‘.Desktop’ Application Launchers to Ubuntu Dock?
Tags: ubuntu
Published: 2021-12-07 18:39:42

---
title: How to Add Custom ‘.Desktop’ Application Launchers to Ubuntu Dock?
published: true
date: 2021-11-27 07:19:33 UTC
tags: Ubuntu
canonical_url: https://stackallflow.com/ubuntu/how-to-add-custom-desktop-application-launchers-to-ubuntu-dock/
---

<header>
<p><span style="font-size: 1.2em; color: initial;">desktop</span><span style="font-size: 1.2em; color: initial;">gnome-shell</span><span style="font-size: 1.2em; color: initial;">ubuntu-dock</span></p>
</header>

I have made `.desktop` files for Ubuntu 16.04 to access my Google Chrome profiles, but once I upgraded to Ubuntu 17.10 (it worked up to Ubuntu 17.04) they got removed from the dock and I can’t pin them back.

**Sample File:**

```
#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=google-chrome
Name[en_US]=Google Chrome
Exec=google-chrome --profile-directory=Default
Comment[en_US]=Chrome
Name=Google Chrome
Comment=Chrome Browser
Icon=google-chrome
Categories=Browser;Internet;
```

#### Best Answer

1. Create a `.desktop` file (or, copy if you already have one ready), say `my-chrome.desktop`, in your `~/.local/share/applications/` directory.  
You may add the following lines to it for a simple, bare-minimum `.desktop` launcher
```
[Desktop Entry]
Name=My Chrome
Comment=Chrome my profile
Exec=google-chrome --profile-directory=Default
Icon=google-chrome
Type=Application
Terminal=false

```

The keys are as described below

  - `Name=` Specific name of the application (For this particular example, I used “_My Chrome_” to avoid confusion with the already existing Google Chrome launcher. You can use any other name.)
  - `Comment=` A short description of the application
  - `Exec=` The command to execute in order to launch the application
  - `Icon=` Icon for the application (You can use an icon provided by your icon theme or an absolute path to an image file.)
2. Click ‘_Activities_‘ or ‘_Show Applications_‘ and search for “My Chrome” (application name as per the `Name` key). It should appear.
3. Right click on it and select ‘_add to favourites_‘.  
If right clicking on application icon in dock doesn’t show “_Add to favourites_” option, search for the application in _Activities_ screen, and then **drag it across to the dock** (suggested by [Legolas](https://askubuntu.com/users/611441/legolas)).

If nothing works, see this Q&A: [Cannot add custom launcher to Ubuntu Dock (Add to Favorites)](https://askubuntu.com/q/990833/480481)

The post [How to Add Custom ‘.Desktop’ Application Launchers to Ubuntu Dock?](https://stackallflow.com/ubuntu/how-to-add-custom-desktop-application-launchers-to-ubuntu-dock/) appeared first on [Stack All Flow](https://stackallflow.com).
How to Find Out Root Password for Installing Software in Ubuntu?
Tags: ubuntu
Published: 2021-12-04 10:56:21

---
title: How to Find Out Root Password for Installing Software in Ubuntu?
published: true
date: 2021-11-27 07:16:34 UTC
tags: Ubuntu
canonical_url: https://stackallflow.com/ubuntu/how-to-find-out-root-password-for-installing-software-in-ubuntu/
---

<header>
<p><span style="font-size: 1.2em; color: initial;">password</span><span style="font-size: 1.2em; color: initial;">root</span></p>
</header>

I’m trying to install the [NetBeans](http://en.wikipedia.org/wiki/NetBeans) IDE in my Ubuntu and in the process it’s asking for my root password which I don’t remember. I know my [sudo](http://en.wikipedia.org/wiki/Sudo) user password. How can I recover my root password?

#### Best Answer

As default Ubuntu has no password set for the root user, i.e., the account named `root`. To gain root privileges as another user you have to type in your _own_ password. This is the password you set for the first user account while installing Ubuntu.

To set a password for the `root`, run the following command in a Terminal shell:

```
sudo passwd root

```

After this you are asked to type in the new password twice. After this the `root` account has its own password, so you can actually log in with the user name `root`.

The post [How to Find Out Root Password for Installing Software in Ubuntu?](https://stackallflow.com/ubuntu/how-to-find-out-root-password-for-installing-software-in-ubuntu/) appeared first on [Stack All Flow](https://stackallflow.com).
Publishing my first package
Tags: opensource, osd600
Published: 2021-11-27 07:15:40

This week, I've published my 1st package on [npm](https://www.npmjs.com/) - [mh-ssg](https://github.com/minhhang107/mh-ssg) - a static site generator CLI.

The process is not complicated and only involves 4 steps:

#### 1. Configure the package
In the `package.json`, I need to make sure that I have all the required information filled: `name` and `version`. When the package is first published, usually it should be version 1.0.0.

#### 2. Publish the package
In order to publish package on [npm](https://www.npmjs.com/), I had to first create an account on the website. Then log in from the command line with:
```bash
npm login
```

After successfully logging in, I can publish the package with:
```bash
npm publish --access public
```

#### 3. Test the package
I asked my friend for help to test the package I just published. She was able to install the package but when she tried to run it, she found a bug and noticed that `README.md` was outdated. Following her feedbacks, I fixed the bug and updated `README.md` with more instructions on how to use the tool.

#### 4. Update the package
When all the bug fixes were in place, I updated the version in `package.json` with any related test cases, committed those changes and did a final `npm publish`.

Now [mh-ssg](https://www.npmjs.com/package/mh-ssg) is available on [npm](https://www.npmjs.com/) and ready to be used by the community. The tool can be installed with the simple command:
```bash
npm i mh-ssg
```
Flatiron | In the Deep End
Published: 2021-11-27 06:24:37

Hooray, I did it! This is my last project with Flatiron. For the last several months my life has been consumed in code, tearing into projects. Now is the time to apply all my newly acquired skills and complete the course and begin my career as a software engineer.

Learning the coursework was like drinking water from a firehouse. It all comes at once and at times can be a lot to handle. After careful review, confusing subjects became clarified and gave me a newfound appreciation of the work that has gone into programming.

Before Flatiron I had no programming experience. Now I know how to create full stack applications. It’s amazing what can happen in only a few short months.

I realize with this final project just how far I’ve come from day one. Learning to program has in many ways been like learning to swim. On day one I could barely float.  I couldn’t imagine creating a website frontend. Now, I’m making application with both a frontend and backend

While this article signals the end of my time as a Flatiron student. The field of programming is vast and I have only scratched the surface of what there is to know. There will be obstacles along the way, but Flatiron has taught me how to overcome them. So when rough times head my way, I will be able to keep my chin up and take it on, like a true programmer.
Django Interview Questions
Tags: django, career, beginners
Published: 2021-11-27 06:41:53

In case you google for web improvement occupations, there, you will see as a large portion of them require Django abilities. Assuming you are planning for an impending web designer talk, we would suggest you go through these best Django inquiries questions.

![Django interview questions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dzu8g5cp769dl62l909b.png) 

## Top Interview questions:
Here we listed top interview questions of Django. If you want to know their answers go through this blog on [Django Interview Questions and Answers](https://www.techgeekbuzz.com/django-interview-questions/).

1. What is Django?
2. What is the latest version of Django?
3. From where does Django get its name?
4. On which architecture design pattern Django works?
5. Give some advantages of using Django.
6. Give some features of Django.
7. Give some disadvantages of Django.
8. Why do we use the include() function in the project urls.py file?
9. Name all the types of inheritance possible in Django.
10. What is the context in Django?
11. If you have worked with Flask then give some differences between Flask and Django.
12. How to install Django in your system?
13. How to create a Django project?
14. By default which database does Django follow?
15. Where do we register our models?
16. What does the createsuperuser subcommand do?
17. Name the caching strategies in Django.
18. What is the use of manage.py in Django?
19. What parameters do we use in signals?
20. Name the usages of middlewares in Django.
21. Give some drawbacks of Object Relational Mapping in Django?
22. Why do we use the migration subcommand?
23. Why do we use the makemigrations subcommand?
24. What does the session framework do?
25. Name all the manage.py subcommands.
26. Name some common Django exceptions.
27. How can we register a model in Django?
28. What do you know about ‘django-admin’?
29. What are the models in Django?
30. What are the views in Django?

## Conclusion

With this, we have arrived at the finish of our Django inquiries questions and replies. We trust you find these inquiries applicable to peruse prior to showing up for a web developer interview.
OSD600 - Publishing my-ssg To NPM
Tags: opensource
Published: 2021-11-27 06:39:02

#1. Lab10 requirement
After a long time updating [my-sgg](https://github.com/hlavu/my-ssg) with new features, this time is an appropriate time to provide a release that allows users to install and use the tool easier. 

Since the tool is written in [NodeJS](https://nodejs.org/en/), I will make use of [npm](https://www.npmjs.com/) to share the tool.
#2. Publishing process
In order to publish a package to **npm**, I need to **create an npm account** first. If not, an error code `404` will be appeared.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mv4uolzuienec38s45r7.png)
Next, I **verified the email** to authenticate the account. After having an authenticated account, I run `npm login` command then provided `username`, `password` and `email` to **sign in the npm account**.

When I logged in successfully, a message will be displayed to announce.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8yerncqrkk6ozd7movvv.png)
 
Finally, I run `npm publish` command to publish the [package](https://www.npmjs.com/package/ssg-cli) to **npm**. 

After making sure that the package is available in **npm** I asked my friend to test the tool. Instead of telling her how to install and use the package, I recommended her to read through the `README.md` file first. 
With the instruction on `README.md` she succeeded in installing the package. On her machine, she tested all the provided features and they all worked as expected.

#3. Overall
This is an interesting lab, I have a chance to learn new knowledge about *npm package* since I never published a package before. Also, this is a good way to share my work with others. 

All in all, thank you for reading the post.

Happy coding!
Game of Thrones-Houses Carousel using HTML, CSS, JavaScript
Tags: html, css, javascript, webdev
Published: 2021-11-27 06:35:35

Recently I have finished watching one of the most hyped Tv series Game of thrones. I regret now for not watching when it was aired in HBO. anyway now I am done with all the seasons. I wanted to create some simple n beatiful carousel since long time.So, when I was looking thru random reddit post got this idea of creating carousel for houses in the series.

Final output:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nsgnrnyklhog8n5vyvse.png)

Codepen link:
https://cdpn.io/pavankalyan-c/debug/NWvQOKY/GnAnbXdNoZnA

This is my first post in dev.to 😃 ✅
#Caruosel #javascript #css #html #gameofthrones #winteriscoming
A Comprehensive Guide about HTTP 405 Method Not Allowed Error
Tags: infographic, beginners, html
Published: 2021-11-27 06:17:03

HTTP 405 error is the response status code that denotes:

_Request is received_
_Request is recognized_
_The request is denied because the used method is not allowed_

## Common Phrases Representing HTTP 405 Error

An HTTP 405 error can appear in a number of ways across varied servers. Some of these common representation phrases are:

_405 Method Not Allowed_
_405 Not Allowed_
_Method Not Allowed_
_HTTP 405 Error_
_HTTP Error 405 – Method Not Allowed_
_HTTP 405 Method Not Allowed_
_Error: 405 Method Not Allowed_
_405 – HTTP verb used to access this page is not allowed_
_HTTP Status 405 – HTTP method GET is not supported by this URL_

![HTTP 405 Method Not Allowed Error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2fnagj9gibn4teoi4nq2.jpg)



Courtesy of [SpiralClick](https://spiralclick.com/)
Macros
Tags: rust
Published: 2021-11-27 06:14:21

---
title: Macros
tags: rust
---

``` rust
([ $( $elem:expr ),* ]) => // 0 or more [aa, bb, cc]
([ $( $elem:expr )* ]) => // 0 or more [aa bb cc]
([ $( $elem:expr ),+ ]) => // 1 or more [aa, bb, cc]
```

outer bracket → pattern `$ ( $elem:expr )*`
`expr` → Expression
`stmt` → Statement
`ty` → type
`tt` → token tree
`ident` → identifier

## JSON macro

This token tree pattern matches to first token tree, otherwise [10,20] is read as expression and looks for From[10,20] which is wrong
`([ $( $elem:tt ),* ])`

``` rust
macro_rules! json {
  (null) => {Json::Null};
  ([ $( $elem:tt ),* ]) => {
      Json::Array(vec![ $( json!($elem) ),* ])
  };
// $value:expr, $value:tt (token tree works only)
  ({ $($key:tt : $value:expr),* }) => {
      {
          let mut fields = Box::new(HashMap::new());
          $( fields.insert($key.to_string(), json!($value)); )*
          Json::Object(fields)
      }
  };
  ($other:tt) => {
      Json::from($other)
  };
}
```

For example,	

``` rust
59 |           Json::from($other)
   |           ^^^^^^^^^^ the trait `From<[{float}; 2]>` is not implemented for `Json`
...
74 |       let role = json!({
   |  ________________-
75 | |         "name": "movies",
76 | |         "actor": [10.0, 20.0]
77 | |     });
   | |______- in this macro invocationr
```

This `[10.0, 20.0]` looks for `From[{float}; 2` because it is trying to evaluate that expression. Instead use `$value:tt` instead. This converts to `Json::Array(<[_]>::into_vec(box [Json::from(10.0), Json::from(20.0)])),`This token tree pattern matches to first token tree, otherwise [10,20] is read as expression and looks for From[10,20] which is wrong `([ $( $elem:tt ),* ])`

## Internal rules pattern. This is extremely useful pattern
		
``` rust
#[macro_export]
macro_rules! foo {
    (@as_expr $e:expr) => {$e};
			  
    ($($tts:tt)*) => {
   foo!(@as_expr $($tts)*)
    };
}
			  
/*
macro_rules! macro1 {
	() => { macro!(@macro2); } ;
	(@macro2) => { }
	}
}
			  
*/
			  
fn main() {
    foo!({
  println!("hello") ;
    });
}
```

## TT munchers

``` rust
macro_rules! handle_operations {
	(up $($tt:tt)*) => {
		println!("up");
		handle_operations!($($tt)*);
	};
	(down $($tt:tt)*) => {
		println!("down");
		handle_operations!($($tt)*);
	};
	() => {};
}
		  
		  
fn main() {
	handle_operations!(up up down down);    
}
```	

## Counting macro
	
``` rust
	macro_rules! count {
		() => (0usize);
		( $x:tt $($xs:tt)* ) => (1usize + count!($($xs)*));
	}
```