A Quest: How I Found My Linux Soulmate!

In our contemporary world wide web, once you stick your head out of the comfortable windows homosphere, the first thing that hits you is the astronomically huge number of Linux distributions out there. There is a disparate Linux distribution ( or -err- a whole another window, if you are not a Linux person) for everything. E.g. a different Linux distribution for artists, music enthusiasts, students, industry level giants, giants, kids, dinosaurs, and you name it.

Long story short, if you are looking for a good alternative to windows operating system, it might take you while before you settle down with a Linux distribution that holds answer to your every (computer) needs and problems.

Similarity, once I ditched windows – and for good reasons – I had to go on a flurry of trying newfound Linux distributions and it took me weeks to finally found the one!

My first requirement was to have a Linux OS that’s USB friendly that I could carry around in my 32GB pen driver, stick into any USB port I could find anywhere, turn it to my personal puppy and start working away.

I first started with the official Ubuntu for some “personal” reasons, but it was no good. Actually, Ubuntu has got it in for me. So far, I have lost more than 500GB of data, 2 USB drives and other numerously digital causalities to the innocent looking Ubuntu.

once done with that, I moved on to an old version of Ubuntu with gnome and got it boxed in my pen drive. First try, 2nd, 3rd, It seemed good enough at the beginning. Everything was great except the boot time. I had to twiddle my thumbs for about 10 mins every time I wanted to boot into it. No good, right? I had a close experience with kali linux earlier which booted significantly faster than this and so I was wrong to think Ubuntu gnome will have the same boot time.

Moving on further, I began to Google for portable Linux OS and quite unsurprisingly, found loads of them. From puppy Linux to `damn small Linux` (yep, that’s a legit name) there were plenty of them with their own pros and cons.

I went for slax Linux and been with it ever since. Nothing could have been more gratifying!

For starters, Slax Linux only takes  200mb. Yes, that’s right. The whole OS is made up of 200MB and supposed to work from a USB drive, a CD or even a memory card for that matter. other than that, It has a module approach to applications. That said, everything is a module in Slax Linux. there are hundreds of them available on their official site and built-in software store. You can find almost everything in there that you might miss from windows including Chrome, VLC and you name it. Unlike many other linux distributions, it supports mp3, mp4 and flash videos out of box, and it has a boot time of 5 SECONDS.

It took me 2 mins to set everything up and to have its first impression:

snapshot1

awesome right? It uses KDE – a light-weight user interface with plenty of options to make up for its “desktop” counter part found in windows.

I installed chrome and few other utilities and everything was perfect except that there was one little hitch. It didn’t support my native resolution which is 1280×1024 and was stuck on 1024×768. It had its toll, but I eventually found a working solution. Here’s a link to the thread I posted asking for help in their forum (nobody really came though) and later -in a spectacular move – ended up helping my own self and posting a working answer to my own question.

http://old.slax.org/forum.php?action=view&parentID=87838

It took these following commands to get the native resolution:

1: root@slax:~# gtf 1280 1024 60
# 1280x1024 @ 60.00 Hz (GTF) hsync: 63.60 kHz; pclk: 108.88 MHz
Modeline "1280x1024_60.00" 108.88 1280 1360 1496 1712 1024 1025 1028 1060 -HSync +Vsync

2: root@slax:~# xrandr –newmode “1280x1024_60.00” 108.88 1280 1360 1496 1712 1024 1025 1028 1060 -HSync +Vsync

3: root@slax:~# xrandr –addmode VGA1 “1280x1024_60.00”

4: root@slax:~# xrandr –addmode VGA1 “1280x1024_60.00”
output:
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 8192 x 8192
VGA1 connected 1024x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm panning 1024x768+0+0
1024x768 60.0*
800x600 60.3 56.2
848x480 60.0
640x480 59.9
1280x1024_60.00 60.0

simply speaking, you first need to create a new display mode with xrandr and then configure your desired resolution in pixels. Once that’s done, it’s only matter of switching to the newly made mode to get the trick done.

There’s a little catch though. Every time Slax reboots, it refreshes everything in the root folder resetting every system settings including resolution. There’s a way to make these changes stick but that needs mucking with the system guts.

