Kotlin prepend element

I think the easiest would be to write: var list = listOf(2,3) println(list) // [2, 3] list = listOf(1) + list println(list) // [1, 2, 3] There is no specific tail implementation, but you can call .drop(1) to get the same. You can make this head\tail more generic by writing these extension properties: val <T> …

Read more

SQL INSERT based on SELECT results

INSERT INTO table (field) SELECT ‘1stString.’ + cast(id as varchar(50)) + ‘.2ndString’ FROM table2 WHERE id = 10 Edit – response to comment: You’re on the right track, but you want to select your hard-coded strings from your table, like this: INSERT INTO table1 (field1, field2, field3) SELECT ‘1stVal’, ‘2ndVal’, ‘1stString.’ + cast(id as varchar(50)) …

Read more

Insert element in Python list after every nth element

I’ve got two one liners. Given: >>> letters = [‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’] Use enumerate to get index, add ‘x’ every 3rd letter, eg: mod(n, 3) == 2, then concatenate into string and list() it. >>> list(”.join(l + ‘x’ * (n % 3 == 2) for n, l in enumerate(letters))) [‘a’, ‘b’, ‘c’, ‘x’, ‘d’, ‘e’, ‘f’, ‘x’, …

Read more

Java + Mysql UTF8 Problem

Solved, I forgot to add the encoding when initializing Connection: before was: con = DriverManager.getConnection(“jdbc:mysql:///dbname”, “user”, “pass”); now (working): con = DriverManager.getConnection(“jdbc:mysql:///dbname?useUnicode=true&characterEncoding=utf-8”, “user”, “pass”);