Skip to content

Instantly share code, notes, and snippets.

View memandip's full-sized avatar
🎯
Focusing

Mandip Tharu memandip

🎯
Focusing
  • Kathmandu, Nepal
View GitHub Profile
import React, {Component} from 'react';
import download from 'downloadjs';
import mime from 'mime-types';
class App extends Component {
handleClick = () => {
let file = '/testfile.txt'; //file url (local or remote)
let filename = 'testfile.txt';
let mimetype = mime.lookup(filename);
@memandip
memandip / zoom-to-specific-element
Last active July 10, 2018 16:38
svg-pan-zoom zoom to specific element
let options = {
panEnabled: true,
dragEnabled: true,
controlIconsEnabled: false,
zoomEnabled: true,
zoomScaleSensitivity: 0.2,
minZoom: 0.8,
maxZoom: 100000
};
let map = svgPanZoom('#svg-id', options);
@memandip
memandip / d3-svg-zoom
Last active August 28, 2018 06:12
create map with topojson and zoom map with d3 v5
let width = 850, height = 345;
let projection = d3.geoMercator();
let path = d3.geoPath().projection(projection);
let svg = d3.select("#map-wrapper").append("svg")
.attr('id', 'map')
.attr("width", '100%')
.attr("height", height)
let g = svg.append('g');
@memandip
memandip / scroll-to-overflowed-element
Created October 1, 2018 05:41
Scroll to specific overflowed element
// Scroll to the top
$parent.scrollTop($parent.scrollTop() + $child.offset().top);
// Scroll to the center
$parent.scrollTop($parent.scrollTop() + $child.offset().top
- $parent.height()/2 + $child.height()/2);
@memandip
memandip / getPrevCursorWord.html
Last active July 8, 2019 06:48
Get nearest word of the cursor position in textbox
<!DOCTYPE html>
<html lang="en">
<head>
<title>Get Nearest word of cursor</title>
</head>
<body>
<input id="textArea" type="text"/>
<br />
@memandip
memandip / filedownload.php
Created July 10, 2019 08:52
PHP file download
<?php
$filename = 'filepath.html';
$path = __DIR__ . '/web/uploads/';
$download_file = $path . $filename;
if (file_exists($download_file)) {
$extension = explode('.', $filename);
$extension = $extension[count($extension) - 1];
header('Content-Transfer-Encoding: binary');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
header('Accept-Ranges: bytes');
@memandip
memandip / index.html
Created July 25, 2019 12:18
Ajax based file upload in nodejs with express-fileupload
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Node JS File Upload</title>
</head>
@memandip
memandip / nginx-proxy-websocket
Last active July 26, 2019 08:50
Nginx configuration to configure reverse proxy for websocket
server {
root projectDirectory;
# example root /var/www/html/myAwesomeProject/public;
index index.html;
server_name domain_name;
location /chat/socket {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
@memandip
memandip / index.html
Last active July 26, 2019 12:26
Send file with websocket
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Node JS WebSocket Upload</title>
</head>
@memandip
memandip / io-wss
Created July 31, 2019 06:08
Socket.io https websocket server with custom web socket url
const fs = require('fs')
const https = require('https')
const app = require('express')()
var privateKey = fs.readFileSync('./privatekey.pem', 'utf8')
var certificate = fs.readFileSync('./certificate.pem', 'utf8')
const credentials = {key: privateKey, cert: certificate}
const httpsServer = https.createServer(credentials, app)