Skip to content

Instantly share code, notes, and snippets.

View avitorio's full-sized avatar
🕶️
🌴

Andre Vitorio avitorio

🕶️
🌴
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@avitorio
avitorio / truncate-string.js
Created January 16, 2019 15:52
Truncate string without cutting words in Javascript.
// From @NT3RP on https://stackoverflow.com/questions/5454235/shorten-string-without-cutting-words-in-javascript
var yourString = "The quick brown fox jumps over the lazy dog"; //replace with your string.
var maxLength = 6 // maximum number of characters to extract
//trim the string to the maximum length
var trimmedString = yourString.substr(0, maxLength);
//re-trim if we are in the middle of a word
trimmedString = trimmedString.substr(0, Math.min(trimmedString.length, trimmedString.lastIndexOf(" ")))
@avitorio
avitorio / truncate-text.php
Created April 13, 2019 11:35
Truncate text in PHP
// Taken from https://stackoverflow.com/a/79986/4187621
function tokenTruncate($string, $your_desired_width) {
$parts = preg_split('/([\s\n\r]+)/u', $string, null, PREG_SPLIT_DELIM_CAPTURE);
$parts_count = count($parts);
$length = 0;
$last_part = 0;
for (; $last_part < $parts_count; ++$last_part) {
$length += strlen($parts[$last_part]);
if ($length > $your_desired_width) { break; }
module.exports = {
env: {
es6: true,
jest: true,
browser: true
},
extends: ["airbnb", "prettier", "prettier/react"],
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
docker run --name postgres -e POSTGRES_PASSWORD=password -p 5432:5432 -d -t postgres
docker run --name mongo -p 27017:27017 -d -t mongo
docker run --name redis -p 6379:6379 -d -t redis:alpine
docker exec -i -t postgres /bin/sh
su postgres
CREATE DATABASE bootcampnodejs;
\q
exit
exit
function smoothScrollByViewports(herodelay, viewports, duration) {
// Hide scrollbar
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = `html::-webkit-scrollbar { width: 0px; }`;
document.getElementsByTagName('head')[0].appendChild(style);
var start = null;
var initialScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var distanceToScroll = window.innerHeight * viewports;