Blog Spot!


Calculate distance between two latitude-longitude points

function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
  var R, dLat, dLon, a, c, d;

  R = 6371; // Radius of the earth in km
  dLat = deg2rad(lat2-lat1);
  dLon = deg2rad(lon2-lon1); 
  a = 
    Math.sin(dLat/2) * Math.sin(dLat/2) +
    Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * 
    Math.sin(dLon/2) * Math.sin(dLon/2)
    ; 
  c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
  d = R * c; // Distance in km
  return parseFloat(d.toFixed(1));
}

function deg2rad(deg) {
  return deg * (Math.PI/180);
}

stackoverflow

Remastered

var fx = {

    /**
     * Get distance in meters between two coordinate points.
     */
    findDistance: function(loc1, loc2) {
        var R, dLat, dLon, a, c, d;

        R = 6371000; // Radius of the earth in meters
        dLat = fx.deg2rad(loc2.lat - loc1.lat);
        dLon = fx.deg2rad(loc2.lng - loc1.lng);
        a = Math.sin(dLat/2) * Math.sin(dLat/2) +
            Math.cos(fx.deg2rad(loc1.lat)) * Math.cos(fx.deg2rad(loc2.lat)) *
            Math.sin(dLon/2) * Math.sin(dLon/2);
        c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
        d = R * c; // Distance in meters
        return parseInt(d);
    },

    /**
     * Convert degrees to radians
     */
    deg2rad: function(deg) {
        return deg * (Math.PI / 180);
    }

};

console.log(fx.findDistance({
    lat: 42.658261,
    lng: 23.285241
}, {
    lat: 42.659616,
    lng: 23.285649
}));

Added on 13.Oct.2015
Tags: coordinates gps latitude longitude

Stop tracking and ignore changes to a file in GIT

Just calling git rm --cached on each of the files you want to remove from revision control should be fine. As long as your local ignore patterns are correct you won't see these files included in the output of git status.

stackoverflow

Added on 12.Oct.2015
Tags: git tracking

C program to Encrypt and Decrypt a password

#include <stdio.h>
#include <string.h>

void encrypt(char password[], int key) {
    unsigned int i;
    for(i = 0; i < strlen(password); i++) {
        password[i] = password[i] - key;
    }
}

void decrypt(char password[], int key) {
    unsigned int i;
    for(i = 0; i < strlen(password); i++) {
        password[i] = password[i] + key;
    }
}
int main() {
    char password[50];

    printf("Enter the password: \n ");
    scanf("%s", password);
    printf("Passwrod = %s\n", password);

    encrypt(password, 0xFACA);
    printf("Encrypted value = %s\n", password);

    decrypt(password, 0xFACA);
    printf("Decrypted value = %s\n", password);

    return 0;
}

run with

gcc -o main *.c
./main

c-program-example

Added on 18.Sep.2015
Tags: c encrypt decrypt passs

Array length in C

There is no .length property in C. The .length property can only be applied to arrays in object oriented programming (OOP) languages. The .length property is inherited from the object class; the class all other classes & objects inherit from in an OOP language. Also, one would use .length-1 to return the number of the last index in an array; using just the .length will return the total length of the array.

I would suggest something like this:

int i, j;
for(i = 0; i < (sizeof(my_array) / sizeof(my_array[0])); i++) {
   for(j = 0; j < (sizeof(my_array) / sizeof(my_array[0])); j++) {
        printf("%d", my_array[i][j]);
        printf("\n");
   }
}

The line (sizeof(my_array) / sizeof(my_array[0])) will give you the size of the array in question. The sizeof property will return the length in bytes, so one must divide the total size of the array in bytes by how many bytes make up each element, each element takes up 4 bytes because each element is of type int, respectively. The array is of total size 16 bytes and each element is of 4 bytes so 16/4 yields 4 the total number of elements in your array because indexing starts at 0 and not 1.

stackoverflow

Added on 17.Sep.2015
Tags: c programming array length

SSHFS - mount folder over ssh in linux

SSHFS is a tool that uses SSH to enable mounting of a remote filesystem on a local machine; the network is (mostly) transparent to the user.

help.ubuntu

Added on 16.Sep.2015
Tags: mount folder ssh sshfs

Search


PHP Libraries


Carbon lib / docs
Idiorm lib / docs
Image Workshop lib / docs
lorenzos/Minixed lib / docs
Parsedown lib / docs
PHP Paginator lib / docs
PHP Redis lib / docs
QrCode lib / docs
Requests lib / docs
Slim lib / docs
Spyc lib / docs
TWIG lib / docs
Upload lib / docs
Validation lib / docs
Zebra Image lib / docs

JS Libraries


AJV lib / docs
BackboneJS lib / docs
Bootstrap Notify lib / docs
C3.js lib / docs
ChartJS lib / docs
FastMD5 lib / docs
HighlightJS lib / docs
jQuery-Storage lib / docs
JS-Cookie lib / docs
Leaflet JS lib / docs
LowDB lib / docs
Marked lib / docs
NeedlyJS lib / docs
ParcelJS lib / docs
RequireJS lib / docs
Swig lib / docs
Toastr lib / docs
Underscore lib / docs
ValidateJS lib / docs
top