Skip to content

Instantly share code, notes, and snippets.

View KrashLeviathan's full-sized avatar

Nathan Karasch KrashLeviathan

View GitHub Profile
@KrashLeviathan
KrashLeviathan / regex-negative-lookahead-with-wildcard.md
Created September 1, 2023 13:25
Regex use case: Locating an HTML element that does NOT contain a given attribute

Negative Lookahead with Wildcard

This regular expression looks for <input> elements in HTML that do not contain the string "fieldSize". Presumably, you might want to look where all such elements are located in a code base so that you can add that attribute to each of them. This could be extended to other use cases as well.

<input(?![\s\S]+fieldSize)[^>]+>
@KrashLeviathan
KrashLeviathan / oracle_long_op_monitoring.sql
Created August 23, 2021 15:43
Execute and monitor a long-running Oracle PL/SQL operation
-- Monitoring query (run in a different session than the long-op is running in):
SELECT opname,
target_desc,
sofar,
totalwork,
units,
elapsed_seconds,
time_remaining
FROM v$session_longops
WHERE opname = 'Item Updates';
@KrashLeviathan
KrashLeviathan / oracle_source_search.sql
Created July 8, 2021 19:50
Oracle SQL query to search all source code for the given :search_text
WITH p AS ( SELECT lower('%' || :search_text || '%') as pattern FROM dual )
SELECT
name, type, line, text
FROM
( SELECT name AS name, type AS type, line AS line, text AS text
FROM user_source join p on lower(text) like p.pattern
UNION ALL
SELECT view_name, 'VIEW', 0, text_vc
FROM user_views join p on lower(text_vc) like p.pattern
UNION ALL
@KrashLeviathan
KrashLeviathan / package_ddl_script_example.sql
Created March 26, 2021 22:17
EXAMPLE: Scripting package DDL changes to run in SQL Developer console
DECLARE
l_example_pkg_spec VARCHAR2(32767) := q'~
create or replace package EXAMPLE_PKG AS
-- spec definition here
end;
~';
l_example_pkg_body VARCHAR2(32767) := q'~
create or replace package body EXAMPLE_PKG AS
@KrashLeviathan
KrashLeviathan / plsql_wrapping_example.sql
Created March 26, 2021 22:07
EXAMPLE: Wrapping (obfuscating) a PL/SQL package body
-- Documentation: https://docs.oracle.com/en/database/oracle/oracle-database/18/lnpls/plsql-source-text-wrapping.html
-- One thing to keep in mind (that I didn't find in the docs) is that later, if you want to
-- update the variables in the package spec and re-compile the spec and the wrapped body, you can do
-- that in SQL Developer without having to re-wrap the original source code. Just open up
-- the wrapped body and click the Compile button.
-- Create package specification without obfuscation
create or replace PACKAGE HELLO_PKG AS
@KrashLeviathan
KrashLeviathan / hashset_demo.sql
Created October 23, 2020 19:38
PL/SQL - Discarding duplicates when processing an array of data by maintaining a hashset (technically a map) of processed inputs
/*
This PL/SQL block demonstrates the use of an associative array and
the STANDARD_HASH function to discard duplicates when processing
an array of inputs from a PL/SQL array (VARRAY).
Written for & tested on an Oracle 12c database.
*/
@KrashLeviathan
KrashLeviathan / queries_are_equivalent.sql
Last active January 6, 2020 20:44
Check to see if two SELECT statements are equivalent in SQL
-- Found this in the following StackOverflow post and found it useful on multiple occasions
-- https://stackoverflow.com/questions/5727882/check-if-two-selects-are-equivalent
WITH query1 AS
(
-- Copy/paste SELECT statement here
),
query2 AS
(
-- Copy/paste SELECT statement here
@KrashLeviathan
KrashLeviathan / logout-cleanup-component.ts
Created June 12, 2019 13:17
This Angular 7 class and decorator can be used to perform component cleanup actions when a user logs out.
import {OnDestroy, OnInit} from '@angular/core';
import {AuthService} from '../service/auth/auth.service';
import {Subscription} from 'rxjs';
/**
* To use this class and the decorator below (must be used together):
*
* @CleanupAfterLogout()
* @Component({
@KrashLeviathan
KrashLeviathan / myCollector.js
Created March 20, 2019 16:28
Used to collect data from Squarespace analytics charts (or any react chart tooltips for that matter)
myCollector = {
data: {},
intervalId: 0,
intervalMillis: 5,
selectors: {
container: '.react-charts-tooltip',
header: '.react-charts-tooltip-header',
rows: '.react-charts-tooltip-row'
},
start: function() {
@KrashLeviathan
KrashLeviathan / bash_template.sh
Last active July 6, 2022 16:53
Bash Script Template
#!/usr/bin/env bash
#
# TODO: This script does ... something
# The equivalent of "use strict"; makes bash a little less error prone
set -euo pipefail
# Pretty-prints the input with the prefix [SCRIPT_NAME]
echoo() { echo -e "\e[33m[${SCRIPT_NAME}] $@ \e[0m"; }