How to fix: “No bootable device” on Dell Inspiron 3458

I bought a new disk, a SSD. I am using a Dell Inspiron 3458. So I open up the computer and changed the disk, no problem so far. Really easy process. Then I rebooted and installed the OS, still no problem. But then when I tried to boot up the machine again a got hit with a scary error.

I can’t remember exactly what it said, but it was something like this

No bootable device

Press F2 to enter bios-configuration

Press F5 to reboot

And some other stuff.

I was lost. So I started the great google-hunt. Read through a ton of blog-posts and videos, and everything I could get my hands on. I tried to change the boot-order to legacy mode. But nothing worked. In the system info in bios I could see that the machine recognized the disk, it just couldn’t find it when I booted up.

Then I found this blog-post: https://itsfoss.com/no-bootable-device-found-ubuntu/. But it was written for an Acer Aspire. But I felt like this was the same issue as I had. And in the comments I found my anonymous hero Chris, who wrote the following comment:

I have a Dell Inspiron, I followed your process, more-or-less, but from step 3 (“Select an UEFI file as trusted for executing”) onwards I had to do something slightly different in the BIOS:

– Settings → General → Boot Sequence
– Press “Add Boot Option”
– Boot Option Name: ubuntu (I don’t think this matters much, but this seems like a sensible name)
– File Name: press the browse button, and as in the instructions above, find the shimx64.efi boot file
– Save this boot option
– Exit the BIOS, and with any luck your computer will now boot

I followed these steps and it worked perfectly.

Memory card – How does it work?

My notebook is a bit slow. I only have 4 gb of ram. So I want to upgrade it a bit.

First thing first. What do I have now?

sudo dmidecode --type memory

This gives us all the info we need about the current memory in out computer.

# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x005B, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 16 GB
Error Information Handle: Not Provided
Number Of Devices: 2

Handle 0x0060, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x005B
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 4096 MB
Form Factor: SODIMM
Set: None
Locator: DIMM A
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: 1600 MHz
Manufacturer: Micron
Serial Number: CFC29B80
Asset Tag: 9876543210
Part Number: 8KTF31561HK-1G6E1
Rank: 1
Configured Clock Speed: 1600 MHz

Handle 0x0065, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x005B
Error Information Handle: Not Provided
Total Width: Unknown
Data Width: Unknown
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: DIMM B
Bank Locator: Not Specified
Type: Unknown
Type Detail: None
Speed: Unknown
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown
Configured Clock Speed: Unknown

In the first section we can see that the maximum-capacity of this computer is 16gb of memory and that the there is space for two devices. In other words, it has two slots for memory. So I guess I can add two 8gb of memory without problem.

Then it lists the current memories I have installed. As you can see I only have one memory installed, on the first slot. And it appears to be a 4gb memory. What is important to note here it the type. Is says here that it is a DDR3. So my new memory must be a DDR3, if cannot be DDR2 or DDR4. Motherboards are usually only able to support one memory-type.

Big-O notation – what is it? How does it work?

I think it is like a rite of passage for a self-taught programmer to write this blog post. You will get to a point where you feel inadequate for not understanding the Big-O notation. You think it is some dark magic that they only teach at computer science programs at the university. Okay, so let’s get to the bottom of this, well at least get through the basics.

First, Big-O notation helps us understand the complexity of an algorithm. And it always looks at the worst-case-scenario of an algorithm, the slowest possible outcome.
I am going to go through these types. In more practical terms, we are looking at understanding CPU-usage.

O(1) – Order of one
O(N) – Order of N

O(N + M)

O(N * M)
O(N^2) – Order of N squared
O(log N) – Order of log N
O(n log N) – Order of n log N

O(1) – Constant-time algorithm

This is just a simple operation that takes the same amount of time to do no matter how big the number is. This is also called Constant-time algorithm.

For example

var myArray = [];

//This will take as much time to perform as:
console.time("n(1)");
myArray.push(10);
console.timeEnd("n(1)");

// this

console.time("n(1)");
myArray.push(1000000000000000000000000000000000000000000000000);
console.timeEnd("n(1)");

The complexity of this operation will never change no matter how big the number we push is. The push is only one operation, no matter how big the number is. This is usually represented as a flat line in an x/y diagram. It is the blue line in the image. As you can see the complexity of the algorithm doesn’t increase if we increase the amount of data.

bigO

 

O(N) – Linear-time algorithm

So let’s move on to the next on our list. So in this case the complexity is directly related to the size of the array we want to iterate over. Let’s look at an example.


console.time("O(N)");
for (var i = 0; i < 1e7; i++) {
}
console.timeEnd("O(N)");

