JavaScript
-
[react][javascript] gps 위치 얻기 위도 경도 latitude/longitudeFrontend/react 2020. 3. 9. 18:49
아래는 위도와 경도를 가져오는 함수이다. Get the gps location. function getLocation() { if (navigator.geolocation) { // GPS를 지원하면 navigator.geolocation.getCurrentPosition(function(position) { alert(position.coords.latitude + ' ' + position.coords.longitude); }, function(error) { console.error(error); }, { enableHighAccuracy: false, maximumAge: 0, timeout: Infinity }); } else { alert('GPS를 지원하지 않습니다'); } } getLoca..
-
[winston] How to customize timestamp format. (to local timezone) 날짜 시간 포맷을 로컬 타임존으로 변경하기Backend/NodeJS 2019. 12. 20. 16:17
Winston에서 날짜 시간 포맷을 로컬 타임존으로 변경 하기! 나의 node.js 프로젝트에 winston을 적용하는 과정에서 로그 메시지의 시간을 기록하는데 timezone이 utc 기준 시간으로 기록이 되었다. 그래서 timestamp를 커스터마이징을 했다. winston 깃허브에서 사용 예를 보면 아래와 같다. timestamp 타임존이 로컬 기준이 아니라 시간이 맞지 않는다. // 원본 소스 const { format } = require('winston'); const { combine, timestamp, label, prettyPrint } = format; const logger = createLogger({ format: combine( label({ label: 'right meow!..
-
[typescript] Start express with typescriptPrograming/javascript 2019. 12. 6. 16:43
1.Make a PROJECT_DIRECTORY $ mkdir plantonline-cron-service && cd $_ 2. Make package.json $ npm init -y // package.json { "name": "plantonline-cron-service", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" } 3. Install modules $ npm install -S express $ npm install -D t..
-
[node] How to send remind-push to customersBackend/NodeJS 2019. 11. 27. 17:21
What is the remind-push? It is push notifications that leads users to access PLANT app service. So, We expect more connection & active users. When should I send it? 하루 중, 자주 접속 했던 시간이 지났는 데도 접속을 하지 않았을때 During a day, When they didn't connect until the time they frequently connect. How? I use data selectivity, histogram. 작업 프로세스 Step 1. 사용자들의 활동에 대한 날짜를 수집한다. Get timestamp that user activity. 2. ..
-
[node] How to double co-routine in promise & loopBackend/NodeJS 2019. 11. 26. 17:06
비동기 작업의 동기화, 코루틴 각 회원들의 프로필과 친구리스트를 회원별로 새로운 객체에 담고 싶을때 co-routine과 promise를 활용하여 DB 작업은 비동기로 처리하고 베이스 루틴은 동기적으로 처리하여 만들어진 객체를 반환한다. 이 작업은 코루틴 안에서 작업을 비동기적으로 하면서, 모든 작업이 완료되었을 때 반환한다. When all jobs are done, this funtion is return and the main tasks are processed asyncronously. const cofunc = bPromise.coroutine(function* () { try { ... const members = yield getMembers();// get DB // [{"id":"", "..
-
[typescript] histogram algorithmPrograming/javascript 2019. 11. 26. 13:54
LINK const histogram = (data: any, size: number = 1) => { const length = data.length; let min = data[0]; let max = data[1]; data.forEach((item: number) => { if (item max) max = item; }); const bins = Math.ceil((max - min + 1) / size); const histogram = new Array(bins); for (let i = 0; i < bins; i++) histogram[i] = 0; for (let i = 0; i < length; i++) histogram[M..
-
[node] Excel file exportPrograming/javascript 2019. 11. 21. 17:52
I need to get the excel data which is the result of db query. And I've got it successfully by using 'node-excel-export' module. [Source Code] main.js const exportExcel = require('./excel_export').exportExcel; ... function run() { ... const qData = getLogs();// QUERY exportExcel(qData); ... } run(); excel_export.js const excel = require('node-excel-export'); ... const exportExcel = (dataset) => {..