Skip to content

Instantly share code, notes, and snippets.

@gabrielstelmach
gabrielstelmach / BruteForceDiscover.bat
Created June 22, 2023 19:31
Attempts to switch Logitech device to channel 2 using all possible values
@echo off
setlocal EnableDelayedExpansion
rem Run trough values 0 to 31 in hex for position C
for /L %%a in (0, 1, 31) do (
for /F %%b in ('DecToHex.bat %%a') do (
@set "hex_c=%%b"
rem Pad left 0
if "%%a" lss 16 (
@set "hex_c=0!hex_c!"
@gabrielstelmach
gabrielstelmach / DecToHex.bat
Created June 22, 2023 19:28
Batch script to convert decimal in hexa values
@echo off & setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set LOOKUP=0123456789abcdef &set HEXSTR=&set PREFIX=
if "%1"=="" echo 0&goto :EOF
set /a A=%* || exit /b 1
if !A! LSS 0 set /a A=0xfffffff + !A! + 1 & set PREFIX=f
:loop
set /a B=!A! %% 16 & set /a A=!A! / 16
set HEXSTR=!LOOKUP:~%B%,1!%HEXSTR%
if %A% GTR 0 goto :loop
echo %PREFIX%%HEXSTR%
@gabrielstelmach
gabrielstelmach / gist:ee8d1b904acb4ad17027ed5901be37ae
Created April 9, 2021 04:16
Search for a specific text in the whole Oracle schema
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;
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 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
(
@gabrielstelmach
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,
CONSTRAINT_NAME varchar(255) NULL,
@gabrielstelmach
gabrielstelmach / NumericUtils.java
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
gabrielstelmach / TimeUtils.java
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
gabrielstelmach / Utils.java
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
{
try
@gabrielstelmach
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);