console.time("O(N)");
for (var i = 0; i < 2e7; i++) {
}
console.timeEnd("O(N)");

console.time("O(N)");
for (var i = 0; i < 3e7; i++) {
}
console.timeEnd("O(N)");

console.time("O(N)");
for (var i = 0; i < 4e7; i++) {
}
console.timeEnd("O(N)");

//O(N): 13.415ms
//O(N): 21.307ms
//O(N): 30.151ms
//O(N): 39.580ms

As we can see here it takes roughly nine milliseconds for each 10 million loop. This means that for every 10 million items we add to the loop the algorithm complexity increase will be linear. As you can see on the image above.
A more practical example would be. If you need to search through an array to find a specific item you need to iterate over every single item. Of course it could be that you find the number you are looking for after one iteration, it might be in the beginning of the array. But Big O notation assumes worst case scenario.

O(N+M)

Well, two loops iterating over their own dataset.

var n = 10;
var m = 100;
for (var i = 0; i < n; i++) {
//Do stuff
}

for (var i = 0; i < m; i++) {
//Do stuff
}

O(N^2) – Quadratic-time algorithm

So far so good, nothing to complicated. Now let’s look at O(N^2).

Let’s say you are given an array with numbers. You are then asked to find out if it is possible to get the number 10 by adding two of the numbers in the array together. To do this you could write the following code.

function findSum(arr, sum){
  for(var i = 0; i < arr.length - 1; i++){
    for(var j = i + 1; j < arr.length; j++){
      if (arr[i] + arr[j] == sum)
    return true;
    }
  }

 return false;
}

 

This is like a brute-force attempt. We are just trying every single possible combination until we get a success. This is not very efficient, but it works. And if the size of the array increases the run time complexity will increase exponentially. If there are five items in the array it must loop through it 5^2. This can pretty soon generate code that needs to do so many iterations. By increasing it from 5^2 (25) to 6^2 (36) we just increase the array with one (one more item in the array), but we increase the number of iterations by 36 – 25 = 11.

A practical example of this would be the bubble sort.

If you have three loops nested we get O(N^3), and so on. This is course gets slow fast, so if you notice you have a O(N^2) or a O(N^3) algorithm you should probably think of ways to fix it.

To pronounce this you say “big oh of n squared“.

O(N*M)

Not all nested loops are O(N^2). For example, the following would not be O(N^2).

var arrayOne = 10;
var arrayTwo = 100;

for (var i = 0; i < arrayOne.length; i++) {
for (var j = 0; j < arrayTwo.length; j++) {
}
}

Since we are iterating over another loop inside the first loop we are not looping n^2, but instead we are looping n*m.

O(log N) – Logarithmic

Log is the shorthand for logarithm. And logarithm is the opposite of exponential. A concept I am more familiar with, so it helps me to understand logarithm.

This is a great description.
O(log n) can be seen as: If you double the problem size n, your algorithm needs only a constant number of steps more.

Image

 

Okay, this might freak someone out. Since it look way to math-ish. So instead let’s look at a video. Minute 17-25.

This is an amazing explanation.
https://stackoverflow.com/questions/9152890/what-would-cause-an-algorithm-to-have-olog-n-complexity

https://stackoverflow.com/questions/9152890/what-would-cause-an-algorithm-to-have-olog-n-complexity

A good example of O(log N) is binary tree search.

Example
Finding a number in an array, the Binary Tree Search-way. Or the O(log N)-way.

 

References

This is a great reference to algorithms that state their complexity with big-o.

http://www.thatjsdude.com/interview/js1.html

http://discrete.gr/complexity/

Nested loops
https://stackoverflow.com/questions/362059/what-is-the-big-o-of-a-nested-loop-where-number-of-iterations-in-the-inner-loop

https://justin.abrah.ms/computer-science/big-o-notation-explained.html

Cronjob in Linux

To create a cronjob on a linux-machine you just run

#The -e flag stands for edit
crontab -e

#The -l flag lists the cronjobs
crontab -l 

So I added my cronjob like this and program it to run every minute:

* * * * * /home/user/cron/script.sh

CPU-intensive operations in NodeJS

Lately I have been learning about CPU-intensive operations and I/O-intensive operations. The problem I have run into has been: how do I handle long-running tasks in the routes/endpoints. Let’s say that you have a million items you want to show the user, so and you have to iterate over all the items and edit them in some way. Wait, that a crappy example, let’s instead say that you have a ton of statistics and you want to give the user a real-time analysis of that statistics. That is going to take a lot of time. If that happens right in the endpoint that request is going to block the node-server until the process is finished. That’s because of the single-threadedness of node (Yada yada this presentation is still the best thing on the internet to explain nodes event-loop.). This means that all other users have to wait for that request to finish.