As an alternative, therefore, I wrote a simple bash script comprised of the above commands and automated the whole thing. my script looks like this and fixes the resolution for me just by running it up on every boot up:

snapshot2

and that pretty much sums up my quest storytelling.

Happy linux using!

A Quest: How I Found My Linux Soulmate!

In our contemporary world wide web, once you stick your head out of the comfortable windows homosphere, the first thing that hits you is the astronomically huge number of Linux distributions out there. There is a disparate Linux distribution ( or -err- a whole another window, if you are not a Linux person) for everything. E.g. a different Linux distribution for artists, music enthusiasts, students, industry level giants, giants, kids, dinosaurs, and you name it.

Long story short, if you are looking for a good alternative to windows operating system, it might take you while before you settle down with a Linux distribution that holds answer to your every (computer) needs and problems.

Similarly, once I ditched windows – and for good reasons – I had to go on a flurry of trying new Linux distributions and it took me weeks to finally found the one!

My first requirement was to have a Linux OS that’s USB friendly that I could carry around in my 32GB pen driver, stick into any USB port I could find anywhere, turn it to my personal puppy and start working away.

I first started with the official Ubuntu for some “personal” reasons, but it was no good. Actually, Ubuntu has got it in for me. So far, I have lost more than 500GB of data, 2 USB drives and other numerously digital causalities to the innocent looking Ubuntu.

once done with that, I moved on to an old version of Ubuntu with gnome and got it boxed in my pen drive. First try, 2nd, 3rd, It seemed good enough at the beginning. Everything was great except the boot time. I had to twiddle my thumbs for about 10 mins every time I wanted to boot into it. No good, right? I had a close experience with kali linux earlier which booted significantly faster than this and so I was wrong to think Ubuntu gnome will have the same boot time.

Moving on further, I began to Google for portable Linux OS and quite unsurprisingly, found loads of them. From puppy Linux to `damn small Linux` (yep, that’s a legit name) there were plenty of them with their own pros and cons.

I went for slax Linux and been with it ever since. Nothing could have been more gratifying!

For starters, Slax Linux only takes  200mb. Yes, that’s right. The whole OS is made up of 200MB and supposed to work from a USB drive, a CD or even a memory card for that matter. other than that, It has a module approach to applications. That said, everything is a module in Slax Linux. there are hundreds of them available on their official site and built-in software store. You can find almost everything in there that you might miss from windows including Chrome, VLC and you name it. Unlike many other linux distributions, it supports mp3, mp4 and flash videos out of box, and it has a boot time of 5 SECONDS.

It took me 2 mins to set everything up and to have its first impression:

snapshot1

awesome right? It uses KDE – a light-weight user interface with plenty of options to make up for its “desktop” counter part found in windows.

I installed chrome and few other utilities and everything was perfect except that there was one little hitch. It didn’t support my native resolution which is 1280×1024 and was stuck on 1024×768. It had its toll, but I eventually found a working solution. Here’s a link to the thread I posted asking for help in their forum (nobody really came though) and later -in a spectacular move – ended up helping my own self and posting a working answer to my own question.

http://old.slax.org/forum.php?action=view&parentID=87838

It took these following commands to get the native resolution:

1: root@slax:~# gtf 1280 1024 60
# 1280x1024 @ 60.00 Hz (GTF) hsync: 63.60 kHz; pclk: 108.88 MHz
Modeline "1280x1024_60.00" 108.88 1280 1360 1496 1712 1024 1025 1028 1060 -HSync +Vsync

2: root@slax:~# xrandr –newmode “1280x1024_60.00” 108.88 1280 1360 1496 1712 1024 1025 1028 1060 -HSync +Vsync

3: root@slax:~# xrandr –addmode VGA1 “1280x1024_60.00”

4: root@slax:~# xrandr –addmode VGA1 “1280x1024_60.00”
output:
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 8192 x 8192
VGA1 connected 1024x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm panning 1024x768+0+0
1024x768 60.0*
800x600 60.3 56.2
848x480 60.0
640x480 59.9
1280x1024_60.00 60.0

