Skip to content

Instantly share code, notes, and snippets.

View anujsinghwd's full-sized avatar
🏠
Working from home

Anuj Singh anujsinghwd

🏠
Working from home
View GitHub Profile
const axios = require('axios');
const fs = require('fs');
const process = async () => {
const response = await axios.get('https://goo.gl/maps/29XfoqKK5s7UdaSy8');
const expression = /window.APP_INITIALIZATION_STATE=\[\[\[\d+.\d+,(\d+.\d+),(\d+.\d+)/
const [,lat, long] = response.data.match(expression)[0].split('[[[')[1].split(',')
console.log({ lat, long})
return { lat, long};
@anujsinghwd
anujsinghwd / GeoJSON.js
Created December 18, 2021 12:16 — forked from max-mapper/GeoJSON.js
google maps polygon editor
var app = {markers: []};
function serializePolygon(gpoly) {
var gjp = {
"type": "Polygon",
"coordinates": []
};
for (var i = 0; i < gpoly.latLngs.length; i++) {
gjp.coordinates[i] = []
var ring = gpoly.latLngs.getAt(i)
@anujsinghwd
anujsinghwd / geo.js
Created November 10, 2021 12:55 — forked from vkarpov15/geo.js
Example of querying a GeoJSON feature collection in MongoDB
db.test.drop();
db.test.insertOne({
name: 'Denver',
location: {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
@anujsinghwd
anujsinghwd / leaflet-google.js
Created October 23, 2021 18:02 — forked from crofty/leaflet-google.js
Leaflet plugin that enables the use of Google Map tiles - http://matchingnotes.com/using-google-map-tiles-with-leaflet
/*
* L.TileLayer is used for standard xyz-numbered tile layers.
*/
L.Google = L.Class.extend({
includes: L.Mixin.Events,
options: {
minZoom: 0,
maxZoom: 18,
tileSize: 256,
@anujsinghwd
anujsinghwd / node_nginx_ssl.md
Created October 21, 2021 10:59 — forked from bradtraversy/node_nginx_ssl.md
Node app deploy with nginx & SSL

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user

@anujsinghwd
anujsinghwd / MapboxDraw.js
Created August 25, 2019 07:50
Mapbox gl + mapbox-gl-draw + turf + react
var map;
var draw;
mapboxgl.accessToken = 'Your_Mapbox_Token';
class Mapload extends React.Component {
constructor(props) {
super(props)
this.state = {
lat: 27.85380233830591,
lng: 78.37183893820759,
@anujsinghwd
anujsinghwd / MapLoad.js
Last active August 22, 2019 06:06
Loading map with Mapbox GL JS + React JS
import React, { Component } from 'react';
import mapboxgl from 'mapbox-gl';
import './mapload.css';
mapboxgl.accessToken = 'Your-Mapbox-Token';
var map;
class MapLoad extends Component {
constructor(props) {
@anujsinghwd
anujsinghwd / spiral.php
Created November 17, 2018 10:53
Given a 2D matrix of size M*N. Traverse and print the matrix in spiral form.
<?php
$arr = array(array(1,2,3,4),array(5,6,7,8),array(9,10,11,12),array(13,14,15,16));
$k = 0;
$m = 3;//last row
$l = 0;
$n = 3; //last column
while($k <= $m && $l <= $n){
for($i=0;$i<=$m;$i++){
echo $arr[$k][$i];
@anujsinghwd
anujsinghwd / count_sort.php
Created November 17, 2018 07:09
Sort an array of 0s, 1s and 2s
<?php
$arr = array(0,2,1,2,0);
$n = count($arr);
$count = array_count_values($arr);
$new_arr;
for($j=0;$j<=2;$j++){
for($i=0;$i<$count[$j];$i++){
$new_arr[] = $j;
}
@anujsinghwd
anujsinghwd / max_sum.php
Last active November 17, 2018 07:10
Given an array A of positive integers. Find the maximum sum of a subsequence such that no two numbers in the sequence should be adjacent in the array.
<?php
$arr = array(5,5,10,100,10,5);
$n = count($arr);
$inc = $arr[0];
$ex = 0;
for($i=1;$i<$n;$i++){
$old_inc = $inc;
$inc = max($inc, $ex + $arr[$i]);
$ex = $old_inc;