Skip to content

Instantly share code, notes, and snippets.

View djom202's full-sized avatar

Jonathan Olier djom202

View GitHub Profile
@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
@djom202
djom202 / number_format.js
Created March 15, 2018 22:56
Function to give them format an numbers. #javascript #numbers
function number_format(amount, decimals) {
amount += ''; // por si pasan un numero en vez de un string
amount = parseFloat(amount.replace(/[^0-9\.]/g, '')); // elimino cualquier cosa que no sea numero o punto
decimals = decimals || 0; // por si la variable no fue fue pasada
// si no es un numero o es igual a cero retorno el mismo cero
if (isNaN(amount) || amount === 0)
return parseFloat(0).toFixed(decimals);
@djom202
djom202 / .htaccess
Created February 19, 2018 23:42
force ssl and redirect to index.php
RewriteEngine On
RewriteBase /
#if the request is not secure
RewriteCond %{HTTPS} off
#redirect to the secure version
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
#These are your existing rules
RewriteCond %{REQUEST_FILENAME} !.(jpg|jpeg|gif|png|css|js|pl|txt)$ [NC]