Skip to content

Instantly share code, notes, and snippets.

@gabrielstelmach
gabrielstelmach / gist:ee8d1b904acb4ad17027ed5901be37ae
Created Apr 9, 2021
Search for a specific text in the whole Oracle schema
View gist:ee8d1b904acb4ad17027ed5901be37ae
set serveroutput on size 100000;
declare
--Text to find, case insensitive. Use % for like.
V_TEXT varchar(50) := '%what I want to locate%';
--Tables schema
V_SCHEMA varchar(50) := 'SCHEMA_NAME';
--List of tables to skip; comma-separated or NONE
V_SKIP_NAMES varchar(200) := 'NONE';
--Using temporary table
V_TEMPORARY_TABLE number := 0;
View PostgreSQL-Search_contents.sql
DO $$ <<lookup_contents>>
DECLARE
_search VARCHAR := 'something'; --what are you looking for?
_limit INTEGER := 1000000;
_total_columns INTEGER := 0;
_total_read INTEGER := 0;
_mark INTEGER;
_text_columns REFCURSOR;
_text_column RECORD;
_address_columns REFCURSOR;
@gabrielstelmach
gabrielstelmach / SQLServer.sql
Last active Oct 27, 2020
Script to search in the whole database for columns with a specific value.
View SQLServer.sql
DECLARE @search_column VARCHAR(255);
DECLARE @search_value VARCHAR(255);
DECLARE @search_type INT; /* 1: specific column 2: string columns 3: numeric columns */
SET @search_column = 'SEARCHING_COLUMN_NAME'; --wrap with %% for wider search
SET @search_value = 'Any value'; --wrap with %% for wider search
SET @search_type = 1;
DECLARE @containing_tables TABLE
(
@gabrielstelmach
gabrielstelmach / data_replication.sql
Created Apr 14, 2019
SQL Server script to replicate all data from a remote database to a local database.
View data_replication.sql
/*
Replicates all data from the remote database to the local database. The local contents are removed, all current local data is erased and not recoverable.
You have to set the value for @LINKED_SERVER_NAME as your local Linked Server name for the remote SQL Server instance.
*/
print 'Starting replication...';
--Control for structure alterations over the process
declare @CONTROL_TABLES table
(
TABLE_NAME varchar(255) NOT NULL,
CONSTRAINT_NAME varchar(255) NULL,
@gabrielstelmach
gabrielstelmach / NumericUtils.java
Created Dec 13, 2017
Simple method to evaluate numeric values
View NumericUtils.java
/**
* Identify a numeric value.
*
* @param value Value to be evaluated.
* @param digits May use digits or not.
* @return True when the value is a numeric representation.
*/
public static boolean isNumeric(String value, boolean digits)
{
String unmarked = value;
@gabrielstelmach
gabrielstelmach / TimeUtils.java
Last active Dec 9, 2017
Formatting a specific amount of time in a friendly way
View TimeUtils.java
/**
* Formats the amount of time in a friendly way.
*
* @param millis Amount of time in milliseconds.
* @param nicly When the amount of time is less than 1 minute, the message will be cool.
* @return Friendly description of the amount of time.
*/
public static String friendlyAmountTime(long millis, boolean nicly)
{
long hours = TimeUnit.MILLISECONDS.toHours(millis);
@gabrielstelmach
gabrielstelmach / Utils.java
Created Dec 8, 2017
Extracting readable XML of JAXBElement
View Utils.java
/**
* Extract the XML content, human friendly, of the <b>JAXBElement</b> object.
*
* @param object Object JAXBElement
* @return XML content
* @throws Exception Will be thrown always when object is not a valid JAXB instance.
*/
public static String extractXMLFromJAXBObject(Object object) throws Exception
{
try
@gabrielstelmach
gabrielstelmach / utils.js
Created Dec 5, 2017
Sort an array of <option>' tag by its name
View utils.js
var options = ["<option value='2'>Green</option>","<option value='1'>Red</option>","<option value='3'>Blue</option>"];
options.sort(function (option1, option2)
{
var name1 = option1.toUpperCase();
var name2 = option2.toUpperCase();
name1 = name1.substr((name1.indexOf(">") + 1)).substr(0, name1.substr((name1.indexOf(">") + 1)).indexOf("<"));
name2 = name2.substr((name2.indexOf(">") + 1)).substr(0, name2.substr((name2.indexOf(">") + 1)).indexOf("<"));
return name1.localeCompare(name2);
@gabrielstelmach
gabrielstelmach / Utils.java
Created Dec 5, 2017
Sorting entries of Map by entry value
View Utils.java
/**
* Orders the map entries by value.
*
* @param map Map with entries to be ordered.
* @return Map ordered by its value.
*/
public static <K, V extends Comparable<? super V>> LinkedHashMap<String, String> orderedMapByValues(Map<K, V> map)
{
SortedSet<Map.Entry<K, V>> orderedEntries = new TreeSet<Map.Entry<K, V>>(new Comparator<Map.Entry<K, V>>()
{
@gabrielstelmach
gabrielstelmach / Utils.java
Created Nov 28, 2017
Retrives a friendly formated byte count
View Utils.java
/**
* Retrieves the friendly format of the number of bytes.<br>
* Is possible to convert it using decimal base, applying <b>International System of Units (SI)</b>, or binary system.
* As result you get:
* <ul>
* <li>Following SI: 1 kB, 1 MB, 1 GB, 1 TB, 1 PB e 1 EB</li>
* <li>Binary system: 1 KiB, 1 MiB, 1 GiB, 1 TiB, 1 PiB, e 1 EiB</li>
* </ul>
* References:
* <ul>