Skip to content

Instantly share code, notes, and snippets.

gabrielstelmach /
Created November 28, 2017 18:57
Retrives a friendly formated byte count
* 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>
gabrielstelmach /
Created December 5, 2017 19:43
Sorting entries of Map by entry value
* 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 / utils.js
Created December 5, 2017 19:50
Sort an array of <option>' tag by its name
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 /
Created December 8, 2017 21:24
Extracting readable XML of JAXBElement
* 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
gabrielstelmach /
Last active December 9, 2017 15:57
Formatting a specific amount of time in a friendly way
* 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 /
Created December 13, 2017 22:30
Simple method to evaluate numeric values
* 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 / data_replication.sql
Created April 14, 2019 23:01
SQL Server script to replicate all data from a remote database to a local database.
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,
gabrielstelmach / SQLServer.sql
Last active October 27, 2020 02:10
Script to search in the whole database for columns with a specific value.
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
DO $$ <<lookup_contents>>
_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 / gist:ee8d1b904acb4ad17027ed5901be37ae
Created April 9, 2021 04:16
Search for a specific text in the whole Oracle schema
set serveroutput on size 100000;
--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;