simply speaking, you first need to create a new display mode with xrandr and then configure your desired resolution in pixels. Once that’s done, it’s only matter of switching to the newly made mode to get the trick done.

There’s a little catch though. Every time Slax reboots, it refreshes everything in the root folder resetting every system settings including resolution. There’s a way to make these changes stick but that needs mucking with the system guts.

As an alternative, therefore, I wrote a simple bash script comprised of the above commands and automated the whole thing. my script looks like this and fixes the resolution for me just by running it up on every boot up:

snapshot2

and that pretty much sums up my quest storytelling.

Happy linux using!

Having Hard Time Lying Out Your Web Layouts?

Hello there, my fellow geeks!

Ever since I finished the set of my first basic algorithms on FCC, I’ve ran out of fresh topics to WordPress anymore. That said, I’m on that stage of learning-to-code where one is supposed to come up with their own web portfolio, which I’m making these days, but it’s taking more time than I had anticipated earlier so there is that. Anyways, since dealing with portfolio needs one to tinker with CSS and my CSS is particularly rusty, I had to go through a few quick refreshers before I went there. During my CSS-Ordeal, however, I stumbled on a few libraries that you must all be familiar with by now. BootStrap and Materialize (ding ding? rings any bell? )

They make layouts as easy as a walk in the park – in addition to a whole another world of HTML/CSS good – thanks to their super flexible 12-grid system. It basically takes care of all types of devices with all kinds of screen sizes with respect to your website with little to no coding, which in return, makes sure you website looks pixel perfect on any device possible. (unless we are talking about your microwave, of course).

However there’s a slight catch. This particular layout system might not come as easy to the beginners as it’s widely adduced to be. In fact, It took me a few dozen days to get to the bottom of it.

I will go into the details of how it really works (the step to step stuff) someday later, but for now check out the link below to a cool codepen that I forked earlier today. It demonstrates the power of 12-grid system and might be just what you need to see before you are convinced that you need to learn this too!

http://codepen.io/pyari/pen/qOqZqv

Challenge: Where Do I belong?

the popular adage – never go with the name of a thing – could not have gotten any more truer. This particularly sad-looking challenge packs enough punch to get all they happy javascript feelings right out of your guts and stomp it all over while you sit in a corner bellowing at the no fairytale ending of your Javascript career.

However, later (to my sheer pleasure) I found that the solution was rather painless if you thought outside the box (or bucket, if that’s where you  prefer to keep all of your javascript eggs) and lucky for us all, I’m here to save you all the pain of going through everything.

quoting the outline, first, as found in FCC

Outline

Return the lowest index at which a value (second argument) should be inserted into a sorted array (first argument).

For example, where([1,2,3,4], 1.5) should return 1 because it is greater than 1 (0th index), but less than 2 (1st index).

Here are some helpful links:

Array.sort()

Solution

the description for this problem is self-explanatory. you need to return the index at which the number(s)   from the second argument  should be added  in the first argument, but here’s the catch: in order to get the right index, you need to make sure that your number(s) is/are added at the right place. in other words, your array must be sorted in an ascending order before you start adding the numbers from your second arguments into it. Now I can think of no more less than 5 solution to this problem (but then again it’s just probably me) but here I will only share the one that’s the most simple and yet the most compact.

One thing more that merits to be mentioned here is that, as far as my earlier post on arr.sort() is concerned, It only sorts the alphabets for you. I didn’t go into the details of how you can get it to sort the numbers as well. nonetheless, It is not that hard to achieve, and only takes a custom function in its body to do the number sorting stuff. Again, for the sake of relevance, I won’t go into its details and directly quote the function below that actually does the number sorting:


function compare (a,b) {

return a - b ;

}

if you need to read up on how the above function works, follow the link to its MDN entry here

Code


function where(arr, num) { 

// pushing numbers (in the second argument) into arr (the first argument)

arr.push(num) ;

//sorting the whole array in an ascending order

arr.sort(function(a,b)

return a - b ;

}) ;

// returning the index of the number recently added

console.log(arr.indexOf(num)) ;

}

