What Awesome Tricks Do You Know? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 36

What Awesome Tricks Do You Know?

Do you know any awesome trick to share with the community? Useless tricks and hacks are accepted too. Please exemplify the trick with a code. All languages are welcome.

22nd Oct 2017, 10:07 PM
Luis Lopes
Luis Lopes - avatar
63 Answers
+ 77
Ctrl+C Ctrl+V Really useful in school.
23rd Oct 2017, 9:55 AM
Corey
Corey - avatar
+ 31
@kautlin //๐Ÿ˜‚๐Ÿ˜‚
24th Oct 2017, 7:09 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 30
Ternary operators are pretty cool. It is like an if-then statement, except they are used on a single line, and work almost like a method call, as they give a value that can then be used, say, in a mathematical expression, or String concatenation. Ternary operators' syntax are as follows: (<boolean expression>)? <the value, if true> : <the value, if false> The boolean expression is what you are comparing between / expressing to determine the outcome. This can be written the same way as you might find them in an if-then statement. The question mark indicates it is a "question", so to speak, with "answers" that follow. The true value is the value given should the boolean expression yield true. The colon separates the true and false values. The false value is the value given should the boolean expression yield false. Ternary operators can be used in just about every expression, and can be used the same way as if-then statements can. Just, bear in mind, unless the result is a method call, ternary operator results in no additional code being run; only a value is given.
22nd Oct 2017, 10:16 PM
Quantallax
+ 26
Ways to download YouTube videos without any software: 1. Typeย vdย in the address bar, just beforeย youtube.com.ย Click the cursor right before the "youtube.com" portion of the video's URL in your browser's address opt and addย vd. For example,ย https://m.youtube.com/watch?v=hP94msJndyE&feature=youtu.beย would becomeย https://m.vdyoutube.com/watch?v=hP94msJndyE&feature=youtu.be 2. similarly adding ss before y https://m.youtube.com/watch?v=hP94msJndyE&feature=youtu.be will become https://m.ssyoutube.com/watch?v=hP94msJndyE&feature=youtu.be
24th Oct 2017, 1:00 PM
Gaurav Adhikari
Gaurav Adhikari - avatar
+ 23
You can use generators instead of for loops. For example, [print(i) for i in range(0,37)] instead if for i in range(0,37): print(i)
23rd Oct 2017, 12:46 AM
๐Ÿ‘‘ Prometheus ๐Ÿ‡ธ๐Ÿ‡ฌ
๐Ÿ‘‘ Prometheus ๐Ÿ‡ธ๐Ÿ‡ฌ - avatar
+ 19
Like HashMaps, or ArrayLists? They can both be pretty useful. Am ArrayList is relatively simple; it is an array, for the most part, but it can change in size, as compared to actual arrays. If you add on an element, the ArrayList expands in size to accommodate the new element. If you take one out, it shrinks. If you want to know the implementation and/or syntax of using them, please ask, and I'll write down an explanation. HashMaps are sets of key-value pairs. Rather than being an ordered set of values, each value corresponds to a key. When you call on a value, you call on it by its key. The common example of a HashMap is a dictionary. When you are looking for the definition of the word "Apple", say, you don't ask for, say, the 54th definition in the book; you go to the definition of "Apple". HashMaps work more or less in this manner. If you would like me to provide a deeper explanation, or syntax or implementation, just ask. I hope this helps.
22nd Oct 2017, 10:58 PM
Quantallax
+ 17
I can't believe that I can unlock "Top Answer" badge here, to thanks for all upvotes, I want to share one awesome trick in my opinion. This is something you use everyday, every moment when you encounter problems at anytime, anywhere, but most people do not realize that is very important. In computer science, there are tooooooooo many knowledges we should learn, but we can't master or remember all skills, so we use "Google Search" everyday for a variety of reasons, and we can always find out the answer across the internet, especially in programming. But, how much time do you usually spend on "Searching" ? This is a critical issue, I means use Google Search efficiently is important, use less time to find out relevant information and get the best answer is good for you. So I want to share the document about the tips of Google Search, hope it will help you. Common search techniques: https://support.google.com/websearch/answer/2466433
27th Oct 2017, 12:35 PM
Corey
Corey - avatar
+ 15
Also, if it helps, for those looking to make their code more efficient, let me try to explain methods: A method is a named block of code, that, upon being called, asks for certain parameters, and returns a given value. Methods can do anything you want them to, and they exist as a convenient way of preventing duplicate code and performing operations. How do you make a method? A method follows the following skeleton; <access modifiers> <object-based or static> <return type> nameOfMethod(parameters){ //code } The access modifiers determine who / what can access the method. If the method is object-based, it must be called from an object (i.e. "new Cat().meow();"). Otherwise, it may simply be called from the class (i.e. "Math.pow(2, 3);", where "Math" is a class). The return type determine what you get from calling the method (i.e. "... int plusFive(..." would return an integer type). An important side note is that "void" return types do not actually return anything. The name is simply what you call the method by (In "Math.pow(2, 3);", the method "pow" is being called). The parameters are variables passed in when the method is called, used however the method is programmed to use them (in the case of "Math.pow", the first double is the base, and the second double is the power to which the base is raised). Everything within the curly brackets is the implementation of the code, and is what is run when the method is called.
22nd Oct 2017, 10:33 PM
Quantallax
+ 15
If it helps, there is also a way to not have to constantly write "System.out" when printing to the terminal. If you have the line of code: "import static java.lang.System.out;" Instead of having to write "System.out", all you have to write is "out". This can speed up typing (not by much, though), and, in theory, shorten the amount of memory used in storing the code.
22nd Oct 2017, 11:14 PM
Quantallax
+ 12
Another thing that you might find interesting; If you have a loop or if-then statement with only one line of code being run within its body, you do not need curly brackets (in Java, at least). The compiler will understand that the line of code directly following the loop / if-then statement is the code to be run should no curly brackets exist. This is useful if you are, for example, trying to count the number of "1"s in an integer array: int[] a = {1,2,3,1,5,6,1,8}; int numOnes = 0; //If you don't understand this loop, just know it will pass through every value between one and one before the end of array "a" for(int i = 0; i < a.length; i++) if(a[i] == 1) numOnes++; //Increments the variable by one Because there is only one argument being processed, no curly brackets are needed.
22nd Oct 2017, 10:28 PM
Quantallax
+ 11
F12 in chrome, to open Dev tools
24th Oct 2017, 4:59 PM
Morpheus
Morpheus - avatar
+ 10
Exclusive or (XOR) has one neat application, for swapping variables. Xor is a n operator much like and/or/not. It's true-false table looks like this: x | y | value ========= 0 | 0 | 0 1 | 0 | 1 0 | 1 | 1 1 | 1 | 0 ...and so, if either x or y is true, then it evaluates to true. If neither or both of them are true, it is then false. With this, you can swap two numbers as follows: // In C++, where ^ is the xor function x = x ^ y; y = y ^ x; x = x ^ y;
25th Oct 2017, 1:56 AM
Keto Z
Keto Z - avatar
+ 9
Another trick you can use is Arrays.sort(). If you are looking to order an array by, say, incrementing numerical values, or by alphabetical order, Arrays.sort will sort an array into a state of least to greatest (for numbers, from the lowest value to the highest value; for Strings, it is alphabetical order; for characters, I believe it is by ASCII value).
22nd Oct 2017, 11:00 PM
Quantallax
+ 9
Just a silly trick : "windows+enter " : // opens narrator select a piece of text or paragraph on adobe or notepad , narrator will read everything for you.
25th Oct 2017, 12:24 PM
RZK 022
RZK 022 - avatar
+ 9
https://code.sololearn.com/W7jduVw85hEi/?ref=app https://code.sololearn.com/WN08rm3tKS6t/?ref=app You can have a look at these 2 codes. There are many cool Java Script functions you can use.( They are very useful๐Ÿ‘)!
25th Oct 2017, 6:12 PM
Anatolii Harhash
Anatolii Harhash - avatar
+ 8
Most Fastest and Easiest way to use CSS on your website. Open your Mozilla Firefox than select, shift + F7. AND Use Sticky notes software for your cool text editor's short-cut keys. ๐Ÿ˜ƒ
25th Oct 2017, 8:10 AM
Ankit
Ankit - avatar
+ 8
only Firefox ๐Ÿ˜ Ctrl+Shift+j ๐Ÿ˜‰ find out your js error
26th Oct 2017, 4:30 AM
Samira
Samira - avatar
+ 6
movement in console aps (pleace run on a pc ID, I use dev c++) https://code.sololearn.com/cJkokphR37Gi/?ref=app
25th Oct 2017, 1:37 AM
Paolo Torregroza
Paolo Torregroza - avatar
+ 6
In the new Chrome version, you can use Ctrl+Shift+C then Ctrl + mouse drag to take a screen shot.
29th Oct 2017, 2:09 AM
Broomstick
Broomstick - avatar