Skip to content

Instantly share code, notes, and snippets.

View tetri's full-sized avatar
🎯
Focusing

Tetri Mesquita tetri

🎯
Focusing
View GitHub Profile
/*
based on http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript
according to http://jsperf.com/replace-all-vs-split-join/25
*/
if (!String.prototype.replaceAll)
String.prototype.replaceAll = function (str, find, rep) {
return str.replace(new RegExp(find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"), 'g'), rep); //faster for Firefox
return str.split(find).join(rep); //faster for Chrome
}
@tetri
tetri / browser.detection
Created September 30, 2014 11:22
browser detection
// as seen on http://jsfiddle.net/9zxvE/383/
// and http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
// by http://stackoverflow.com/users/938089/rob-w
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Opera 8.0+ (UA detection to detect Blink/v8-powered Opera)
var isFirefox = typeof InstallTrigger !== 'undefined'; // Firefox 1.0+
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
// At least Safari 3+: "[object HTMLElementConstructor]"
var isChrome = !!window.chrome && !isOpera; // Chrome 1+
@tetri
tetri / timeout.cs
Last active April 23, 2019 17:33 — forked from clupasq/timeout.cs
C# Timeout implementation
public void ComputeResultWithTimeout()
{
var task = Task.Factory.StartNew(() => ComputeResult("vrau"));
//task.Wait(0999);
task.Wait(1000);
if (task.IsCompleted)
Console.WriteLine($"oba! {task.Result}");
else
@tetri
tetri / PostgreSQL random boolean
Created September 19, 2019 22:49
PostgreSQL random boolean for generate test values
SELECT RANDOM()::INT::BOOLEAN;
@tetri
tetri / RevertWhitespaceChangesInFolder.ps1
Created May 23, 2024 11:53
Este script em PowerShell automatiza o processo de verificar e descartar alterações em arquivos dentro de uma pasta e suas subpastas em um repositório SVN, quando as diferenças são apenas espaços em branco e quebras de linha extras.
# Parâmetros do script
param (
[string]$folderPath
)
# Função para normalizar o conteúdo do arquivo
function Normalize-Content {
param (
[string]$content
)
@tetri
tetri / sp_conta_filtros.sql
Created July 26, 2024 17:25
Consulta que retorna o número de registros por tabela para o usuário informado.
CREATE OR REPLACE FUNCTION public.sp_conta_filtros(p_idusuario numeric)
RETURNS TABLE(tabela character varying, counttabela numeric, countfiltro numeric)
LANGUAGE plpgsql
AS $function$
declare tabelas record;
conta numeric;
begin
drop table if exists __contafiltro;
CREATE TEMPORARY TABLE __contafiltro
(tabela varchar(255), counttabela decimal(18), countfiltro decimal(18)) WITH ( OIDS=FALSE );