Counter For Tracking Tickets Using Python

Daily post #13 – I just created a counter using python to track the number of support tickets I do for my company.

This will help me to see a final count by the end of the day. It’ll also show me a timestamp to see when the count was incremented. Here’s the script:

And this is what it it looks like in the output –

I’ve also added a command for exit to end the program. Overall, it’s nothing fancy! But it’s definitely something that’ll help me with my job 🙂

Note: I’m going to Dubai tomorrow for vacation, so I’ll be taking this week off. I will resume my daily posts from 4th of December! 🙂

How To Auto-indent Code In Sublime Text 3?

Daily post #12 – Today’s post is a simple one but again it’s something which will save you plenty of time. How do you auto-indent code in Sublime Text 3?

Method #1 – You just press command+shift+p and type in reindent. This will give a list of results. Just hit enter as you want to select the first option in there. And that’ll add the correct indentation to your code.

Method #2 – You assign a shortcut to method #1 to cut down the whole process to a single step. For this, you’ll need to add the following code to your key binding in Sublime:

{"keys": ["alt+shift+f"], "command": "reindent", "args": {"single_line": false}}

I use command instead of alt, but it’s totally up to you! I learned these two tips from this StackOverflow page.

That’s all for this post, I hope you find this useful 🙂

Script To Generate Random Hex Color Code

Daily post #11 – I just wrote a piece of code to generate a random hex color code. Here’s what it looks like:

Explanation:

  • Create a box and a button
  • Select those using JS
  • Add event listener to the button
  • Connect it with updateButton function
  • This function will generate hex code and insert it inside the box.

My logic was to generate a random number from 0 to 9.

Clearing DNS Cache In Chrome

Daily post #10 – Sometimes a website will stop loading on your computer but it’ll continue to load on other devices. In this case, you may try clearing your DNS cache and that might do the job!

If you’re running Google Chrome, just type the following in your address bar and hit clear host cache button in there.

chrome://net-internals/#dns

This should clear your DNS and allow you to access all the sites again 🙂

What Is $0 In Google Chrome Developer Tools?

Daily post #9 – If you right click on this page and click inspect element, you’ll notice a $0 symbol next to the element which is currently selected. Here’s a screenshot for reference –

So what is it and what it really does? I haven’t explored it enough but based on what I learned it helps us as a reference point. To understand what this means, you have to click on the console tab in developer tools (or simply press CMD+OPT+J on Mac).

Once you’re in the browser/javascript console, type in $0 and hit enter. This is what you’ll see –

That’s pretty much what it does! (afaik at this point) 🙂

Selecting Random Value From An Array Using JavaScript

Daily post #8 – In this post, I’ll be sharing a simple trick to select or print a random value from a given array. Here’s the code for it:

function randomValueFromArray(array){
  var random = Math.floor(Math.random()*array.length);
  return array[random];
}

My favorite part of this code is the math on the second line – multiplying a random number with the length of the array. This is genius! I’ll explain why –

Math.random function generates a number between 0 and 1 (but never 1). If you multiply such a number with any given number X, the result will never be greater than X. And thus you will never run into an ArrayIndexOutOfBounds error 🙂

Learning JavaScript Using Console

Daily post #7 – I missed writing a post yesterday so I’m going to write two posts today. This one is about using your Google Chrome console to learn JavaScript. Let’s dive into this directly!

First open your Google Chrome console by going to menu bar > view > developer > JavaScript console. Or you can use CMD+OPT+J (because I like keyboard shortcuts).

Once in Console, you can type in any JS code and it’ll execute right there and give you the result at the same time. For example, type in the following code:

 
a = 5
b = 6
a
b

This will print the values of a and b on screen. You can also write multiline code using shift+enter or just by copy pasting code in there. For example:

for (i=0; i<10; i++)
console.log(i)

This will print out numbers from 0 to 9. The best part about this process is you can do this inside your browser while watching a tutorial on YouTube!

That’s all in this post. Going to write another post now! 🙂