Skip to content

Instantly share code, notes, and snippets.

View babacarMbengue12's full-sized avatar

Babacar Mbengue babacarMbengue12

View GitHub Profile
@z2015
z2015 / float.md
Created May 12, 2016 05:46
ceil vs floor vs round

The Math.ceil() function returns the smallest integer greater than or equal to a given number. Math.ceil(.95); // 1 Math.ceil(4); // 4 Math.ceil(7.004); // 8

The Math.floor() function returns the largest integer less than or equal to a given number. Math.floor( 45.95); // 45 Math.floor(-45.95); // -46

The Math.round() function returns the value of a number rounded to the nearest integer.

@babacarMbengue12
babacarMbengue12 / paginate.js
Created June 12, 2022 22:14
Paginate data using lodash support typescript and javascript
import _ from "lodash";
function paginate(
items,
page=1,
pageSize = 100
){
const offset = (page - 1) * pageSize;
const pagedItems = _.drop(items, offset).slice(0, pageSize);
return {
@babacarMbengue12
babacarMbengue12 / verify_token.js
Created June 24, 2022 22:37
javascript verify if user token is expired
import jwtDecode from "jwt-decode";
function dateFromUnix(unix){
return new Date(unix * 1000)
}
function isTokenExpired(token: string,unixField="exp"){
if (token) {
const decoded = jwtDecode(token);
const exp = decoded[unixField]
return dateFromUnix(exp) < new Date()