Skip to content

Instantly share code, notes, and snippets.

View dietercastel's full-sized avatar
💭
🤔

Dieter Castel dietercastel

💭
🤔
View GitHub Profile
@dietercastel
dietercastel / tmap.jl
Created June 19, 2021 16:32
Naive throttling map function
function tmap(fn,arr,delay)
res = []
for a in arr
push!(res,fn(a))
sleep(delay)
end
end
@dietercastel
dietercastel / concat.jl
Last active May 15, 2021 10:29
Concat and replace PNG transparent images.
# Concatenate images vertically and replace transparancy with white.
using Images
a = readdir(".")
pngs = filter(x->endswith(x,".png"),a)
imgsperpage = 4
pages = length(pngs) ÷ imgsperpage
@dietercastel
dietercastel / wormhole.jl
Last active November 1, 2020 14:58
Use the (magic) wormhole tool from julia repl to transfer files easeily
# 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 / jpg2png2invert.py
Last active September 9, 2020 08:12
Convert JPG -> PNG -> INVERTED
from PIL import Image
import PIL.ImageOps
#Using PIL/pillow (install with 'pip3 install pillow' )
name = 'RPS-g2.jpg'
outname = 'RPS-g2.png' #png extension
im = Image.open(name)
inv = PIL.ImageOps.invert(im) #invert opperation
inv.save(outname)
@dietercastel
dietercastel / rps.pbl
Last active August 16, 2020 12:56
Multiplayer Rock, Paper, Scissors win chance problog.
% 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 / MoveScreenshots.jl
Last active July 25, 2020 13:02
Moving screenshots using julia
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 / osm_tiles_downloader
Last active June 10, 2020 15:10 — forked from tonyrewin/osm_tiles_downloader
small script to download OSM tiles
#!/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 January 6, 2020 17:06
Convert black and white image to black & red.
# 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 / ApproxBug.jl
Created October 24, 2019 15:22
Elementwise vs overall Approx Bug Julia?
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 October 16, 2019 09:04
Shuffling fails basic normalisation test.
#!/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)