Programming Tips πŸ’‘
51.6K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips πŸ’‘
Articles πŸ“•
Resources πŸ‘Ύ
Design Patterns πŸ’Ž
Software Principles βœ…

πŸ‡³πŸ‡± Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
πŸ–Ό 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
Google Material GuideLines for Implementation UI πŸ“–

The Material Design guidelines are a living document of visual, interactive, and motion guidance. πŸ’Ž

https://material.io/guidelines/

#Android #Material
@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
#Fun Is That integer or... !! πŸ€”
@ProgrammingTip
Value Types in the Real World 🌍

Suppose you’re reading something fantastic, and you want a friend to read it too. πŸ“œ

What do you need to give your friend so that he can read it too❓

To give your friend a copy, you’d need to photocopy all the pages and then give it to him, At that point, he has his own complete copy of the document. πŸ“ƒ

In this situation, you’re dealing with value type behavior❗️

All the information is directly in your hands, you don’t need to go anywhere else to get it.

Your copy of the information is also independent of your friend’s after you’ve made the copy. πŸ‘₯

You could add some notes to your pages, and his pages wouldn’t be changed at all.πŸ™…πŸ»β€β™‚οΈ

γ€°γ€°γ€°γ€°γ€°γ€°
#Types #ValueTypes
@ProgrammingTip
Reference Types in the Real World 🌍

Compare that with the situation where you’re reading a web page. 🌐

This time, all you have to give your friend is the URL of the web page. ↗️

This is reference type behavior, with the URL taking the place of the reference. ↔️

In order to read the document, you have to navigate the reference by putting the URL in your browser and asking it to load the page. ☝🏻

If the web page changes for some reason, both you and your friend will see that change the next time each of you loads the page. πŸ™‡πŸ»

γ€°γ€°γ€°γ€°γ€°γ€°
#Types #ReferenceTypes
@ProgrammingTip