Simple way to detect browser’s FPS via JS
It’s dumb and dead simple but works. You can even track browser’s metrics with that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
(() => { const times = []; let fps; function refreshLoop() { window.requestAnimationFrame(() => { const now = performance.now(); while (times.length > 0 && times[0] <= now - 1000) { times.shift(); } times.push(now); fps = times.length; refreshLoop(); }); } refreshLoop(); // output to console once per second setInterval(() => {console.log(fps);}, 1000) })(); |
Mocking for testing go code
If you’re testing go code and have a huge API you have to mock, you have two options: make your dummy struct with embedded interface and implement only methods you need, or use your own interface that has only methods you need (and change your code to use that). For instance, I had amazon’s s3 …
BDD Framework For Golang
There is a good one: https://github.com/onsi/ginkgo It prefers to use http://onsi.github.io/gomega/ as a matcher.
Golang, PostgreSQL and array_agg
If you have SQL like this:
Microservice architecture patterns
Why do you need a microservice architecture? Decrease blast radius of problems and increase flexibility. You want technology diversity in your company. You want to scale your app more granular according to consumer needs. You want newcomers to be productive earlier. You want your company structure to be mirrored with technical responsibilities (it’s mainly about …
Postgresql: style guide for DataGrip
Place it into xml file and import into DataGrip or another jetbrains’ product
PostgreSQL: using indices on json fields
It’s obviously a really bad idea. But if you really need it, that’s what you can do.
Postgresql: show all locked queries
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
WITH RECURSIVE l AS ( SELECT pid, locktype, mode, granted, ROW(locktype,database,relation,page,tuple,virtualxid,transactionid,classid,objid,objsubid) obj FROM pg_locks ), pairs AS ( SELECT w.pid waiter, l.pid locker, l.obj, l.mode FROM l w JOIN l ON l.obj IS NOT DISTINCT FROM w.obj AND l.locktype=w.locktype AND NOT l.pid=w.pid AND l.granted WHERE NOT w.granted ), tree AS ( SELECT l.locker pid, l.locker root, NULL::record obj, NULL AS mode, 0 lvl, locker::text path, array_agg(l.locker) OVER () all_pids FROM ( SELECT DISTINCT locker FROM pairs l WHERE NOT EXISTS (SELECT 1 FROM pairs WHERE waiter=l.locker) ) l UNION ALL SELECT w.waiter pid, tree.root, w.obj, w.mode, tree.lvl+1, tree.path||'.'||w.waiter, all_pids || array_agg(w.waiter) OVER () FROM tree JOIN pairs w ON tree.pid=w.locker AND NOT w.waiter = ANY ( all_pids ) ) SELECT (clock_timestamp() - a.xact_start)::interval(3) AS ts_age, replace(a.state, 'idle in transaction', 'idletx') state, (clock_timestamp() - state_change)::interval(3) AS change_age, a.datname,tree.pid,a.usename,a.client_addr,lvl, (SELECT count(*) FROM tree p WHERE p.path ~ ('^'||tree.path) AND NOT p.path=tree.path) blocked, repeat(' .', lvl)||' '||left(regexp_replace(query, '\s+', ' ', 'g'),100) query FROM tree JOIN pg_stat_activity a USING (pid) ORDER BY path; |
Smart Home systems
There are quite a lot of that systems: MajorDoMo OpenHab Iobroker Domoticz HomeAssistant The most interesting ones are: Iobroker (Node.js-based) HomeAssistant (based on Python 3)
Install exact version via brew
For instance, we’re looking for kubernetes-helm@2.9 helm 2.9
1 2 3 4 5 6 |
git -C "$(brew --repo homebrew/core)" fetch --unshallow cd "$(brew --repo homebrew/core)" git log Formula/kubernetes-helm.rb # searching for 2.9.0 with a command /2\.9\.0 and copying hash like "7ade79f13b4bbcc6126803245594d97b2abbe2fa" git checkout -b kubernetes-helm@2.9.0 7ade79f13b4bbcc6126803245594d97b2abbe2fa HOMEBREW_NO_AUTO_UPDATE=1 brew install kubernetes-helm |
Now we have needed version of helm. If you see an error message like Error: go: unknown version :mountain_lion, you should make a little hack (as it said here). Check all the files depending on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
grep 'depends_on :macos => :mountain_lion' Formula/* # you'll see something like Formula/bashdb.rb: depends_on :macos => :mountain_lion Formula/chrome-cli.rb: depends_on :macos => :mountain_lion Formula/clipsafe.rb: depends_on :macos => :mountain_lion Formula/go.rb: depends_on :macos => :mountain_lion Formula/go@1.8.rb: depends_on :macos => :mountain_lion Formula/go@1.9.rb: depends_on :macos => :mountain_lion Formula/ios-sim.rb: depends_on :macos => :mountain_lion Formula/mesos.rb: depends_on :macos => :mountain_lion Formula/mongodb.rb: depends_on :macos => :mountain_lion Formula/mongodb@3.0.rb: depends_on :macos => :mountain_lion Formula/mongodb@3.2.rb: depends_on :macos => :mountain_lion Formula/mongodb@3.4.rb: depends_on :macos => :mountain_lion ... |
In each file just comment a string saying depends_on :macos …