// logs 1

where([40, 60], 50, "") ;

// logs 2
where([10, 20, 30, 40, 50], 30);


// logs 0

where([5, 3, 20, 3], 3) ;


// logs 3

where([2, 5, 10], 15);


code in action

Other Possible Solutions

I will go and drop a pair of hints and see if you can work them out for yourself?

  1. you could do it the loopy way. sort the array first and loop through all the elements and return the index of the extra numbers added.
  2. since there is looping involved, you could make use of array.forEach() or arr.filter() or even array.every() and wait did I mention arr.map() ?

PS:

thanks to @Rafase282 and @rahul1992 from the FCC community for lending me their companies, time and wits needed for me to come up with this code.

Challenge: Seek and Destroy

Sorry for such a star war-ish name for the challenge we are up against today. I didn’t come up with it myself, It’s just how it was named on FCC.

the solution of this problem makes heavy use of arguments object so make sure you are comfortable with it before you bring your wits to seek or destroy anything for you. (I certainly don’t want the blood of any innocuous neurons on my conscious.)

Outline

You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.

Here are some helpful links:

Arguments object
Array.filter()

Solution

this problem comes in this format:

destroy([argument 1], [argument 2])

as you might have guessed it, some of the elements in argument 1 are similar to the elements in argument 2. we need to come up with a function that takes both the arguments into account, and removes the twins present in the both arguments.

since there’s going to be filtering involved, you can count on me to use the array.filter() method to get to the end of this problem. Before that, we will need to make sure we have something that has access to all the arguments (both the argument 1, and argument 2), that’s your cue for using arguments object , and since we need to check for duplicates, we will also be using an array method called, arr.indexOf() –  arr.indexOf() checks for the first occurrence of an element in an array and returns its index. If there is no such element present, it returns -1. In other words, -1 indicates that the said element doesn’t exist in the array.

enough with the theory.. let’s get to the battleground !

Code


function destroyer(arr) {

// args = all the arguments in the function from index 1. i.e. (2,3," ")
var args = Array.prototype.slice.call(arguments, 1);

//passes each element  in the array (i.e. 1,2,3,1,2,3) into the indexOf()
return arr.filter(function(e) {

//if an element in args doesn't exist in arr, keep it otherswise filter it out
return args.indexOf(e) === -1
});
}

//returns 1, 1

destroyer([1, 2, 3, 1, 2, 3], 2, 3, "") ;

//returns 1,5,1

destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3) ;

//returns 1

destroyer([3, 5, 1, 2, 2], 2, 3, 5) ;

code in action

Javascript Arguments Object!

There are all kind of arguments in the world; the good ones, the bad ones, the ones I have with mom for every min of my life (and let’s not forget the ones I never lose, while we are at it)… in fact, there is no getting around arguments. Turned out, our lovely JavaScript has its own distinct niche for arguments, more specifically, for arguments object, and they are just wonderful! let me show you how:

javascript: you want an ARGUMENT? let me first get my OBJECTS out of the way

so what’s all this Arguments Object fuss about? in order to understand it, you will first have to make sure that you know the difference between a simple function argument and an argument object that hatches alongside every JavaScript function; yes, my friends, as I learned later after 5 hours of sweating on a single problem, these two are , in fact, two different things and should never be confused for each other.

a simple function argument(s)

there is no rocket science here. every function in  JavaScript can take neither, one or more than one parameters. these parameters are called on by their respective arguments, and these arguments are, what we have been calling simple function arguments . illustration below:


function add (a, b) {

return a + b ;

}

add(6,4);

in the above example, as you can see, our add() function takes two parameters, a and b, and ogles their addition out, but by default, it has no values to store inside a or b. however, when It’s called on with 6 and 4 respectively, we get 10 back. so these two digits (6, 4), in this example are,  simple function arguments.

Arguments Object!

