This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tmap(fn,arr,delay) | |
res = [] | |
for a in arr | |
push!(res,fn(a)) | |
sleep(delay) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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). | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
NewerOlder