Community driven, articles, resources, guides, interview questions, quizzes for DevOps. Learn to become a modern DevOps engineer by following the steps, skills, resources and guides listed in this roadmap.
— Read on roadmap.sh/devops
Category Archives: Programming
Ultra light dev setup
Simplification of dev setup:
- VPS
- Docker
- vim/neovim
- iPad Pro 11 + Keyboard
- Blink shell
Apps to develop
- web apps
- apis
- text generator using ai
- number crunching/data science python/R
- blogs
- command line games and apps
- php/js/go/python/ruby/c/c++
git error: github.com:abc/xyz.git did not send all necessary objects
I was getting following error when running git pull
git pull
fatal: bad object refs/heads/master 2
error: github.com:abc/xyz.git did not send all necessary objects
I tried running git gc
git gc
error: bad ref for .git/logs/HEAD 2
fatal: bad object refs/heads/master 2
fatal: failed to run repack
The fix was to remove above to files under .git
rm .git/logs/HEAD\ 2
rm .git/refs/heads/master\ 2
After that I was able to run gc
and do git pull
git gc
Enumerating objects: 257, done.
Counting objects: 100% (257/257), done.
Delta compression using up to 4 threads
Compressing objects: 100% (224/224), done.
Writing objects: 100% (257/257), done.
Total 257 (delta 85), reused 0 (delta 0), pack-reused 0
LeetCode 1089: Duplicate Zeros
LeetCode 1089: Duplicate Zeros solution in PHP.
class Solution {
/**
* @param Integer[] $arr
* @return NULL
*/
function duplicateZeros(&$arr) {
$len = count($arr);
for ($i=0; $i < $len; $i++) {
if (0 === $arr[$i]) {
array_splice($arr, $i++, 0, 0);
}
}
array_splice($arr, $len);
}
}
LeetCode 11. Container With Most Water
Here is my solution to Container with Most Water in JavaScript.
/**
* @param {number[]} height
* @return {number}
*/
var maxArea = function(height) {
let left = 0;
let right = height.length-1;
let maxWater = 0;
while (left < right) {
const water = (right-left) * Math.min(height[left], height[right]);
if (water > maxWater) {
maxWater = water;
}
if (height[left] < height[right]) {
left++;
} else {
right--;
}
}
return maxWater;
};
LeetCode 1: Two Sum
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
const numsToFind = {};
for (let i=0; i<nums.length; i++) {
const numToFind = nums[i];
if (numsToFind[numToFind] >= 0) {
return [i, numsToFind[numToFind]];
}
numsToFind[target - numToFind] = i;
}
};
My solution for Two Sum problem in PHP.
LeetCode 88: Merge Sorted Array solution
Here is my solution for Merge Sorted Array problem in PHP. This is not the most efficient solution.
class Solution {
/**
* @param Integer[] $nums1
* @param Integer $m
* @param Integer[] $nums2
* @param Integer $n
* @return NULL
*/
function merge(&$nums1, $m, $nums2, $n) {
if ($n == 0) {
return;
}
if ($m == 0) {
for ($i=0; $i<$n; $i++) {
$nums1[$i] = $nums2[$i];
}
}
$i = 0;
$j = 0;
while ($i<$m && $j<$n) {
if ($nums1[$i]<=$nums2[$j]) {
$i++;
} else {
$this->array_insert($nums1, $i++, $nums2[$j]);
$m++;
$j++;
}
}
while ($j < $n) {
$nums1[$i++] = $nums2[$j++];
}
}
function array_insert(&$arr, $i, $num) {
$endArr = array_slice($arr, $i);
//print_r($endArr);
$arr[$i] = $num;
for ($x=$i+1; $x<count($arr); $x++) {
//print_r($arr);
$arr[$x] = array_shift($endArr);
}
}
}
LeetCode 26 – Remove Duplicates from Sorted Array
Here is my solution to Remove Duplicates from Sorted Array problem in JavaScript
/**
* @param {number[]} nums
* @return {number}
*/
var removeDuplicates = function(nums) {
let i=0;
while (i<nums.length-1) {
if (nums[i] === nums[i+1]) {
nums.splice(i+1, 1);
} else {
i++;
}
}
return nums.length;
};
Results
Runtime: 108 ms, faster than 33.69% of JavaScript online submissions for Remove Duplicates from Sorted Array.Memory
Usage: 40.6 MB, less than 89.66% of JavaScript online submissions for Remove Duplicates from Sorted Array.
LeetCode #73: Set Matrix Zeroes
Here is my solution to Set Matrix Zeros problem in PHP:
class Solution {
/**
* @param Integer[][] $matrix
* @return NULL
*/
function setZeroes(&$matrix) {
$rowsToZeroOut = [];
$colsToZeroOut = [];
for ($i=0; $i<count($matrix); $i++) {
for ($j=0; $j<count($matrix[$i]); $j++) {
if ($matrix[$i][$j] === 0) {
$rowsToZeroOut[] = $i;
$colsToZeroOut[] = $j;
}
}
}
foreach($rowsToZeroOut as $r) {
for($i=0; $i<count($matrix[$r]); $i++) {
$matrix[$r][$i] = 0;
}
}
foreach($colsToZeroOut as $c) {
for($i=0; $i<count($matrix); $i++) {
$matrix[$i][$c] = 0;
}
}
}
}
Results
Runtime: 52 ms, faster than 13.33% of PHP online submissions for Set Matrix Zeroes. Memory Usage: 19.8 MB, less than 80.00% of PHP online submissions for Set Matrix Zeroes.
Git Simplified
One of most common technology that new professional developers struggle with is git
.
Many junior developers are eager to start using all of the powerful commands of git
and usually end up getting more confused.
Here are a few commands that I recommend to anyone learning git
for the first time:
clone
This downloads entire git repo from a remote server, usually. You will get all revision history and branches.
init
This initialize new empty git repo in current directory. As a junior developer you are unlikely to do this. Most likely you will be cloning an existing project.
Another caveat here is that when you initialize a git repo, you will need to set remote destination to push your code changes. But let’s not worry about it yet.
checkout
Once you have cloned a repo on your machine, you can checkout a specific branch. By default when you clone, master branch is checked out. Most likely you will be working in some other branch. So you will check it out by typing git checkout branch-name
pull
This command pulls changes from remote server into your local copy of repo. If you are working a branch that another developer created then that developer needs to push that branch to remote server, then you can pull it. And finally you can check it out. I see many junior developers not pulling before checking out a new branch.
commit
This is simple make your changes and commit your code to repo. When you issue this command, your changes are stored in your local copy of repo. You will need to issue push
command before your changes are pushed to remote server and only then other developers can pull your changes.
push
This pushes your local repo with all local to changes to remote server.
Many times you will need to merge changes from remote in your local repo before you can push.
merge
This is where things get a bit confusing new developers. There are likely 3 different cases when you merging:
2 or more developers are working on same branch
This is simplest case. You can simply issue git pull
command and it will fetch and merge remote changes. Now this can result in conflicts, which will need to be resolved manually. I will talk about conflicts later.
New release went out
It is recommend to merge master (or default) branch into your branch often especially right after any major release. This avoids any conflicts later during Continuous Integration pipeline.
You need a feature from another branch
This is probably the worst scenario to deal with because now your branch is dependent on another branch. I prefer to avoid this scenario unless the feature is in master. The reason for avoiding this scenario are two folds, first code reviews get hard as it is hard to tell what was changed in your branch and what was pulled in from the other branch. And then many times my code got delayed because I was waiting on other branch.
You may have to issue pull command before merging
git pull
git merge other-branch my-branch
Tools of Trade
I use 13-inch MacBookPro for personal projects and 15-inch for work. My personal MBP would be last traditional laptop, hopefully. Since most of my work can easily be done on Linux VPS. I have been using 10.5-inch iPad Pro with Blink shell for most my side projects. I like the form factor of iPad Pro and I am getting better at Linux administration. Now I am also setting up Docker images so I can bring up new images as needed.
Though I might still need personal computer mostly for photos and videos but I might as well buy a desktop next time. I can build a powerful video editing station for fraction half or less than what a decent MacBookPro would cost.
MacOS Tools
Brew.sh
This makes installing various software dev tools super easy.
VS Code
I was a big fan of Sublime Text and PHPstorm but VS Code finally won me over. PHPStorm is still better for PHP work but VS Code lighter and faster to open, so I end up opening it more often than PHPStorm.
Docker
I am getting into DevOps and spinning up new VPSs as needed, Docker is pretty much default choice for this.
iaWriter
This is my favorite writing software. I am using this for writing and pretty much all my blog posts.
iOS Tools
Blink Shell
This is the best terminal software I have used. It is free and Open Source too. This is all you need to use iPad for development of most web apps and machine learning.
iaWriter
iOS version on iPad Pro is perfect. A lot of my blog posts are written in Starbuck on iPad.
WorkingCopy
It is a git client. In theory, I didn’t need it when you got shell access to a Linux machine. But vim is great for writing code but not so much when writing blogs.
So I use WorkingCopy to clone my blog on iPad, add new posts with iaWriter, and then again use WorkingCopy to commit and push my posts. I use Netlify for hosting this blog, so as soon as I push new posts, Netlify will publish it here.
Linux Tools
I have been using Ubuntu as my main flavor of Linux. The list of tools that I use on Linux is long but here are some:
- Nginx
- PHP
- Python
- Conda
- Nodejs
- npm
- git
- composer
- MariaDB
- vim
ReflectionException: Class Tests\Unit\Symfony\Component\HttpKernel\Exception\NotFoundHttpException does not exist
Running unit tests in Laravel, I was getting this error:
ReflectionException: Class Tests\Unit\Symfony\Component\HttpKernel\Exception\NotFoundHttpException does not exist
The issue was missing root backslash, make sure you have expected exception like:
$this->expectException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class);