now to the interesting part, when you create a function in Javascript, you are creating way more than that, but since all the action is happening behind the scene, you can’t see anything dancing around. one of these things that are automatically created by JS for you with the birth of every new function includes Arguments Object. in other words, every function has an arguments object built in with it, and it’s an array-like object. what the heck is array-like object, I hear you say? well, array-like objects are something b/w objects and arrays. they look like arrays, but they are not full arrays so none of the array methods (arr.split(), arr.join() remember?) don’t apply on them. you can, of course, convert any array-like object into a fully blown array with the following code, and make use of every array methods on them:

var arguments = Array.prototype.slice.call(arguments) ;

the above line turns the (array-like) argument object into a full array instantly giving you access to all the array methods(), but what exactly does arguments object hold again? well, its name is a dead give-away. it holds all the arguments of a function inside it. that said, if your function has three arguments such as *cats*, *unicorns*, *ducks* the arguments object for this function will have all these 3 values stuffed inside it, which you can call on to (should you need) simply by referring to it inside the function. yes, it pretty much acts like a variable inside the function and has all the values of the function’s arguments inside it, and its scope is limited inside the function so it can’t be called on, used, or accessed outside the function’s body.

Examples:

let’s put our arguments object to a good use. and I’m quoting MDN here, since it has access to all the arguments of a function, we could create a function that concentrates different words with our desired separator.


function concentrate (separator) {

var args = Array.prototype.slice.call(arguments, 1) ; // now args hold all the arguments starting except the very first)

var join = args.join(separator);

alert(join);

}

//results: wow; cool; awesome!!!
concentrate(";", "wow", "coool", "awesome!!!");
//results: name: Mehrosh : loves : javasript
concentrate(":", "name", "Mehrosh", "loves", "Javasript");


see the above code in action

Bonus:

so if we can use arguments object to concentrate random words with our desired separator, could it possibly be used to create automated HTML tags? the ans is, YES! let’s create a function that automates the creation of HTML lists:


function make (type) {
var text = '<' + type + "l><li>"
var args = Array.prototype.slice.call(arguments, 1);
text += args.join("</li>");
text+= "</li>" + "</" + type + "l>";
alert(text);
}
//creates an ordered HTML list
make("o", "uincorns", "fishes", "pokemons") ;

make("u", "uincorns", "fishes", "pokemons") ; // creates an unordered HTML list 

code in action

Final thoughts

so you can see how awesome could arguments object be? we have just created an automated HTML list with what? 5 or so lines? you can create any HTML tag you would want or do much more than that. only the sky is limit here!

array.prototype.sort()

hello guys! long time no code? well, I lost my focus for a while, but then I’m back here so let’s do a quick post here. there is nothing fancy going on here. just  a simple array method() that can do a world of wonders. chances are, if you have just began to learn JS, then,  this might really come in handy.

Definition:

someArray.sort() is an array method and takes one array into an account and sorts its element up using its own dark magic defined somewhere deep in JS. I mean, you don’t really have to do the array’s element sorting as long as you know how to use sort(). you simply need an array and call it on and it will result into sorted element just like that. one thing to note here is that, the way it “sorts” the elements or the logic behind the sorting is not necessarily stable. it’s purely based on the Unicode to code points so you will have to get ready for funny results now and then, but it should work fine for most of the time. again, it sorts both alphabets and digits accordingly.

Syntax:

arr.sort()    ;    //where arr is any given arr you want the sort() to work on

Examples:

let’s whip up a teeny weeny function that takes a string and sort it up for us;


function sorting(text) {

//turning string into array for sort() to do its sortWork on it

var getArray = text.split(" ") ;

// calling sort() on our newly turned getArray[]

var sort = getArray.sort();

//logging the sorted results

console.log(sort);

}

sorting("cat bat apple");   //logs "apple bat cat"
sorting("a g c e d z");    // logs "a c d e g z"
sorting("1 5 7 4  6 5 3"); // logs "1 3 4 5 5 6 7"

Proof:

usually, I provide some kind of link here with my  code in action, but due to the soporific nature of this problem you will have to do that for yourself  since I’m already asleep on my feet and might not be able to even complete my senten

Objects Equilty in JavaScript – your 2 min guide to losing your mind!