While I read about this I came across a few concepts that are useful to know.

CPU-bound

This can sometimes be called: long running CPU tasks, CPU intensive tasks or
CPU-bound tasks.

A program/application/process that is CPU-bound is something that requires a lot of CPU-power. CPU-power is usually needed when doing a lot of calculations.

I/O-bound

An application that is I/O-bound is mostly wait for network or database. This is something that Nodejs does really good. Since it can process several requests while it is waiting for a response from the database. That’s why node can be so fast in servering many requests.

Different Server

So there are conceptually some different servers. One being a web-server.
A web-server is basically a I/O-bound server. The main focus is to server requests as fast as possible. That mean that if you have an operation that is CPU-bound is does not belong in the Web-server. That process probably belongs better in a worker-server.

Possible solutions for CPU-bound operations in a NodeJs-server

Okay, so how to we solve the problem of doing CPU-bound operations on a NodeJS application?

Here are some of the alternatives I have run into while researching this. This list is not exhaustive, and it might not even be correct (I have just been googeling around a bit, I’m no expert).

  • 1. “Offline”-server dedicated to processing data
    You can have a server that process the data offline, in the sense that it is not in real-time.
    A. Cron-job
    Having a cron-job that calculates on a schedule. For example every half hour or something like that. This is of course very resource consuming. What if nothing has happened and the server process the data again? That would be very unnecessary.

    B. Only calculate when an update in the database is done. This could be achieved by having a message sent every time the database gets updated.

    C. Do part of the calculation when an update to the database is done. But only process the data since the last process. If this is possible.

    There is a pretty good answer on SO about this.

  • 2. Separate server do the CPU-crunching.
    Have a separte server do the number crunching. And then just connect the web-server to that endpoint. Since the request is async, other requests will work meanwhile. Since node can work while waiting for a callback.

    Here is a blog-post discussing this.

  • 3. Using Nodes ClusterModule — Clusters – LoadBalancer with separate processes

    How to Create a Node.js Cluster for Speeding Up Your Apps

  • 4. Rabbit queue message

  • 5. process.NextTick/setImmediate
    If you know what you are doing and you really want the operation to happen on your web-server. This can be a way.
    This trick can make synchronous operations asynchronous. So that the server can attend other easier tasks meanwhile. This is blog exemplified it pretty well.

    http://bytearcher.com/articles/io-vs-cpu-bound/?utm_source=hashnode.com
    http://stackoverflow.com/questions/3491811/node-js-and-cpu-intensive-requests?rq=1
    http://stackoverflow.com/questions/16974557/why-is-node-js-not-suitable-for-heavy-cpu-apps?noredirect=1&lq=1
    http://programmers.stackexchange.com/questions/158781/cpu-heavy-web-server
    https://www.toptal.com/nodejs/top-10-common-nodejs-developer-mistakes
    http://neilk.net/blog/2013/04/30/why-you-should-use-nodejs-for-CPU-bound-tasks/

Atom plugins and configs

Plugins
– Minimap
Show a minimap.
– file-icons
Show nice file-icons in the file-tree.
merge-conflicts
Show git merge-conflicts in a more intuitive way.
– keyboard-localization
If you have a non-english keyboard.
– react
Show react-syntax.
– pigments
multi-cursor-plus
This is a great plugin. For the times you want to use multiple cursors but now exactly below each other. It requires a copy-paste configuration.
color-picker
Makes it a bit easier to select colors for your css
– linter
To automatically check the code.
– linter-jshint
For linter to work on JS
Here is a list of other languages languages
– linter-markdown
– atom-terminal
this plugin let’s you run ctr-alt-t in any file, and a terminal will open up in that directory

Themes
atom-material-ui
Syntax
atom-material-syntax

This can be done fast with the atom package manager

apm install minimap file-icons merge-conflicts keyboard-localization react pigments multi-cursor-plus color-picker linter linter-jshint atom-material-syntax atom-material-ui atom-terminal

Paste in this in your keymap.json file to get the comment function to work correctly.

'atom-workspace atom-text-editor:not([mini])':
  'ctrl-7': 'editor:toggle-line-comments'

Print out field from MongoDB and save in file

Today I encountered a fun little problem. I had to run through a database and print out every single field of the query and save it in a text document.

So I ended up doing it like this.

First I wrote a script that looks like this:

//script.js
db.collection.find({active: true}).forEach(
    function(x) {
        print(x.id); 
    } 
);`

Then I ran the script like this:

`mongo databaseName script.js | sed -n -e ‘1,1000p’ > testing.txt`

I added the sed-command to print out the first 1000 lines. This approach worked out well, and I can add sort and uniq if I need that.