Skip to content

Instantly share code, notes, and snippets.

View ddugovic's full-sized avatar
💭
I may be slow to respond.

Daniel Dugovic ddugovic

💭
I may be slow to respond.
View GitHub Profile
@ddugovic
ddugovic / stockfish.js
Created June 14, 2018 00:51
Relay Chess Stockfish.js
This file has been truncated, but you can view the full file.
var Module = {
print: (function(stdout) {
postMessage(stdout)
})
};
var Module;
if (!Module) Module = (typeof Module !== "undefined" ? Module : null) || {};
var moduleOverrides = {};
for (var key in Module) {
if (Module.hasOwnProperty(key)) {
function play(min,sec){var challenges=$(".challenge");if(arguments.length===0)return challenges.eq(Math.floor(Math.random()*challenges.length)).find(".accept").click();else{challenges=challenges.filter(function(){return $(this).find(".desc").text().search(new RegExp(min+"\\+"+sec))!==-1});if(challenges.length===0)console.log("No challenges matching the specified time control");else{return challenges.eq(Math.floor(Math.random()*challenges.length)).find(".accept").click()}}}
(function() {
function myzoom() {
document.body.setAttribute('style', '--zoom:140');
window.lichess.dispatchEvent(window, 'resize');
}
window.setInterval(myzoom, 1000);
})();
@ddugovic
ddugovic / challengeUser.js
Created April 10, 2020 19:17
Create example for how to create a challenge using whiteAccessToken and blackAccessToken
export async function challengeUser(
whiteAccessToken: string,
blackAccessToken: string,
username: string
): Promise<ChallengeGame> {
const response = await createClient(whiteAccessToken).post<
CreateChallengeResponse
>(
`/api/challenge/${username}`,
stringify({
@ddugovic
ddugovic / pipfilelock-to-requirements.sh
Created July 2, 2020 09:22
Generate requirements.txt from pipfile.lock
#
# https://github.com/pypa/pipenv/issues/3493#issuecomment-651148507
cat Pipfile.lock \
| grep -B1 '"hashes"\|"version": ' \
| grep -v '"markers": \|"hashes": ' \
| grep ": {\|version" \
| sed -e 's/: {$//g' \
| tr '\n' ',' | tr -s ' ' ' ' \
| sed -e 's/, "version": "//g;s/", "/ /g;s/"//g;s/,//g' \
| tr ' ' '\n' \
@ddugovic
ddugovic / shogi_pawn_encoder.rb
Created March 19, 2021 17:35
Encodes pawns as a bitwise-AND-comparable index (from a SFEN)
# Encodes pawns as a bitwise-AND-comparable index (from a SFEN)
# Usage: ruby pawn_encoder.rb "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL"
def encode(fen)
board = fen.gsub("9"," 8").gsub("8"," 7").gsub("7"," 6").gsub("6"," 5").gsub("5"," 4").gsub("4"," 3").gsub("3"," 2").gsub("2"," 1").gsub("1"," ")
# replace 'P' with '1' and replace 'p' with '1'
bpawnsA = board.gsub(/[^P\/]/,"0").gsub(/P/,"1").split("/")
wpawnsA = board.gsub(/[^p\/]/,"0").gsub(/p/,"1").split("/")
# shift black pawns upwards a rank (rotate left) etc.
bpawnsB = bpawnsA.rotate(-1)
@ddugovic
ddugovic / 81dojo-import.sh
Created March 12, 2022 11:07
Import kifu into MongoDB
#!/usr/bin/zsh
python3 fetch_81dojo_games.py ~/81dojo/ && \
cat ~/81dojo/*.json | mongoimport --db=81dojo --collection=kifu |& tail -1
@ddugovic
ddugovic / extract.sh
Last active August 13, 2022 19:21
Extract keyframe images from Shogi Wars MP4 (YouTube thumbnail candidate images)
ffmpeg -skip_frame nokey -i *.mp4 -vsync vfr %06d.bmp