Skip to content

Instantly share code, notes, and snippets.

@dietercastel
dietercastel / rps.pbl
Last active Aug 16, 2020
Multiplayer Rock, Paper, Scissors win chance problog.
View rps.pbl
% Rock, Paper, Scissors in problog.
% Editor URL: https://dtai.cs.kuleuven.be/problog/editor.html#task=prob&hash=462b1ed73475d1bbd67dbc1f6d503a4c
1/3::rock(X); 1/3::paper(X) ; 1/3::scissors(X) :- rps(X).
%1/5::rock(X); 1/5::paper(X) ; 1/5::scissors(X) ; 1/5::lizard(X); 1/5::spock(X) :- rpslk(X).
rps(X) :- between(1,11,X).
%rps(1).
%rps(2).
%rps(3).
@dietercastel
dietercastel / wormhole.jl
Last active Nov 1, 2020
Use the (magic) wormhole tool from julia repl to transfer files easeily
View wormhole.jl
# Script to run magic-wormhole (see https://github.com/warner/magic-wormhole) from Julia repl
# Author: Dieter Castel
# Installing requirements once.
# Meanwhile refactored into: https://github.com/dietercastel/Wormhole.jl
]add Conda
]add PyCall
using Conda
using PyCall
Conda.add("magic-wormhole",channel="conda-forge")
# Good to go using PyCall.
@dietercastel
dietercastel / osm_tiles_downloader
Last active Jun 10, 2020 — forked from tonyrewin/osm_tiles_downloader
small script to download OSM tiles
View osm_tiles_downloader
#!/usr/local/bin/python3
# Initially converted with 2to3.py and then tweaked at bit
# from the original script by tonyrewin at https://gist.github.com/tonyrewin/9444410
# Author: tonyrewin & Dieter Castel
from sys import argv
import os
import math
import urllib.request, urllib.error, urllib.parse
import random
import os.path
@dietercastel
dietercastel / bw2NewColor.py
Last active Jan 6, 2020
Convert black and white image to black & red.
View bw2NewColor.py
# This script coverts a black & white image to an image with new colors.
from PIL import ImageOps, Image
imgPath = "testImg.png"
blackColor = (255,0,0,0)
whiteColor = (0,0,0,255)
img = Image.open(imgPath).convert("L")
# Black pxl, white pxl
newImg = ImageOps.colorize(img,blackColor,whiteColor)
#ImageOps.crop(newImg,border=55).show()
newImg.show()
@dietercastel
dietercastel / MoveScreenshots.jl
Last active Jul 25, 2020
Moving screenshots using julia
View MoveScreenshots.jl
fromdir = "." # cd to e.g. the Desktop.
# Filters the read in directory
t = filter(x->startswith(x,"Screenshot"),readdir(fromdir))
# Move every x in t to it's new location.
map(x->mv(x,"../screenshots/$x"),t) # x is replaced using string interpolation
@dietercastel
dietercastel / ApproxBug.jl
Created Oct 24, 2019
Elementwise vs overall Approx Bug Julia?
View ApproxBug.jl
using Test
alldigits = cat([[0.375297 0.624703]; [0.39924 0.60076]], [[0.664557 0.335443]; [0.664557 0.335443]], dims=3)
threedig = map(x -> round(x,digits=3), alldigits)
@testset "Testing" begin
@test size(alldigits) == size(threedig)
@test all(isapprox.(alldigits, threedig, atol=1e-3))
#This one fails???
@test isapprox(alldigits, threedig, atol=1e-3)
end
@dietercastel
dietercastel / shufflefails.jl
Last active Oct 16, 2019
Shuffling fails basic normalisation test.
View shufflefails.jl
#!/usr/local/bin/julia
# Author: Dieter Castel
#
using Match
using Random
using Distributions
using Test
# Recursive function generating random numbers that sum to value t.
function genRandTot(n,t)
@dietercastel
dietercastel / findmasterkey.sh
Created Oct 8, 2019
Does what it says on the tin.
View findmasterkey.sh
#!/usr/local/bin/fish
#
# Finds masterkey files of Joplin.
echo "Searching: " $argv
find "$argv" -name "*.md" -print0 | xargs -0 grep -lrniE "content:|checksum:|encryption_method: 2"
@dietercastel
dietercastel / logplotrps.jl
Last active Sep 20, 2019
Plotting on a logaritmic scale
View logplotrps.jl
#Plot of calculating the win chance for g-player Rock, Paper, Scissors.
# A winning RPS game contains exactly two options.
#Total amount of options BigInt function
tot(g) = 3^BigInt(g)
#Winning options BigInt function
win(g) = 3*2*(2^(BigInt(g)-1)-1)
#Calculate the win chance
winchance(g) = win(g)//tot(g)
xto(n) = range(3,stop=n)
@dietercastel
dietercastel / plotrps.jl
Last active Sep 16, 2019
RPS julia plotting
View plotrps.jl
#Plot of calculating the win chance for g-player Rock, Paper, Scissors.
# A winning RPS game contains exactly two options.
#Total amount of options BigInt function
tot(g) = 3^BigInt(g)
#Winning options BigInt function
win(g) = 3*2*(2^(BigInt(g)-1)-1)
#Calculate the win chance
winchance(g) = win(g)//tot(g)
xto(n) = range(3,stop=n)