Skip to content

Instantly share code, notes, and snippets.

View leo-from-spb's full-sized avatar

Leonid Bushuev leo-from-spb

  • JetBrains
  • München
View GitHub Profile
@leo-from-spb
leo-from-spb / deduplicate-case-insensitive.kt
Created June 2, 2022 21:03
How to de-duplicate a list of strings
class X {
private val obst = listOf("Apple", "Pear", "Pear", "PEAR", "APPLE", "APRICOT", "Apple")
@Test
fun deduplicateCaseInsensitively_1() {
val deduplicated = obst.asSequence().sortedWith(String.CASE_INSENSITIVE_ORDER).fold(ArrayList<String>(obst.size)) { a, o ->
if (a.isEmpty() || !a.last().equals(o, true)) a += o
a
}
println(deduplicated)
When a user write a database creation script, they give names for most of database objects (i.e. table names,
column names, constraint names, etc). When the DB author performs this script using a DBMS it creates a database
that contains objects with the names specified in the script. If the author perfroms this script several times,
the result will be several database with the same object names (as specified in the script).
However, sometimes the DB author can omit some names (i.e. names of constraints, indices, etc.), in this case
the DBMS makes names for these objects automatically (usually by concatenating a hardcoded prefix with a kind of
random or sequential number). When the author performs their script several times, the result will be databases
with different names (because that names were not specified in the script). We call such auto-genertated names
synthetic ones. So, the mentioned option includes such auto-generated stuff.
@leo-from-spb
leo-from-spb / Билд-завис.txt
Created June 19, 2018 18:10
Билд завис
2018-06-19 21:00:31
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.171-b11 mixed mode):
"Attach Listener" #29 daemon prio=9 os_prio=0 tid=0x00007fd748001000 nid=0x28cf waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"DestroyJavaVM" #28 prio=5 os_prio=0 tid=0x00007fd774017800 nid=0x20c8 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"TimerQueue" #25 daemon prio=5 os_prio=0 tid=0x00007fd72527b000 nid=0x210a waiting on condition [0x00007fd72275d000]
@leo-from-spb
leo-from-spb / SQL-Inserts-MultirowSynthax.sql.groovy
Last active November 5, 2024 07:56
DataGrip data exporting script
SEP = ", "
QUOTE = "\'"
NEWLINE = System.getProperty("line.separator")
begin = true
def record(columns, dataRow) {
if (begin) {
OUT.append("INSERT INTO ")
@leo-from-spb
leo-from-spb / fun42.sql
Created October 23, 2017 14:36
Postgres function result record
create function fun42(a integer, b integer, OUT c bigint, OUT d character varying)
returns record
language plpgsql
as $$
begin
c = a + b;
d = c::varchar;
end;
$$;
@leo-from-spb
leo-from-spb / idea_modifies_files_again_20171019.patch
Created October 19, 2017 11:55
Idea modifies files again :(
Index: .idea/codeStyles/codeStyleConfig.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- .idea/codeStyles/codeStyleConfig.xml (date 1508413887000)
+++ .idea/codeStyles/codeStyleConfig.xml (date 1508413887000)
@@ -0,0 +1,5 @@
+<component name="ProjectCodeStyleConfiguration">
+ <state>