Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Martin Møller Skarbiniks Pedersen MartinMSPedersen

🎯
Focusing
View GitHub Profile
@MartinMSPedersen
MartinMSPedersen / two_colours.R
Created Feb 19, 2021
Make two colour - one light and one dark
View two_colours.R
f1 <- sample(0:255,3)
while (sum(f1*c(0.2126,0.7152,0.0722)) < 0.85*255) { # brightness
f1 <- sample(0:255,3)
}
f2 <- sample(0:255,3)
while (sum(f2*c(0.2126,0.7152,0.0722)) > 0.15*255) { # brightness
f2 <- sample(0:255,3)
}
if (runif(1) > 0.5) {
View setdiff.R
#!/usr/bin/env Rscript
args <- commandArgs(trailingOnly = TRUE)
if (length(args) < 2) {
cat("Usage: setdiff <file1> <file2> [files]\n", file = stderr())
}
ignorecase <- FALSE
if (args[[1]] == "-i") {
@MartinMSPedersen
MartinMSPedersen / .bashrc
Created Jan 26, 2021
bash aliases and functions
View .bashrc
# aliases
alias enscript="enscript -M A4 --header=\'\$n\'"
alias flacseek='metaflac --add-seekpoint=5s *.flac'
alias fuse="fuse -g hq3x"
alias kali='docker pull martinmspedersen/kali ; docker container run --rm --hostname kali --name kali-$$ -v "/data/ctf":/data -w /data -it martinmspedersen/kali:latest'
alias katana='docker run -v "$PWD:/data" -it katana'
alias kubectl="sudo kubectl"
alias MYIP="torify wget http://ipinfo.io/ip -qO -"
alias nnmap="nmap -sC -sV -oN scan.txt"
@MartinMSPedersen
MartinMSPedersen / thor2xor.R
Created Sep 29, 2020
R script to convert othello games in Thor-format to XOR-format.
View thor2xor.R
library(stringr)
tournaments <- NULL
players <- NULL
DEBUG <- FALSE
get_tournaments <- function(filename) {
f <- file(filename, "rb", raw = TRUE)
tournament_input <<- as.integer(readBin(f, "raw", file.size(filename)))
close(f)
View RSA_simple.R
# work-in-progress
# based on https://www.di-mgt.com.au/rsa_alg.html
library(gmp)
# returns a random odd value. The first bit and last bit is 1.
random_value <- function(how_many_bits = 512) {
hex_values <- ceiling(how_many_bits/4)-4
if (hex_values < 1) stop("more bits please.")
result <- c(
View permutation_game.md5.R
library(digest)
DEBUG <- FALSE
while(TRUE) {
flag <- paste0(c(sample(c(letters,LETTERS,0:9,":","_","+"), 8, replace = TRUE)), collapse = "")
shasum <- substr(digest(flag,"md5", serialize=FALSE), 27,32)
cat(flag,shasum,"\n")
}
View Generate_Chess960_starting_position.R
#http://rosettacode.org/wiki/Generate_Chess960_starting_position
pieces <- c("R","B","N","Q","K","N","B","R")
generateFirstRank <- function() {
attempt <- paste0(sample(pieces), collapse = "")
while (!check_position(attempt)) {
attempt <- paste0(sample(pieces), collapse = "")
}
return(attempt)
@MartinMSPedersen
MartinMSPedersen / compute-pi.R
Created May 15, 2019
Compute 1 million of PI using R
View compute-pi.R
library(gmp)
ONE <- as.bigz("1")
TWO <- as.bigz("2")
THREE <- as.bigz("3")
FOUR <- as.bigz("4")
SEVEN <- as.bigz("7")
TEN <- as.bigz("10")
q <- as.bigz("1")
View polygon.R
polygon <- function(n) {
tibble(
x = accumulate(1:(n-1), ~.x+cos(.y*2*pi/n), .init = 0),
y = accumulate(1:(n-1), ~.x+sin(.y*2*pi/n), .init = 0),
xend = accumulate(2:n, ~.x+cos(.y*2*pi/n), .init = cos(2*pi/n)),
yend = accumulate(2:n, ~.x+sin(.y*2*pi/n), .init = sin(2*pi/n)))
}
ggplot(polygon(5) + geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) + theme_void() + coord_equal()