10 Commont Jquery Mistakes You should Aware

Well, everybody makes mistakes and and better part would be to not repeat them again. You must "always make new mistakes" :). jQuery is amazing library. however believe me, it will cause you to crazy if it's not used properly and with efficiency. It will hit performance of your page and you do not even understand it. Raise yourself that as a developer whereas writing jQuery code does one really think about performance or it's only if your client shouts.



I have listed down ten common jQuery mistakes from my personal expertise and their fixes that you just can be additionally doing while writing jQuery code.

1. Be courageous to remove jQuery

Sometimes things can be done easily via CSS without even thinking about jQuery but we don't realize it. Plain CSS is far better than jQuery. So be open and courageous to remove jQuery whenever needed.

2. Not using latest version of jQuery

jQuery team is keep on updating the jQuery library and the newer version comes with lots of bug fixes and performance enhancement. I understand that it is not always possible for you to use the latest version for your old projects but I suggest for your new projects, you can use latest version of jQuery.

3. Not using minified version of jQuery library

The jQuery library (when you download) comes in two versions.

  1. Production (Compressed Version)
  2. Development (Uncompressed Version)



For development purpose, you can choose the development version of .js file as if you want to make some changes then that can be easily done. But ensure that when your software or product goes on production, always use the production version of .js file as its size is 5 times lesser than the development version. This can save some amount of bandwidth.

4. Not loading jQuery from Google CDN

Google is sea of free services. Do you know that Google is also hosting jQuery libraries on its CDN(Content delivery network) and allows any website to use it for free.


Why to use Google CDN?


  • Caching: The most important benefit is caching. If any previously visited site by user is using jQuery from Google CDN then the cached version will be used. It will not be downloaded again.
  • Reduce Load: It reduces the load on your web server as it downloads from Google server's.
  • Serves fast : You will be also benefitted from speed point of view. As Google has dozen's of different servers around the web and it will download the jQuery from whichever server is closer to the user. Google's CDN has a very low latency, it can serve a resource faster than your webserver can.
  • Parellel Downloading: As the js file is on a separate domain, modern browsers will download the script in parallel with scripts on your domain.

5. Not loading jQuery locally when CDN fails

It is a good approach to always use CDN but sometimes what if the CDN is down (rare possibility though) but you never know in this world as anything can happen. So if you have loaded your jQuery from any CDN and it went down then your jQuery code will stop working and your client will start shouting.

