Azlyrics

My personal mod for a full-screen non-scrollable AzLyrics page:

javascript: (function() {
    var h = document.getElementsByTagName('head')[0],
        s = document.createElement('style');
    s.setAttribute('type', 'text/css');
    s.appendChild(document.createTextNode('.main-page {margin:0 auto; padding: 0; width:100%}.row{margin: 0 auto}col-xs-12 col-lg-8 text-center{padding:0} body > div.container.main-page > div > div.col-xs-12.col-lg-8.text-center > div:nth-child(8){column-count: 3;line-height: 18px;height: 430px;font-size: 18px;}'));
    h.appendChild(s);
})()
Standard

Dark-mode any website

Just add this to your favorites bar and click it whenever you feel like getting back in black 😉

javascript: (function() {
    var h = document.getElementsByTagName('head')[0],
        s = document.createElement('style');
    s.setAttribute('type', 'text/css');
    s.appendChild(document.createTextNode('html{-webkit-filter:invert(100%) hue-rotate(180deg) contrast(70%) !important; background: #000;} .line-content {background-color: #fefefe;}'));
    h.appendChild(s);
})()
Standard

7 Tough Truths About The Programming Career

Programming is the sort of career that if you don’t do it right, you gonna mess yourself up pretty badly.

This is a long-term game. You need to craft the right habits that will mold you everyday into following the right path.

1. Programming is a physically demanding activity. Good exercise and good sleep are essential for any programmer. Sit with your back straight. Take a break every 30 minutes. Drink lots of liquids. Take walks and get exposed to sunshine. You have to protect your body from getting deteriorated and destroyed into the shape of a chair.

2. Adopt a get-it-done attitude. Get things out the door. Get your eye on the go and than reverse engineer it. Don’t keep working on some strange small stupid little bug or problem for hours and hours trying to solve some puzzle you created in your head. Don’t over-romanticize the technology. Don’t keep working on something that never really ships. Be result-oriented.

3. Keep it simple and consistent. Don’t over-engineer your code. Don’t try to show-off how smart you are. That works against you.

4. Allow yourself to get in the “zone”. Have long stretches of time without interruption. 3 to 4 hours of specific undisturbed time to be productive. Build large abstractions and metal blocks in your head.

5. Always be learning. Sharpen yourself. Don’t get stuck in a certain routine. Be able to debug. Be able to learn a new environment, understand how the system was put together and diagnose it.

6. Collaboration. Don’t try to be that lone hacker. Don’t stay stuck on something without reaching for help. Programming is very much a team sport. You’re a team player in the digital domain.

7. Programming is a lonely activity. Probably one of the loneliest careers. Get used to be spending lots of time in your own. Lots of times in the digital world. It’s not a social job.

Standard

Codility – Demo Tast – MissingInteger

Task description

Write a function:

class Solution { public int solution(int[] A); }

that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.

For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.

Given A = [1, 2, 3], the function should return 4.

Given A = [−1, −3], the function should return 1.

Write an efficient algorithm for the following assumptions:

  • N is an integer within the range [1..100,000];
  • each element of array A is an integer within the range [−1,000,000..1,000,000].

Solution in C#:

using System;
using System.Collections.Generic;
using System.Linq;

class Solution {
    public int solution(int[] A) {

        var result = -1;        
        A = A.OrderBy(x => x).ToArray();
        
        var max = A.Max();
        var min = A.Min();
        
        if (min > 1) return 1;
        if (A.Length == 2 &amp;&amp; min < 0 &amp;&amp; max &gt; 1) return 1;
        
        for (int i = 0; i < A.Length-1;  i++) {
            if (A[i] < 0) continue;
            if (A[i+1]-A[i] &gt; 1){
                result = A[i]+1;
                break;
            }
        }
        
        if (result == -1)
            if (max <= 0) result = 1;
            else if(min &gt; 1) result = 1;
            else result = max+1;

        return result;
    }
}

Standard

Codility – Lesson 2 – Arrays – Task 2 – CyclicRotation

Task description:

An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place).

The goal is to rotate array A K times; that is, each element of A will be shifted to the right K times.

Write a function:

class Solution { public int[] solution(int[] A, int K); }

that, given an array A consisting of N integers and an integer K, returns the array A rotated K times.

For example, given A = [3, 8, 9, 7, 6] K = 3

the function should return [9, 7, 6, 3, 8]. Three rotations were made: [3, 8, 9, 7, 6] -> [6, 3, 8, 9, 7] [6, 3, 8, 9, 7] -> [7, 6, 3, 8, 9] [7, 6, 3, 8, 9] -> [9, 7, 6, 3, 8]

For another example, given A = [0, 0, 0] K = 1

the function should return [0, 0, 0]

Given A = [1, 2, 3, 4] K = 4

the function should return [1, 2, 3, 4]

Assume that:

  • N and K are integers within the range [0..100];
  • each element of array A is an integer within the range [−1,000..1,000].

In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.

Solution in C#:

using System;
using System.Linq;
using System.Collections.Generic;
 
class Solution {
    public int[] solution(int[] A, int K) {
 
        var array = A;
        var count = K;
     
        if (array.Length <= 0) return array;
        if (count <= 0) return array;
 
        count %= array.Length;
        int[] result = new int[array.Length];
        Array.Copy(array, array.Length - count, result, 0, count);
        Array.Copy(array, 0, result, count, array.Length - count);
        return result;
    }
}
Standard

Codility – Lesson 2 – Arrays – Task 1 – OddOccurrencesInArray

Task description

A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired.

For example, in array A such that: A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9

  • the elements at indexes 0 and 2 have value 9,
  • the elements at indexes 1 and 3 have value 3,
  • the elements at indexes 4 and 6 have value 9,
  • the element at index 5 has value 7 and is unpaired.

Write a function:

class Solution { public int solution(int[] A); }

that, given an array A consisting of N integers fulfilling the above conditions, returns the value of the unpaired element.

For example, given array A such that: A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9

the function should return 7, as explained in the example above.

Write an efficient algorithm for the following assumptions:

  • N is an odd integer within the range [1..1,000,000];
  • each element of array A is an integer within the range [1..1,000,000,000];
  • all but one of the values in A occur an even number of times.

Solution in C#:

using System;
using System.Linq;
using System.Collections.Generic;

class Solution {
    public int solution(int[] A) {
        
        List<int&gt; lst = A.OfType<int&gt;().ToList();
        
        lst = lst
        .GroupBy(n =&gt; n)
        .Where(g =&gt; g.Count() == 1)
        .Select(g =&gt; g.Key).ToList();
        
        var result = lst.Distinct().FirstOrDefault();
        
        return result;
    }
}
Standard