Skip to content

Instantly share code, notes, and snippets.

View Sanaldev's full-sized avatar

SanalDev Sanaldev

  • Near
  • Bangalore, India
View GitHub Profile
@Sanaldev
Sanaldev / map_box_static_map_geoJson.js
Last active March 5, 2019 08:13
Map Box - Static Map - GeoJson
var topLocations = [{"Locations":"Cedar Grove Park","Lat Long":"-26.75768,152.8438","Footfall":293},{"Locations":"Noel Burns Park","Lat Long":"-26.76416,153.12004","Footfall":289},{"Locations":"Bill Keylock Place","Lat Long":"-27.60254,152.98185","Footfall":288},{"Locations":"Pardalote Park","Lat Long":"-27.60706,153.04122","Footfall":284},{"Locations":"Laurel Oak Park","Lat Long":"-27.62282,153.03159","Footfall":276},{"Locations":"Biambi Yumba Park","Lat Long":"-27.54035,152.96964","Footfall":272},{"Locations":"Homestead Park","Lat Long":"-27.60673,152.95791","Footfall":272},{"Locations":"Crummunda Park","Lat Long":"-26.7643,153.12379","Footfall":271},{"Locations":"Bicentenary Park","Lat Long":"-26.75921,152.85016","Footfall":271},{"Locations":"Hives Park","Lat Long":"-27.53381,152.98028","Footfall":267}];
L.mapbox.accessToken = 'Sample Token'; //Use a Valid Token
var featureArray = [];
topLocations.forEach(function(ele,i){
lat = parseFloat(ele['Lat Long'].split(',')[0]);
lon = parseFloat(ele['
@Sanaldev
Sanaldev / rspec_model_testing_template.rb
Created June 16, 2017 08:22 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@Sanaldev
Sanaldev / Detect Mobile - JS
Created May 10, 2017 15:13
JS Snippet to identify the mobile device from userAgent
function detectmob() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
return true;
@Sanaldev
Sanaldev / gmap_imgdiv_overlay
Last active March 20, 2017 12:30
Fixed image overlay over the Google Map
<!DOCTYPE html>
<html>
<head>
<title>GoogleMap</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=4.0, user-scalable=yes"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<style>
#map-page, #map-canvas { width: 100%; height: 100%; padding: 0; }
@Sanaldev
Sanaldev / gmap_jq.html
Created March 17, 2017 08:51
Fullscreen Google Map with Direction Service & Custom InfoWindow
<!DOCTYPE html>
<html>
<head>
<title>GoogleMap</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=4.0, user-scalable=yes"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<style>
.gm-style-iw{
top: 10px !important;
@Sanaldev
Sanaldev / APC Cache
Last active July 7, 2016 11:24
A Simple class utilizing APC caching system
<?
class CacheAPC {
var $iTtl = 600; // Time To Live
var $bEnabled = false; // APC enabled?
// constructor
function CacheAPC() {
$this->bEnabled = extension_loaded('apc');
}
@Sanaldev
Sanaldev / Dijkstra
Last active February 17, 2016 10:02
Dijkstra Shortest Path in a Graph
class vertex
{
public $key = null;
public $visited = 0;
public $distance = 1000000; // infinite
public $parent = null;
public $path = null;
public function __construct($key)
{
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<!-- <form action="evalcode.php" id="usrform" method="post">-->
Code 1: <textarea id="code1" name="code1" rows="10" cols="70"></textarea>&nbsp;&nbsp;&nbsp; Code2: <textarea id="code2" name="code2" rows="10" cols="70"></textarea></br>
No of Iterations: <input type="text" name="itr" id="itr">&nbsp;</br></br>
<div align="center">
<input type="submit" align="center" onclick="callAjax()">
@Sanaldev
Sanaldev / gist:7802376
Created December 5, 2013 09:13
VideoMarkups
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
var videoDuration;
var firstQuartileFlag = true;
var mutedFlag = false;
var videoad;
var updateProgressBar = function() {
progress = (100.0 * parseFloat(videoad.prop("played").end(0)) / videoDuration).toFixed(2);
if (firstQuartileFlag && progress >= 25.0 && progress < 50.0) {
@Sanaldev
Sanaldev / Haversine PHP
Last active February 4, 2016 09:14
Haversine formula in PHP
function getDistance($latitude1, $longitude1, $latitude2, $longitude2) {
$earth_radius = 6371000;
$dLat = deg2rad($latitude2 - $latitude1);
$dLon = deg2rad($longitude2 - $longitude1);
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon/2) * sin($dLon/2);
$c = 2 * asin(sqrt($a));
$d = $earth_radius * $c;