I always recommend that write the code, if jQuery library is not loaded properly then it should use your local copy of jQuery.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
  document.write(unescape("%3Cscript src='Scripts/jquery.1.9.0.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
It first loads the jQuery from Google CDN and then check the jQuery object. If jQuery is not loaded successfully then it will references the jQuery.js file from hard drive location. In this example, the jQuery.js is loaded from Scripts folder.

6. Not using selectors efficiently

Be smart while using selectors. As there are many ways to select element using selectors but that doesn't mean that all are equal. Always try to use ID and Element as selector as they are very fast. Even the class selectors are slower than ID selector.

When IDs are used as selector then jQuery internally makes a call to getElementById() method of Java script which directly maps to the element.

When Classes are used as selector then jQuery has to do DOM traversal.So when DOM traversal is performed via jQuery takes more time to select elements. In terms of speed and performance, it is best practice to use IDs as selector.

7. Using jQuery selectors repeatedly

Take a look at below jQuery code. The selectors are used thrice for 3 different operation.
$("#myID").css("color", "red");
$("#myID").css("font", "Arial");
$("#myID").text("Error occurred!");
The problem with above code is, jQuery has to traverse 3 times as there are 3 different statements.But this can be combined into a single statement.
$("#myID").css({ "color": "red", "font": "Arial"}).text("Error occurred!"); 
This will ensure that jQuery traverse only once through DOM while selecting the element.

8. Not knowing how selectors are executed

Do you know how the selectors are executed? Your last selectors is always executed first. For example, in below jQuery code, jQuery will first find all the elements with class ".myCssClass" and after that it will reject all the other elements which are not in "p#elmID".
$("p#elmID .myCssClass");

9. By not caching the stuff

Caching is an area which can give you awesome performance, if used properly and at the right place. While using jQuery, you should also think about caching. For example, if you are using any element in jQuery more than one time, then you must cache it. See below code.
$("#myID").css("color", "red");
//Doing some other stuff......
$("#myID").text("Error occurred!");
Now in above jQuery code, the element with #myID is used twice but without caching. So both the times jQuery had to traverse through DOM and get the element. But if you have saved this in a variable then you just need to reference the variable. So the better way would be,
var $myElement = $("#myID").css("color", "red");
//Doing some other stuff......
$myElement.text("Error occurred!");
So now in this case, jQuery won't need to traverse through the whole DOM tree when it is used second time. So in jQuery, Caching is like saving the jQuery selector in a variable. And using the variable reference when required instead of searching through DOM again.

10. Not checking while using various plugins

One of the great feature of jQuery is various plugins available created using jQuery are available for free. You like a jQuery plugin and start using it in your project. But while using plugins do you really consider,

  • File size
  • Performance of plugin
  • Browser Compatibility

Before using any plugin, always ensure that it must not hit performance of your page and it should not conflict with other plugins that you are using already.

Feel free to contact me for any help related to jQuery, I will gladly help you.

HungerMoji - Android Notification Game [Source Code]

As you know Android has such a great scope in gaming field but you just need some innovation and different ideas which can attract the user to play your game again and again.
Today i am telling you a great idea of game with their source code. You'll play it on your notification bar. Its cool isn't it ?
This game named as HungerMoji and it is a unique Android game that takes place within the system notification drawer.

Players must feed their emoji which resides in a notification by dismissing any offending notifications, and collecting any bonus point notifications.


Download Source Code

Demo


Hope you enjoy and please give some time for feedback 😀😀😀.


Google Draw AI Experiment - Kids can learn by draw

Google Draw,  a brand new group of online artificial-intelligence experiments and one particularly stands out as each an habit-forming game and a desirable window on machine learning.

Quick, Draw challenges you to form a series of drawings in under twenty seconds for each one. The neural network tries to work out what you are drawing as you go. It learns from its mistakes and seeks to enhance its recognition skills.



I'm no nice visual creative person, however the AI racked up a powerful 5-out-of-6 score on my 1st round, properly identifying grass, a chopper, a penguin, a remote control and scissors. The one it lost was an outline of a feather, that I though was good, however the AI thought it looked a lot of sort of a mouse, ice cream or tennis racket.



There's an almost addictive thrill to wiggling with fast, Draw. The timer counts down and gets a lot of pressing as the seconds tick by. A voice guesses at your drawings, making it want a browser-based game of charades. generally it simply provides up, saying "I don't have any clue what you are drawing. Sorry i could not guess it." and so you are feeling like you've got let the poor AI down along with your tinny art skills.



In one stunningly bad round, I drew a kangaroo that sounded like a lizard, a sun that sounded like an exploded egg, a tornado that seemed like a cream horn and a basketball that resembled a cookie. however the neural network does not decide. It simply causes you to wish to play once more.

PhotoScan - A new Google Photo feature

Google has launched PhotoScan, a innovative application that allows users to scan recent photos which will thenceforth be hold on and retouched in Google Photos.
PhotoScan allows users to scan recent photos in numerous formats, and also, wherever necessary, to revive them to their former glory. The app options retouching, and rotation functionalities, together with options to enhance perspective and eliminate reflections. the concept is produce high-quality digital copies that provides a new life to recent photos.



Along with this new application, Google is additionally launching an update to Photos with a recently improved automatic improvement feature that permits users to effortlessly balance exposure and saturation to optimize image detail.

How will it work ?

  1. The app opens to the camera and prompts users to position a photograph inside the frame.
  2. Four dots ought to appear over the picture if done properly.
  3. The app can automatically crop, rotate and color correct.
  4. Google has additionally created area for these memories in Google Photos, that is accessed using the search ‘scan’.
  5. This app is offered for each iOS and android users. 
‘Scanned photos is saved in one tap to Google Photos to be organized, searchable, shared, and safely secured at high quality—for free.’

Photoscan, google photo, features

To scan the print, move your phone over every of the dots and hold it till the circle seems to be filled in.
Not solely is that this less expensive than a scanner, however as shortly as you’ve uploaded one photograph you'll be able to move right to the next.
And the app can automatically crop, rotate and color correct.


The latest version of Google Photos additionally includes 12 new filters that modify pictures by adding shadows, warming up colours, and adjusting saturation. There are advanced retouching choices (light, color, sharpness and style) that permit users to optimize the looks every kind of photos.
Google PhotoScan and Google Photos is downloaded for free of charge from Google Play (Android) and App Store (iOS).

Top 8 Features of Snapchat Glass : You should know

Snapchat has renamed itself to Snap inc. and enlarged its service to client hardware. the first product launched by the company is that the latest Snap Spectacles that could be a pair of glasses with in-built wireless enabled camera and reminds Google Glass. However, the popular instant electronic messaging company claims that their wearable is way higher in terms of functionality and staying power.



Spectacles smart glasses can permit users to require snaps or shoot videos of the primary person and send them on to the Snapchat app. Though, it's necessary for our users to understand that Google Glasses weren't appreciated an excessive amount of by the lots as a result of people had concern that anyone carrying such overpriced glasses will record their video secretly.

Snapchat believes that it won’t happen with their Spectacles and hopes that they'll for certain become a huge success in close to future. There are many reasons behind this confidence, Let’s see what we all know regarding Snapchat Spectacles until currently and it'd assist you to come to a decision whether or not to travel for it or not.

1. Decent value

The Spectacles can value you around $129.99 that is even lesser than the try of designer shades with none camera inbuilt. it's also terribly cheaper than Google Glass that was priced $1,500 at the time of launch. Snapchat Spectacles provide similar fun and fits into everyone’s budget, which may undoubtedly create a distinction. they'll be shipped in 3 color variants Black, Coral and Teal.


2. Focus on Single Aim

Google Glasses were launched with several options and were additional sort of a wearable computer than a mobile camera. On the opposite hand Snapchat Spectacles have the one aim to capture pictures or record video. Users will record up to ten seconds of video by sound the button mounted on the frame and every tap can records a replacement clip.

3. You'll be able to Shoot while not a Phone

The Spectacles have the flexibility to attach on to the Snapchat via Bluetooth or Wi-Fi and send the footage during a circular video format instead of rectangular or sq. in order that they'll play full screen on any device. The camera glass uses 115-degree lens to suit additional into the frame that is wider than the iPhone that provides 74 degree of viewing angle.


4. Strong Battery Backup

Spectacles ar meant to be the right answer for standalone photography or videography and a strong battery is crucial to try to to therefore. The battery comes with the glasses is capable of taking snaps (that get keep on the glass) for the day when one charge.

5. Share Videos through Snapchat App Wirelessly

As we already mentioned, you'll be able to transfer pictures or video clips via Bluetooth or Wi-Fi to your Snapchat app that is put in on your android or iPhone. you'll be able to add those pictures in your recollections and share them within the Snapchat stories. you'll be able to play videos taken by the Spectacles despite of this fact that they were captured in circular video format as a result of Snapchat can crop them automatically once you rotate the device.

6. No Secret Recording

We keep in mind that people carrying Google Glasses were late prohibited to publicly places because of the very fact that they were able to capture video or pictures of others while not their information. Though, Google created tries to form it clear that the lens of the wearable glitters once the video gets recorded, however folks weren't happy and wished one thing higher. there's no such problem in Spectacles and also the little ring round the camera lights up to let others grasp that you just ar recording.

7. Spectacles Charge just in case

Yes, you scan it right, your Snapchat Spectacles wirelessly charges in their own case. That means, you don’t got to carry wires or charges beside you whereas traveling. Your case can charge the automatically. Though, we are still waiting to check however it can be done.


8. Snapchat Spectacles availability

There is no specific time, that is mentioned by the company as once it's planning to be available within the market. however “Coming Soon” tag is on the website and it clearly means you'll be able to expect it to launch within the finish of the 2016 or early 2017.


It’s been virtually one and a half-year since the Google Glass was launched and currently things has modified lots. people are more comfortable with selfies and social networks, however still you'll be able to meet those that don’t just like the plan of carrying a try of sunglass with a mobile camera at public areas. Snapchat is presenting Spectacles as a fun device and is ready to drag it back and introduce one thing less arguable if it doesn’t work.

Leonids - Android Particle Animation Library

Leonids is a particle system library that works with the standard Android UI.
The library is extremely lightweight, LeonidsLib.jar is just 81Kb.
You can download Leonids Demo from Google Play to check out what can be done with it.

Setup

Leonids is available in jcenter as well as a jar file to fit both Android Studio and Eclipse.

Android Studio / gradle

Add the following dependency to the build.gradle of your project₹₹₹₹
dependencies {
    compile 'com.plattysoft.leonids:LeonidsLib:1.3.1'
}
Note: If you get an error, you may need to update the jcenter repository to:
repositories {
    jcenter{
        url "http://jcenter.bintray.com/"
    }
}

Eclipse / jar file

Just put LeonidsLib.jar into the libs folder of your app.

Why this library?

Particle systems are often used in games for a wide range of purposes: Explosions, fire, smoke, etc. This effects can also be used on normal apps to add an element of "juiciness" or Playful Design.
Precisely because its main use is games, all engines have support for particle systems, but there is no such thing for standard Android UI.
This means that if you are building an Android app and you want a particle system, you have to include a graphics engine and use OpenGL -which is quite an overkill- or you have to implement it yourself.
Leonids is made to fill this gap, bringing particle sytems to developers that use the standard Android UI.

Basic usage

Creating and firing a one-shot particle system is very easy, just 3 lines of code.
new ParticleSystem(this, numParticles, drawableResId, timeToLive)
.setSpeedRange(0.2f, 0.5f)
.oneShot(anchorView, numParticles);
Note that the ParticleSystem checks the position of the anchor view when oneShot (or emit) is called, so it requires the views to be measured. This means that ParticleSystem won't work properly if you call oneShot or emit during onCreate
When you create the particle system, you tell how many particles will it use as a maximum, the resourceId of the drawable you want to use for the particles and for how long the particles will live.
Then you configure the particle system. In this case we specify that the particles will have a speed between 0.2 and 0.5 pixels per milisecond (support for dips will be included in the future). Since we did not provide an angle range, it will be considered as "any angle".
Finally, we call oneShot, passing the view from which the particles will be launched and saying how many particles we want to be shot.

Emitters

You can configure emitters, which have a constant ratio of particles being emited per second. This is the code for the Confeti example:
new ParticleSystem(this, 80, R.drawable.confeti2, 10000)
.setSpeedModuleAndAngleRange(0f, 0.3f, 180, 180)
.setRotationSpeed(144)
.setAcceleration(0.00005f, 90)
.emit(findViewById(R.id.emiter_top_right), 8);

new ParticleSystem(this, 80, R.drawable.confeti3, 10000)
.setSpeedModuleAndAngleRange(0f, 0.3f, 0, 0)
.setRotationSpeed(144)
.setAcceleration(0.00005f, 90)
.emit(findViewById(R.id.emiter_top_left), 8);
It uses an initializer for the Speed as module and angle ranges, a fixed speed rotaion and extenal acceleration.

Available Methods

List of the methods available on the class ParticleSystem.

Constructors

All constructors use the activity, the maximum number of particles and the time to live. The difference is in how the image for the particles is specified.
Supported drawables are: BitmapDrawable and AnimationDrawable.
  • ParticleSystem(Activity a, int maxParticles, int drawableRedId, long timeToLive)
  • ParticleSystem(Activity a, int maxParticles, Drawable drawable, long timeToLive)
  • ParticleSystem(Activity a, int maxParticles, Bitmap bitmap, long timeToLive)
  • ParticleSystem(Activity a, int maxParticles, AnimationDrawable animation, long timeToLive)
There are also constructors that recieve a view id to use as the parent so you can put the particle system on the background (or between any two views)
  • ParticleSystem(Activity a, int maxParticles, int drawableRedId, long timeToLive, int parentViewId)
  • ParticleSystem(Activity a, int maxParticles, Drawable drawable, long timeToLive, int parentViewId)
  • ParticleSystem(Activity a, int maxParticles, Bitmap bitmap, long timeToLive, int parentViewId)
  • ParticleSystem(Activity a, int maxParticles, AnimationDrawable animation, long timeToLive, int parentViewId)

Configuration

Available methods on the Particle system for configuration are:
  • setSpeedRange(float speedMin, float speedMax): Uses 0-360 as the angle range
  • setSpeedModuleAndAngleRange(float speedMin, float speedMax, int minAngle, int maxAngle)
  • setSpeedByComponentsRange(float speedMinX, float speedMaxX, float speedMinY, float speedMaxY)
  • setInitialRotationRange (int minAngle, int maxAngle)
  • setScaleRange(float minScale, float maxScale)
  • setRotationSpeed(float rotationSpeed)
  • setRotationSpeedRange(float minRotationSpeed, float maxRotationSpeed)
  • setAcceleration(float acceleration, float angle)
  • setFadeOut(long milisecondsBeforeEnd, Interpolator interpolator): Utility method for a simple fade out effect using an interpolator
  • setFadeOut(long duration):Utility method for a simple fade out
You can start the particle system "in the future" if you want to have the particles already created and moving using
setStartTime(int time)
For more complex modifiers, you can use the method addModifier(ParticleModifier modifier). Available modifiers are:
  • AlphaModifier (int initialValue, int finalValue, long startMilis, long endMilis)
  • AlphaModifier (int initialValue, int finalValue, long startMilis, long endMilis, Interpolator interpolator)
  • ScaleModifier (float initialValue, float finalValue, long startMilis, long endMilis)
  • ScaleModifier (float initialValue, float finalValue, long startMilis, long endMilis, Interpolator interpolator)

One shot

Make one shot using from the anchor view using the number of particles specified, an interpolator is optional
  • oneShot(View anchor, int numParticles)
  • oneShot(View anchor, int numParticles, Interpolator interpolator)

Emitters

Emits the number of particles per second from the emitter. If emittingTime is set, the emitter stops after that time, otherwise it is continuous.

Basic emitters

  • emit (View emitter, int particlesPerSecond)
  • emit (View emitter, int particlesPerSecond, int emittingTime)

Emit based on (x,y) coordinates

  • emit (int emitterX, int emitterY, int particlesPerSecond)
  • emit (int emitterX, int emitterY, int particlesPerSecond, int emitingTime)

Emit with Gravity

  • emitWithGravity (View emiter, int gravity, int particlesPerSecond)
  • emitWithGravity (View emiter, int gravity, int particlesPerSecond, int emitingTime)

Update, stop, and cancel

  • updateEmitPoint (int emitterX, int emitterY) Updates dynamically the point of emission.
  • stopEmitting () Stops the emission of new particles, but the active ones are updated.
  • cancel () Stops the emission of new particles and cancles the active ones.

Other details

Leonids requires minSDK 11 because it uses ValueAnimators. It should be very easy, however to use nineoldandroids and make it work on Gingerbread.
The library is Free Software, you can use it, extended with no requirement to open source your changes. You can also make paid apps using it.
Each Particle System only uses one image for the particles. If you want different particles to be emitted, you need to create a Particle System for each one of them.