Skip to content

Instantly share code, notes, and snippets.

View kudryashov-sv's full-sized avatar

Sergey Kudryashov kudryashov-sv

View GitHub Profile
@kudryashov-sv
kudryashov-sv / filter-my-ass
Last active November 21, 2018 15:32
filter_test.go
func FilterJunior(s []int) []int {
var pos = 0
for i := 0; i < len(s); i++ {
if s[i]%3 != 0 {
s[pos] = s[i]
pos++
}
}
return s[:pos]
}
@kudryashov-sv
kudryashov-sv / binary.md
Last active September 12, 2018 14:58
Binary search battle

Results

[Go]   dream team search: 10000000 iteration, elapsed time: 539984163 ns, iteration time: 53 ns
[Java] standard search  : 10000000 iteration, elapsed time: 574840969, iteration time: 57 ns
[Java] bob search       : 10000000 iteration, elapsed time: 750649175, iteration time: 75 ns

Versions:

  • Go 1.10.2
  • Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
-module(test).
-compile(export_all).
-record(state, {count, ts, big_dict}).
-define(PRINT_PERIOD, timer:seconds(1)).
run(DictSize, Threshold) ->
Monitor = run_monitor(Threshold),
@kudryashov-sv
kudryashov-sv / .gitignore
Last active August 29, 2015 14:19
Sort stupid
qsort
*.swp
*.class
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 20;
@kudryashov-sv
kudryashov-sv / pg_cte_upsert.txt
Created March 24, 2015 13:11
CTE upsert for postgresql
db=> create table what(id serial primary key, v text);
CREATE TABLE
db=> with upsert as (update what set v='updated value' where id=42 returning *) insert into what(id, v) select 42, 'inserted value' where not exists (select * from upsert);
INSERT 0 1
db=> select * from what;
id | v
----+----------------
42 | inserted value
(1 row)