Skip to content

Instantly share code, notes, and snippets.

View AlexKardone's full-sized avatar

Alexander Matskevich AlexKardone

View GitHub Profile
@AlexKardone
AlexKardone / Phone field mask
Created May 24, 2019 13:49
Phone field mask
<script>
$(document).ready(function() {
$("#phone").mask("+7 (999) 99-99-999", {autoclear: false});
$("#phone").click(function(){
if($("#phone").val()=="+7 (___) __-__-___") {
$('#phone')[0].selectionStart = 4;
$('#phone')[0].selectionEnd = 4;
}
})
});
@AlexKardone
AlexKardone / Check overlap between two rectangles
Last active July 31, 2019 17:21
Check overlap between two rectangles
var checkCollisions = function(rect1, rect2) {
var xOverlap = Math.abs(rect1.x - rect2.x) <= Math.max(rect1.width, rect2.width);
var yOverlap = Math.abs(rect1.y - rect2.y) <= Math.max(rect1.height, rect2.height);
return xOverlap && yOverlap;
}
@AlexKardone
AlexKardone / Calculate the angle of shooting
Created August 26, 2019 14:14
Calculate the angle of shooting
shapes.point.x = shapes.point.x + shapes.point.velocity * Math.cos(angle / 180 * Math.PI);
shapes.point.y = shapes.point.y + shapes.point.velocity * Math.sin(angle / 180 * Math.PI);
function isObject(obj) {
return obj?.constructor.name === 'Object';
}
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);