Programming Tips 💡 – Telegram
Programming Tips 💡
51.6K subscribers
67 photos
10 videos
30 files
355 links
Programming & AI:
Tips 💡
Articles 📕
Resources 👾
Design Patterns 💎
Software Principles

🇳🇱 Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
JavaScript Clean Code 🛠

Use explanatory variables 💡

Bad :
const address = 'One Infinite Loop, Cupertino 95014';

const cityZipCodeRegex = /^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/;

saveCityZipCode(address.match(cityZipCodeRegex)[1], address.match(cityZipCodeRegex)[2]);


Good :
const address = 'One Infinite Loop, Cupertino 95014';

const cityZipCodeRegex = /^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/;

const [, city, zipCode] = address.match(cityZipCodeRegex) || [];

saveCityZipCode(city, zipCode);



#JSTips #CleanCode
@ProgrammingTip
JavaScript Clean Code 🛠

We will read more code than we will ever write. It's important that the code we do write is readable and searchable.💡

Bad :
// What the heck is 86400000 for?
setTimeout(blastOff, 86400000);


Good :
// Declare them as capitalized `const` globals.
const MILLISECONDS_IN_A_DAY = 86400000;

setTimeout(blastOff, MILLISECONDS_IN_A_DAY);



#JSTips #CleanCode
@ProgrammingTip
JavaScript Clean Code 🛠

Don't add unneeded context 💡
If your class/object name tells you something, don't repeat that in your variable name.

Bad :
const Car = {
carMake: 'Honda',
carModel: 'Accord',
carColor: 'Blue'
};

function paintCar(car) {
car.carColor = 'Red';
}


Good :
const Car = {
make: 'Honda',
model: 'Accord',
color: 'Blue'
};

function paintCar(car) {
car.color = 'Red';
}



#JSTips #CleanCode
@ProgrammingTip
🖼 Rescale Image In Java 🖼

An image can rescaled using AffineTransform. First of all, Image Buffer of input image is created and then scaled image is rendered. ✔️

BufferedImage imgSource = 
ImageIO.read(new File("myImage.jpg"));

BufferedImage imgDest =
new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);

Graphics2D g2d = imgDest.createGraphics();

AffineTransform affinetransformation =
AffineTransform.getScaleInstance(2, 2);

g2d.drawRenderedImage(imgSource,
affinetransformation);

ImageIO.write(imgDest, "JPG",
new File("outImage.jpg"));


#java #image
@ProgrammingTip
JavaScript Clean Code 🛠

Functions should do one thing 💡

Bad :
function emailClients(clients) {
clients.forEach((client) => {
const clientRecord = database.lookup(client);
if (clientRecord.isActive()) {
email(client);
}
});
}


Good :
function emailActiveClients(clients) {
clients
.filter(isActiveClient)
.forEach(email);
}

function isActiveClient(client) {
const clientRecord = database.lookup(client);
return clientRecord.isActive();
}



#JSTips #CleanCode
@ProgrammingTip
Media is too big
VIEW IN TELEGRAM
C# Events & Delegates ⚜️

Instructor : Mosh Hamedani 🎥

#CSharp #Events #Delegates
@ProgrammingTip
📦 Macro To Get Array Size Of Any Data Type In C 📦

The following macro will help you in getting the size of an array of any data type. It works by dividing the length of the array to the size of its field. 💡

Code:
#define num(x) (sizeof (x) / sizeof (*x)) 

int _tmain() {
int numbers[10] =
{1,1,1,1,1,1};

char *chars[20] =
{"","","","","","","","",""};

printf("Size of numbers[10] is %d\n",
num(numbers));

printf("Size of chars[20] is %d\n",
num(chars));
}



Output:
  Size of numbers[10] is 10 

  Size of chars[20] is 20  

  Press any key to continue . . .


#c #cpp #array
@ProgrammingTip
JavaScript Clean Code 🛠

Don't use flags as function parameters 💡

Bad :
function createFile(name, temp) {
if (temp) {
fs.create(`./temp/${name}`);
} else {
fs.create(name);
}
}


Good :
function createFile(name) {
fs.create(name);
}

