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 / fill-bits-from-right.js
Last active December 21, 2015 15:37
Fast fill bits from right - JavaScript bitwise function
function fillBitsFromRight(n) { // http://jsperf.com/fill-bits-bitwise-vs-alternatives
return ~(-1 << n); // ~(~0 << n)
}
@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 / buffer-arraybuffer.js
Last active December 21, 2015 22:41
Node.js Buffer -> ArrayBuffer -> Buffer conversion / cloning functions
function toArrayBuffer(buffer) {
const ab = new ArrayBuffer(buffer.length);
const view = new Uint8Array(ab);
for (var i = 0, l = buffer.length; i < l; i++) {
view[i] = buffer[i];
}
return ab;
}
function toBuffer(ab/*:ArrayBuffer*/) {
@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 / string-repeat.js
Created December 28, 2015 04:23
String repeat polyfill for JavaScript
function repeat(str, times) {
var n = times | 0;
var res = '';
var buffer = str;
for (;;) {
if (n & 1) res += buffer;
if (n >>= 1) buffer += buffer;
else break;
}
return 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;
}
UF Municipio
GO Abadia de Goiás
MG Abadia dos Dourados
GO Abadiânia
MG Abaeté (Minas Gerais)|Abaeté
PA Abaetetuba
CE Abaiara
BA Abaíra
BA Abaré
@leodutra
leodutra / fast remove files windows
Last active January 12, 2016 15:36
Remove folders and files in Windows
The worst way is to send to Recycle Bin: you still need to delete them. Next worst is shift+delete with Windows Explorer: it wastes loads of time checking the contents before starting deleting anything.
Next best is to use rmdir /s/q foldername from the command line. del /f/s/q foldername is good too, but it leaves behind the directory structure.
The best I've found is a two line batch file with a first pass to delete files and outputs to nul to avoid the overhead of writing to screen for every singe file. A second pass then cleans up the remaining directory structure:
del /f/s/q foldername > nul
rmdir /s/q foldername
This is nearly three times faster than a single rmdir, based on time tests with a Windows XP encrypted disk, deleting ~30GB/1,000,000 files/15,000 folders: rmdir takes ~2.5 hours, del+rmdir takes ~53 minutes. More info at Super User.
@leodutra
leodutra / municipios-brasileiros-2016-01-05.sql
Last active January 25, 2016 19:57
Municípios brasileiros extraídos da Wikipedia e do IBGE 2016-01-05 SQL
CREATE TABLE IF NOT EXISTS `pais` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(60) DEFAULT NULL,
`sigla` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
INSERT INTO `pais` (`id`, `nome`, `sigla`) VALUES (1, 'Brasil', 'BR');