Skip to content

Instantly share code, notes, and snippets.

View tetrashine's full-sized avatar

louisz tetrashine

View GitHub Profile
@tetrashine
tetrashine / multer-fileupload-2.js
Last active August 23, 2020 09:31
multer fileupload setup
var storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, path.join(__dirname, '/tmp'));
},
filename: function (req, file, callback) {
callback(null, 'file-' + Date.now() + path.extname(file.originalname));
}
});
var uploadFunc = multer({ storage: storage }).single('uploaded_file');
@tetrashine
tetrashine / multer-fileupload-3.js
Created August 23, 2020 09:35
multer-fileupload-3
const express = require('express');
const multer = require('multer');
const path = require('path');
const app = express();
const port = 8080;
app.use('/', express.static('public'));
var storage = multer.diskStorage({
destination: function (req, file, cb) {
const https = require("https");
const data = "{\"limit\": 1000}";
const req = https.request('https://api.dropboxapi.com/2/file_requests/count', {
method: 'POST',
headers: {
'Authorization': `Bearer ${TOKEN}`,
},
}, (res) => {
const https = require("https");
fs = require('fs')
fs.readFile('test.txt', 'utf8', function (err, data) {
const req = https.request('https://content.dropboxapi.com/2/files/upload', {
method: 'POST',
headers: {
'Authorization': `Bearer ${TOKEN}`,
'Dropbox-API-Arg': JSON.stringify({
'path': '/Upload/test.txt',
const https = require("https");
const JSONbig = require('json-bigint');
fs = require('fs')
const req = https.request(`https://content.dropboxapi.com/2/files/upload_session/start`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${TOKEN}`,
'Dropbox-API-Arg': JSON.stringify({
@tetrashine
tetrashine / main.js
Last active July 14, 2021 11:02
onVideoComplete
await this._page.evaluateOnNewDocument(() => {
let checkWatchTimeFunc = () => {
let currElem = document.getElementsByClassName('ytp-time-current'); //grab the element showing current play time
let maxElem = document.getElementsByClassName('ytp-time-duration'); //grab the element showing total play time
if (
currElem.length > 0 && maxElem.length > 0 //check if there are any such element
&& currElem[0].innerText === maxElem[0].innerText //compare the value between the 2 elements
) {
@tetrashine
tetrashine / map-dashboard-postgresql.sql
Last active March 7, 2021 08:04
map-dashboard-postgresql.sql
CREATE TABLE map.assets (
id SERIAL primary key,
name VARCHAR(50)
);
CREATE TABLE map.assets_location (
id SERIAL primary key,
asset_id INTEGER references assets,
last_update TIMESTAMP,
geom geometry(Point, 4326)
@tetrashine
tetrashine / map-dashboard.js
Created March 7, 2021 08:07
map-dashboard.js
require('leaflet');
var WMS = require('leaflet.wms');
window.onload = function() {
// initialize the map on the "map" div with a given center and zoom
var map = L.map('map', {
center: new L.LatLng(1.355, 103.84),
zoom: 13,
});
@tetrashine
tetrashine / timer.js
Created March 10, 2021 01:48
periodic refresh
function timer() {
layer.setParams({'r': Math.random()}, false);
setTimeout(timer, 5000);
}
setTimeout(timer, 5000);
@tetrashine
tetrashine / asset_server.js
Created March 10, 2021 20:48
asset_server.js
require('dotenv').config()
const express = require('express');
const app = express();
const { Pool, Client } = require('pg');
const pool = new Pool({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_DBNAME,
password: process.env.DB_PASS,