Greetings! I wish I could write this out in a more pleasing manner on a less unwelcoming day and having far more time on my hands, but since none of that is going to happen in a long time, I’m going to go ahead and do this real quick. first off, there are few things that I’m going to cram all up in this post, even though I realize that they all deserve their own independent space somewhere on this blog so get ready for a serious JavaScript cocktail up ahead .

Challenge: where art thou

don’t just geteth taken aroint by the nameth of this challengeth high-lone, it’s ev’ry bit exhaust’d  as its nameth suggets (pardon my Shakespearean English). in fact, I’m still recuperating from it and the torture that it unleashed on me.

Outline:

Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching property and value pairs (second argument). Each property and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array.

For example, if the first argument is [{ first: 'Romeo', last: 'Montague' }, { first: 'Mercutio', last: null }, { first: 'Tybalt', last: 'Capulet' }], and the second argument is { last: 'Capulet' }, then you must return the the third object from the array (the first argument), because it contains the property and it’s value, that was passed on as the second argument.

Remember to use Read-Search-Ask if you get stuck. Write your own code.

Challenge: Title Case a string!

this challenge wants us to take a string and return it title-cased . In other words, if you have something like “hello this is me” your function should return “Hello This Is Me” – a title-cased string.

Outline:

Return the provided string with the first letter of each word capitalized.

For the purpose of this exercise, you should also capitalize connecting words like ‘the’ and ‘of’.

Challenge: Check For Palindromes!

hello mortals! (sorry been watching lotsa GOT)

we are I’m back with another challenge. this time, it’s more than head scratching. In fact, I might have scratched half of my hair away if I had not found the solution this soon or If I didn’t have hair in abundance.  Either way lads! we have the solution, but before we go down there let’s get the outline out of our way.

Outline:

Return true if the given string is a palindrome. Otherwise, return false.

A palindrome is a word or sentence that’s spelled the same way both forward and backward, ignoring punctuation, case, and spacing.

You’ll need to remove punctuation and turn everything lower case in order to check for palindromes.

We’ll pass strings with varying formats, such as “racecar”, “RaceCar”, and “race CAR” among others.

Here are some helpful links:

String.replace()
String.toLowerCase()

Solution:

I found this solution particularly uncanny because first, I’m way bigger a noob than I’m comfortable admitting, and secondly, because my knowledge of JS is so limited, there is simply no limit to it. besides, if your brain is anything like mine, it must be like a leaking bucket. anyways, thanks to the “helpful links” I, somehow manged to find a solution (let’s just not talk about the over dozen times when I actually failed while trying to find the solution). it’s devil in the details. To work out this problem, you need to find a way to compare two strings. one is the original string that’s passed to the function and other is the manipulated version of the same string in the reverse order with all the caps and white-spaces gone. after that, all you need is an if-else statement resulting in true if both the strings are exactly equal to each other. otherwise, return false.

how does this manipulation process work again? well, if you can recall my last post, we used three methods namely, string.split() to split each character over into an array, string.reverse() to reverse the order of each character and  string.join() to join them all back into a valid string. we will be using the same three methods with addition to a new one called string.replace(). this little beauty here takes a regex expression and replaces all the matches with whatever you want it to. here we will use it to replace any white-space b/w strings with “” that’s nothing i.e. we will omit all the white spaces so that our palindromes function can work out anything even if it’s a monstrosity like “HelLA YouG etting mE Iam nota palindR ome bUT if IWas Iwould be a PainIn the Class “

code:


function palindrome(str) {
strStrp = str.toLowerCase().replace(/\W/g, ""); //changes the string case and omits any non-alphabate-chars (whitspaces) present in the string
strRev = strStrp.split("").reverse().join("");  // splits strings over, reverses the order and joins everything back to make  a string.
if (strStrp === strRev) {      // do we have an exact match? yes?
console.log(str  + " is a palindrome");  // : )
} else {
console.log(str + " is not a palindrome"); // : (
}
}

palindrome("eye"); //true

palindrome("race car"); //true

palindrome("not a palindrome");  //false

palindrome("A man, a plan, a canal. Panama"); //true

palindrome("never odd or even"); // true

palindrome("nope"); // nope

palindrome("almostomla") // almost true

code in action here