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
@anujsinghwd
anujsinghwd / main.go
Created March 16, 2018 10:47
Upload File - golang
package main
import (
"crypto/md5"
"fmt"
"io"
"net/http"
"os"
"strconv"
"text/template"
@anujsinghwd
anujsinghwd / couchbase.go
Last active March 23, 2018 06:37
Connecting couchbase with go
import (
"github.com/couchbase/gocb"
)
var bucket *gocb.Bucket
func main() {
cluster, _ := gocb.Connect("couchbase://localhost")
@anujsinghwd
anujsinghwd / datevalidation.html
Last active May 23, 2018 11:50
validate date and also reformat date
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Checking Date</title>
<style>
li {
list-style-type: none;
font-size: 16pt;
@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;
@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 / 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 / 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 / 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 / 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 / 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,