Skip to content

Instantly share code, notes, and snippets.

View ornicar's full-sized avatar
💭
⏚⏚⏚⏚

Thibault Duplessis ornicar

💭
⏚⏚⏚⏚
View GitHub Profile
@ornicar
ornicar / extension.scala
Last active November 14, 2022 10:02
scala 3 extensions are weird
// scala 3.2.1
extension [String](x: String) def f1 = ???
extension [T](x: Option[T]) def f2 = ???
object A:
def f1(i: Int) = ???
def f2(i: Int) = ???
import A.*
@ornicar
ornicar / a.scala
Created September 29, 2022 10:59
private def exaggerateResults(result: ResultCounts) = {
import result._
val (lower, upper) = (30d, 70d)
val factor = 100d / (upper - lower)
((blackPercent - lower) * factor, drawsPercent * factor, (whitePercent - lower) * factor)
}
"2021-12": {
"black": 357217,
"draws": 33942,
"white": 367111
},
"2022-01": {
"black": 175233,
"draws": 16724,
"white": 179330
},
[info] exception occurred while typechecking /home/thib/lichess-db/src/main/scala/lila/game/BSONHandlers.scala
[info] exception occurred while compiling /home/thib/lichess-db/src/main/scala/LightUser.scala, /home/thib/lichess-db/src/main/scala/Main.scala, /home/thib/lichess-db/src/main/scala/Puzzle.scala, /home/thib/lichess-db/src/main/scala/Reporter.scala, /home/thib/lichess-db/src/main/scala/db.scala, /home/thib/lichess-db/src/main/scala/db/BSON.scala, /home/thib/lichess-db/src/main/scala/db/Handlers.scala, /home/thib/lichess-db/src/main/scala/db/dsl.scala, /home/thib/lichess-db/src/main/scala/lila/ByteArray.scala, /home/thib/lichess-db/src/main/scala/lila/CorrespondenceClock.scala, /home/thib/lichess-db/src/main/scala/lila/Eval.scala, /home/thib/lichess-db/src/main/scala/lila/PerfType.scala, /home/thib/lichess-db/src/main/scala/lila/Sequence.scala, /home/thib/lichess-db/src/main/scala/lila/analyse/Advice.scala, /home/thib/lichess-db/src/main/scala/lila/analyse/Analysis.scala, /home/thib/lichess-db/src/main
{
nbPlayers: 2970,
duels: [
{
id: 'wGHslr9M',
p: [
{ n: 'lizen269', r: 2178, k: 8 },
{ n: 'lizen939', r: 2222, k: 2 }
]
},
var Chessground=function(){"use strict";function e(e){var t={exports:{}};return e(t,t.exports),t.exports}var t=e((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.ranks=t.files=t.colors=void 0,t.colors=["white","black"],t.files=["a","b","c","d","e","f","g","h"],t.ranks=["1","2","3","4","5","6","7","8"]})),o=e((function(e,o){Object.defineProperty(o,"__esModule",{value:!0}),o.computeSquareCenter=o.createEl=o.isRightButton=o.eventPosition=o.setVisible=o.translateRel=o.translateAbs=o.posToTranslateRel=o.posToTranslateAbs=o.samePiece=o.distanceSq=o.opposite=o.timer=o.memo=o.allPos=o.key2pos=o.pos2key=o.allKeys=o.invRanks=void 0,o.invRanks=[...t.ranks].reverse(),o.allKeys=Array.prototype.concat(...t.files.map((e=>t.ranks.map((t=>e+t)))));o.pos2key=e=>o.allKeys[8*e[0]+e[1]];o.key2pos=e=>[e.charCodeAt(0)-97,e.charCodeAt(1)-49],o.allPos=o.allKeys.map(o.key2pos),o.memo=function(e){let t;const o=()=>(void 0===t&&(t=e()),t);return o.clear=()=>{t=void 0},o};o.timer=()=>{let e;return{start(){e=performance.n
@ornicar
ornicar / browser-ndjson-stream-reader.js
Last active November 9, 2023 19:02
Read a ND-JSON stream from the browser or from nodejs
/* FOR THE BROWSER
Utility function to read a ND-JSON HTTP stream.
`processLine` is a function taking a JSON object. It will be called with each element of the stream.
`response` is the result of a `fetch` request.
See usage example in the next file.
*/
const readStream = processLine => response => {
const stream = response.body.getReader();
const matcher = /\r?\n/;
@ornicar
ornicar / howto
Last active June 1, 2021 07:55
set up daq on dying server
cd /home
git clone https://github.com/niklasf/magics
cd magics/v2
apt install make gcc
make
cd ../tracker
# put many.sh here
chmod +x many.sh
./many.sh python3 client.py http://alpha.backscattering.de:8080 eventually
/* Generates and saves a new generation of puzzle paths.
* Drops the previous generation.
*
* mongo <IP>:<PORT>/<DB> mongodb-puzzle-regen-paths.js
*
* Must run on the puzzle database.
* Should run every 60 minutes.
* Should complete within 3 minutes.
* OK to run many times in a row.
* OK to skip runs.
{
"_id" : "cxGnatYfw",
"n" : 6290,
"u" : "thibault",
"c" : true,
"p" : 2,
"e" : "A00",
"mc" : 3,
"or" : 1708,
"os" : 30,