function createTempFile(name) {
createFile(`./temp/${name}`);
}



#JSTips #CleanCode
@ProgrammingTip
Axios 👾

Promise based HTTP client for the browser and node.js .

Features :
🔸Make XMLHttpRequests from the browser
🔹Make http requests from node.js
🔸Supports the Promise API
🔹Intercept request and response
🔸Transform request and response data
🔹Cancel requests
🔸Automatic transforms for JSON data
🔹Client side support for protecting against XSRF

https://github.com/mzabriskie/axios

Use it instead of old AJAX, it's very simple & handy 🔥

#JavaScript #Ajax
@ProgrammingTip
#Fun He'll Punish Them!
@ProgrammingTip
Online VS Code IDE for Angular & React & Ionic 💎

Features :
🔸Intellisense, Project Search, Go to Definitions.
🔹Hot reloading as you type.
🔸Import NPM packages into your project.
🔹Keep editing while offline
🔸Hosted app URL where you can see (or share) your live application at any time.

https://stackblitz.com/

Try it, it's awesome 😍

#Angular #React #Ionic
@ProgrammingTip
Apress Pro ASP.NET SignalR.pdf
7.8 MB
Apress Pro ASP.NET SignalR 📘
Author : Keyvan Nayyeri 🖊

#Book #aspnet #Signalr
@ProgrammingTip
JavaScript Clean Code 🛠

Avoid negative conditionals 💡

Bad :
function isDOMNodeNotPresent(node) {
// ...
}

if (!isDOMNodeNotPresent(node)) {
// ...
}


Good :
function isDOMNodePresent(node) {
// ...
}

if (isDOMNodePresent(node)) {
// ...
}



#JSTips #CleanCode
@ProgrammingTip
Async & Await in JavaScript 🔥

Async/Await will make your code simpler even more than you think.

Stop writing callback functions and love JavaScript ES7. 💎

https://blog.patricktriest.com/what-is-async-await-why-should-you-care/

#JavaScript #CleanCode
@ProgrammingTip
Announcing .NET Core 2.0 🔥

.NET Core 2.0 is available today as a final release. 📦

You can start developing with it at the command line, in your favorite text editor, in Visual Studio 2017 15.3, Visual Studio Code or Visual Studio for Mac.

It is ready for production workloads, on your own hardware or your favorite cloud, like Microsoft Azure.

Microsoft also released ASP.NET Core 2.0 and Entity Framework Core 2.0 💎

https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-net-core-2-0/

Download SDK :
https://www.microsoft.com/net/download/core


#DotNet #ASPNET #Core
@ProgrammingTip
📦 Grab The Stack Trace Of An Exception 📦

Checking your code for errors is one of the most Painstaking – and frustrating – parts of the development process. 🙆🏻‍♂️

It’s also horrendously Time-Consuming, particularly if you’ve a pesky error whose source isn’t immediately clear. 💡

Using this code, you can more easily track down where an Exception is occurring – and bring yourself that much closer to being rid of it.

Code
Exception e = …;
java.io.StringWriter sw = new java.io.StringWriter();
e.printStackTrace(new java.io.PrintWriter(sw));
String trace = sw.getBuffer().toString();


#java #exception #error #trick
@ProgrammingTip
Use String.valueOf() instead of toString() 💎

If obj needs to be converted to string then the result of obj.toString() and String.valueOf(obj) will be same.

But String.valueOf() is Null Safe, means it will never throw NullPointerException. 🎯

Test test = null;

// Below statement will not throw NPE
System.out.println(String.valueOf(test));

// Next statement will throw NPE
System.out.println(test.toString())


#java #string
@ProgrammingTip
JavaScript Clean Code 🛠

Use getters and setters 💡

Bad :
function makeBankAccount() {

return {
balance: 0,
// ...
};
}

const account = makeBankAccount();
account.balance = 100;


Good :
function makeBankAccount() {
let balance = 0;

function getBalance() {
return balance;
}

function setBalance(amount) {
balance = amount;
}

return {
getBalance,
setBalance,
};
}

const account = makeBankAccount();
account.setBalance(100);



#JSTips #CleanCode
@ProgrammingTip