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 / getAbsolutePath.js
Created September 19, 2012 16:18
Get Absolute Path (JavaScript)
function getAbsolutePath(url) {
return url.match(/^\w+:\/\/[^\/]+\/*(?:[^\/\.]+(?:\r|\/+))*/)[0];
}
@leodutra
leodutra / CacheControlFilter.java
Last active November 8, 2015 14:13
Filtro para controle de cache de resources para Servlets 2.3+ (Websphere 5+)
/**/
package com.github.leodutra.filters;
import java.io.IOException;
import java.util.Date;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
@leodutra
leodutra / check-object-permission.sh
Last active November 8, 2015 14:15
Check file/folder owner and permissions on Linux shell
#!/bin/sh
ls -ld /.
@leodutra
leodutra / request-animation-frame-polyfill.js
Last active December 3, 2015 14:52 — forked from paulirish/rAF.js
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
@leodutra
leodutra / videos interessantes
Created December 6, 2015 00:52
videos interessantes sobre ciencia
UM POUCO DE CIÊNCIA DA COMPUTAÇÃO PARA O FERIADO...
------------------------------------------------------------------
1 - ÁTOMO
https://www.youtube.com/watch?v=TW1HTyTissw
2 - ELETRICIDADE
https://www.youtube.com/watch?v=VfuoAHOe7j0
3 - CONDUTORES ELÉTRICOS
https://www.youtube.com/watch?v=Szj09sb8uoU
4 - SINAL ANALÓGICO
https://www.youtube.com/watch?v=i_Y8Tya_qf8
@leodutra
leodutra / utils-number-base.js
Last active December 7, 2015 17:18
JavaScript decimal, hexadecimal, octal, binary manipulation.
function baseTobase(n, base1, base2) {
return parseInt(n, base1).toString(base2);
}
function decToHex(n) {
// more about >>> for negatives
// here: http://stackoverflow.com/a/17106974/1260526
// here: https://en.wikipedia.org/wiki/Two%27s_complement
// and here: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_shift_operators
return (n >>> 0).toString(16);
@leodutra
leodutra / iso-3166-1-list-scrapper
Last active December 8, 2015 03:28
Wikipedia ISO 3166-1 code list scrapper (https://en.wikipedia.org/wiki/ISO_3166-1)
var res = []
$('.wikitable').first().find('tbody tr').each(function() {
var $td = $(this).find('td')
res.push({
englishShortName: $td.eq(0).find('a').first().text(),
ISO_3166_1_Alpha_2_code: $td.eq(1).text(),
ISO_3166_1_Alpha_3_code: $td.eq(2).text(),
ISO_3166_1_Numeric_3_code: $td.eq(3).text() });
@leodutra
leodutra / toUnicode.js
Last active December 15, 2015 03:39
Converts Array, String or Number to Unicode String
function toUnicode(val/* :Array|Number|String */) {
var res = '';
var type = $.type(val);
var i;
switch(type) {
case 'array':
val = s.join('');
case 'string':
case 'number':
i = (val + '').length;
@leodutra
leodutra / Web References
Last active December 15, 2015 04:59
JavaScript & Web Related References
JAVASCRIPT, CSS, HTML5 AND WEB RELATED REFERENCES
=================================================
FIXES AND HACKS
---------------
HTML5 DOCTYPE <------------ HTML5 DOCTYPE IS TOTALLY CROSS-COMPATIBLE WITH IE 5.5, 6, 7, 8, 9, 10, 11, ... !!!
<!DOCTYPE html>
(yeah! just that!)
@leodutra
leodutra / htmlSpecialCharsEntityEncode
Last active December 15, 2015 06:19
Encodes (escapes) HTML Special Chars
function htmlSpecialCharsEntityEncode(str) {
return str.replace(/[<>&\r\n"']/gm, function (match) {
return '&' + {
'<': 'lt;',
'>': 'gt;',
'&': 'amp;',
'\r': "#13;",
'\n': "#10;",
'"': 'quot;',
"'": 'apos;' /*single quotes just to be safe*/