Skip to content

Instantly share code, notes, and snippets.

View leodutra's full-sized avatar
🦙
Llama and other LLMs

Leo Dutra leodutra

🦙
Llama and other LLMs
View GitHub Profile
@leodutra
leodutra / limitStringBy.js
Last active August 23, 2019 23:03
Limit String Size - JavaScript
function limitStringBy (num, str, complement) {
if (str.length > num) {
const k = str.substr(0, num).lastIndexOf('\u0020')
return str.substr(0, k !== -1 ? k : num) + (complement || '...')
}
return str
}
@leodutra
leodutra / crossBrowserFullScreen.js
Last active December 21, 2015 17:58
crossBrowserFullScreen.js - Try fullscreen mode on most browsers. HTML5 alternatives only work when bound to an interaction event (click/ keyboard/ etc).
/*
Copyright 2013 Leonardo Dutra Constancio.
https://gist.github.com/LeoDutra/ - leodutra.br@gmail.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
@leodutra
leodutra / float-group.css
Last active December 23, 2015 00:39
ClearFix CSS. Forces height on a container of "floater elements".
/* source: http://css-tricks.com/snippets/css/clear-fix/ */
.float-group:after {
visibility: hidden;
display: block;
content: "";
clear: both;
height: 0;
}
* html .float-group { zoom: 1; } /* IE6 */
@leodutra
leodutra / toCharEntity.js
Last active December 27, 2015 17:29
Text to HTML char entities.
function toCharEntity(str, useHexa) {
if (str !== undefined && str !== null) {
str = '' + str;
var codeCache;
var res = '';
for(var i = 0, l = str.length; i < l ;) {
res += '&#';
codeCache = str.charCodeAt(i++);
res += useHexa ? 'x' + codeCache.toString('16') : codeCache;
res += ';';
@leodutra
leodutra / overflow-fix.css
Last active December 29, 2015 17:39
Overflow fix.
/* http://css-tricks.com/the-css-overflow-property/ */
.scroll-x {
overflow-x: auto;
-ms-overflow-x: auto;
}
.scroll-y {
overflow-y: auto;
-ms-overflow-y: auto;
}
@leodutra
leodutra / removeDiacritics.js
Last active June 7, 2021 01:49
Remove diacritics from character strings.
// SOURCE: http://stackoverflow.com/a/5912746/1260526
const diacriticsMap = [
{'base':'A', 'letters':/[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/gm},
{'base':'AA','letters':/[\uA732]/gm},
{'base':'AE','letters':/[\u00C6\u01FC\u01E2]/gm},
{'base':'AO','letters':/[\uA734]/gm},
{'base':'AU','letters':/[\uA736]/gm},
{'base':'AV','letters':/[\uA738\uA73A]/gm},
{'base':'AY','letters':/[\uA73C]/gm},
{'base':'B', 'letters':/[\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181]/gm},
@leodutra
leodutra / iframe-reference.html
Last active August 29, 2015 14:00
IFrame Default Attributes Reference + Scroll Definition (IE 8- Fix)
<!--
seamless="seamless" - Specifies that the <iframe> should look like it is a part of the containing document
allowTransparency="true" - old "seamless" alternative (is not a W3C spec/ option)
frameborder="0" - no border on old browsers (deprecated on HTML5)
scrolling="auto" - Specifies whether or not to display scrollbars in an <iframe> (deprecated on HTML5)
horizontalscrolling - force hide horizontal scrolling on (IE fix)
verticalscrolling - force hide vertical scrolling on (IE fix)
AUTO RESIZE IFRAME
https://github.com/davidjbradshaw/iframe-resizer
@leodutra
leodutra / simple-crawler.js
Last active May 23, 2017 16:15
Simple JavaScript Cralwer (js, crawler, javascript)
/*
JavaScript Link Crawler
author: Leonardo Dutra (leodutra.br@gmail.com)
Instructions: open browser console, paste, run.
*/
var limit = 30000; // limite de links encontrados
@leodutra
leodutra / fullEncodeURI.js
Last active August 29, 2015 14:05
Fully Encode URI/URL
function fullEncodeURI(str) {
if (str !== undefined && str !== null) {
str = '' + str;
var res = '';
for(var i = 0, l = str.length; i < l ;) {
res += '%';
res += str.charCodeAt(i++).toString('16');
}
return res;
}
@leodutra
leodutra / bitwise-hacks.js
Last active October 30, 2023 02:37
Fast Int Math + Bitwise Hacks For JavaScript
// http://michalbe.blogspot.com.br/2013/03/javascript-less-known-parts-bitwise.html
// http://jsperf.com/bitwise-vs-math-object
// http://united-coders.com/christian-harms/results-for-game-for-forfeits-and-the-winner-is/
// https://mudcu.be/journal/2011/11/bitwise-gems-and-other-optimizations/
// https://dreaminginjavascript.wordpress.com/2009/02/09/bitwise-byte-foolish/
// http://jsperf.com/math-min-max-vs-ternary-vs-if/24
"use strict";
var PI = Math.PI;