Skip to content

Instantly share code, notes, and snippets.

View vparaskevas's full-sized avatar

Vasileios Paraskevas vparaskevas

View GitHub Profile
@InsilicoSoft
InsilicoSoft / stream-pdf-from-nodejs.js
Last active January 25, 2024 10:42
Stream local pdf file from nodejs (restify) server to client
server.get('/downloadPdf/:fileData', function (req, res) {
// config
var fileData = Buffer.from(req.params.fileData, 'base64');
var menuData = JSON.parse(fileData.toString());
var userName = menuData.userName;
var menuName = slug(menuData.menuName);
var fileName = userName + "-" + menuName + PDF_EXT;
var filePath = PDF_PATH + fileName;
// process headers
@Yawenina
Yawenina / debounce-lodash.js
Last active May 7, 2024 09:44
lodash debounce and throttle source code
const nativeMax = Math.max;
const nativeMin = Math.min;
function debounce(func, wait, options) {
let lastArgs,
lastThis,
maxWait,
result,
timerId,
lastCallTime,
lastInvokeTime = 0,
@ziluvatar
ziluvatar / token-generator.js
Last active April 8, 2025 08:12
Example of refreshing tokens with jwt
/**
* Example to refresh tokens using https://github.com/auth0/node-jsonwebtoken
* It was requested to be introduced at as part of the jsonwebtoken library,
* since we feel it does not add too much value but it will add code to mantain
* we won't include it.
*
* I create this gist just to help those who want to auto-refresh JWTs.
*/
const jwt = require('jsonwebtoken');
@ccnokes
ccnokes / axios-instance-config.js
Created July 6, 2017 16:23
Good default configuration for axios in node.js
const axios = require('axios');
const http = require('http');
const https = require('https');
module.exports = axios.create({
//60 sec timeout
timeout: 60000,
//keepAlive pools and reuses TCP connections, so it's faster
httpAgent: new http.Agent({ keepAlive: true }),
@robdodson
robdodson / index.html
Last active October 4, 2023 18:57
Shady DOM example
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2>Hello from outside the Shadow DOM!</h2>
@Riimu
Riimu / ai.js
Last active July 12, 2018 18:12
Simple greedy pathfinding algorithm for finding the path to the nearest fruit in a snake game
// Copyright (c) 2017 Riikka Kalliomäki
// Licensed under MIT license: https://opensource.org/licenses/MIT
window.snake = {};
(function (exports) {
"use strict";
var queue;
var nearest;
@rcanepa
rcanepa / routes.js
Last active March 2, 2023 08:29
Private routes with React Router v4
function PrivateRoute ({component: Component, authenticated, ...rest}) {
return (
<Route
{...rest}
render={(props) => authenticated === true
? <Component {...props} />
: <Redirect to={{pathname: '/login', state: {from: props.location}}} />}
/>
)
}
@javilobo8
javilobo8 / download-file.js
Last active March 17, 2025 14:25
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
'use strict';
import * as fs from 'fs';
import * as restify from 'restify';
import * as helmet from 'helmet';
if (process.env.NODE_ENV === 'development') {
require('dotenv').config();
}
@azeemhassni
azeemhassni / nationalities.json
Last active July 3, 2019 18:35
Nationalites List in JSON format
{
"afghan": "Afghan",
"albanian": "Albanian",
"algerian": "Algerian",
"american": "American",
"andorran": "Andorran",
"angolan": "Angolan",
"antiguans": "Antiguans",
"argentinean": "Argentinean",
"armenian": "Armenian",