Leetcode.Solved.Two-sum

//https://leetcode.com/problems/two-sum/
public class Solution {
    public class TwoSum
    {
        public int[] TwoSum(int[] nums, int target) {        
            var dict = new Dictionary<int, int>();
            for (int i = 0; i < nums.Length; i++)
            {
                if (dict.ContainsKey(nums[i]))
                    return new int[] { i, dict[nums[i]] };

                int diff = target - nums[i];

                dict.Add(diff, i);
            }

            return null;
        }
    }
}
Posted in Без рубрики | Comments Off on Leetcode.Solved.Two-sum

Leetcode.Solved.Repeated-substring-pattern

//https://leetcode.com/problems/repeated-substring-pattern/
public class Solution {
    public bool RepeatedSubstringPattern(string s) {

            int minSubstrLength = 1;
            int maxSubstrLength = s.Length / 2;
            StringBuilder sb = new StringBuilder();

            for (int i = minSubstrLength; i <= maxSubstrLength; i++)
            {                
                int substrLength = i;
                string substr = s.Substring(0, substrLength);

                int nTimesRepeat = s.Length / substrLength;             

                sb.Clear();
                for (int j = 0; j < nTimesRepeat; j++)                
                  sb.Append(substr);
                                
                if (s.Equals(sb.ToString()))
                    return true;
            }

            return false;
    }
}
Posted in Без рубрики | Comments Off on Leetcode.Solved.Repeated-substring-pattern

Leetcode.Solved.Concatenation-of-array

// https://leetcode.com/problems/concatenation-of-array/
public class Solution {
    public int[] GetConcatenation(int[] nums) {
        int[] res = new int[2 * nums.Length];
        for (int i = 0 ; i < nums.Length; i++) {
          res[i] = nums[i];
          res[i + nums.Length] = nums[i];
        }        

        return res;
    }
}
Posted in Без рубрики | Comments Off on Leetcode.Solved.Concatenation-of-array

Leetcode.Solved. Search-insert-position

// https://leetcode.com/problems/search-insert-position/
public class Solution {
    public int SearchInsert(int[] nums, int target) {
      int l = 0;
      int r = nums.Length - 1;

      while (l <= r) {
        int mid = (l + r) / 2;
        if (target < nums[mid])
          r = mid - 1;
        else if (target > nums[mid])
          l = mid + 1;
        else return mid;    
      }

      return l;        
    }
}
Posted in Без рубрики | Comments Off on Leetcode.Solved. Search-insert-position

WepPackDevServer

Part of webpack. Needed for hot reload, also can serve requested files.

configure in webpack.config

    devServer: {
        port: 3003,
        static: {
            directory: path.join(__dirname, 'out'),
            publicPath: `/path/${APP_VERSION}/`,
        },
    },

Start it like this

npx webpack serve --config webpack.config.ts --mode production

after start it will show smth like

<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:3003/
<i> [webpack-dev-server] On Your Network (IPv4): http://10.6.14.56:3003/
<i> [webpack-dev-server] Content not from webpack is served from 

How to define which files it can serve ?

http://localhost:3003/webpack-dev-server

After showing, click any of them and you will see the adress, so you can pick any of them.

For example you can add this way a source map

http://localhost:3003/path/sourceMaps/js/main.js.map
Posted in Без рубрики | Comments Off on WepPackDevServer

Git. Rev-Parse. Getting latest commit

It helps you to find out the commit ID of the current HEAD (i.e. the current commit you are viewing)

git rev-parse HEAD
OR if you want the shorter commit

git rev-parse --short HEAD
If you want to find the latest commit in another branch, you can do

git rev-parse <local-branch-name>
git rev-parse origin/<remote-branch-name>

Source

Posted in Без рубрики | Comments Off on Git. Rev-Parse. Getting latest commit

Git.Log

git log --oneline

will log commits in one line

Posted in Без рубрики | Comments Off on Git.Log

Git.Revert

git revert [commitHash, HEAD] --no-edit

will add commit to history that will revert commitHash commit

history will not be overwritten

Posted in Без рубрики | Comments Off on Git.Revert

Git. Clean

git clean -f -d

will clean all untracked files and directories

Posted in Без рубрики | Comments Off on Git. Clean

Git. Reset

git reset [--hard, --mixed, --soft] [commitHash, file, HEAD~N]

–hard will erase all

–mixed will move out from index

–soft will be visible only on another commit, and don’t move out from index

Posted in Без рубрики | Comments Off on Git. Reset