Skip to content

Instantly share code, notes, and snippets.

View djom202's full-sized avatar

Jonathan Olier djom202

View GitHub Profile
@djom202
djom202 / Nested-Routers-Express.md
Created May 13, 2019 14:21 — forked from zcaceres/Nested-Routers-Express.md
Child Routers in Express

Nested Routers in Express.js

Express makes it easy to nest routes in your routers. But I always had trouble accessing the request object's .params when you had a long URI with multiple parameters and nested routes.

Let's say you're building routes for a website www.music.com. Music is organized into albums with multiple tracks. Users can click to see a track list. Then they can select a single track and see a sub-page about that specific track.

At our application level, we could first have a Router to handle any requests to our albums.

const express = require('express');
@djom202
djom202 / bike_share_time_series.csv
Created April 5, 2019 18:12
Bike Share time series
datetime season holiday workingday weather temp atemp humidity windspeed
2011-01-20 00:00:00 1 0 1 1 10.66 11.365 56 26.0027
2011-01-20 01:00:00 1 0 1 1 10.66 13.635 56 0
2011-01-20 02:00:00 1 0 1 1 10.66 13.635 56 0
2011-01-20 03:00:00 1 0 1 1 10.66 12.88 56 11.0014
2011-01-20 04:00:00 1 0 1 1 10.66 12.88 56 11.0014
2011-01-20 05:00:00 1 0 1 1 9.84 11.365 60 15.0013
2011-01-20 06:00:00 1 0 1 1 9.02 10.605 60 15.0013
2011-01-20 07:00:00 1 0 1 1 9.02 10.605 55 15.0013
2011-01-20 08:00:00 1 0 1 1 9.02 10.605 55 19.0012
@djom202
djom202 / bitbucket-pipelines.yml
Created February 18, 2019 13:58 — forked from thesabbir/bitbucket-pipelines.yml
Bitbucket pipeline example for JS projects
image: node:7.0 #node v7
clone: # the 'clone' section
depth: 1 # latest commit only
pipelines:
default:
- step:
script:
- npm i -g yarn
- yarn
root = true
[*]
charset = utf-8
indent_style = tab
indent_size = 4
end_of_line = lf
insert_final_newline = false
trim_trailing_whitespace = true
@djom202
djom202 / array.js
Created September 11, 2018 16:47
Sort numeric array
function sortArr(arr){
return arr.sort(function (a, b){
return a - b;
});
}
@djom202
djom202 / firebase_env.js
Created May 25, 2018 15:46
Init firebase services in nodejs
module.exports = {
'type': '',
'project_id': '',
'private_key_id': '',
'private_key': '',
'client_email': '',
'client_id': '',
'auth_uri': '',
'token_uri': '',
'auth_provider_x509_cert_url': '',
@djom202
djom202 / style.css
Created May 25, 2018 00:20
Setting 100% height of the screen
html, body {
height:100vh; /* viewport height */
}
/*
The second method is using the vh unit. Surely you already know that to determine the "size"
of an element in CSS we can use units such as pixels, points, percentages or even em. But
maybe you have not heard about the vh and vw units. A vh unit (viewport height) is
equivalent to 1% of the height of the viewport (the total of the screen of the device that
shows our web). 1vh = 1% of the total screen, 100vh = 100%. As you may have guessed, the
@djom202
djom202 / haversine.js
Created May 8, 2018 16:45
Using the Haversine Formula in Javascript Ask
Number.prototype.toRad = function() {
return this * Math.PI / 180;
}
var lat2 = 42.741;
var lon2 = -71.3161;
var lat1 = 42.806911;
var lon1 = -71.290611;
var R = 6371; // km
@djom202
djom202 / NMEA2GPS.js
Last active April 20, 2018 03:08
Converter from NMEA to Decimals (GPS)
function NMEA2GPS(num, pole){
var poles = {'N':1,'S':-1,'W':-1,'E':1};
var s = parseFloat(num).toString();
var deg = s.substring(0,2);
var min = s.substring(2);
return (parseInt(deg) + parseFloat(min)/60) * poles[pole];
}
// NMEA2GPS(07721.2060, 'W') => -77.35347
@djom202
djom202 / index.js
Last active April 4, 2018 14:44
The function will count the amount of existences of a character specific into the string
// You'll need to include the prototypes.js file before use it.
// To NodeJs: let proto = require('prototypes');
// To Html: <script src="path/prototypes.js"></script>
// Note: ChanceJs plugin could be omited since it's only used to verify the correct working for any case.
let Chance = require('chance'); // Plugin to generate content random
let chance = new Chance();
let text = chance.paragraph(); // Generating paragraph random