Skip to content

Instantly share code, notes, and snippets.

Avatar

Anthony Clays anthonyclays

  • Leuven, Belgium
View GitHub Profile
View P-taal
#!/usr/bin/env perl
<>;
foreach(<>){
s/(ij|[aeiou]+)p\1/\1/ig;
print;
}
View Editor
#!/usr/bin/env perl
for (my $N=<>; $N; $N--){
$_ = "";
for (my $L=<>; $L; $L--) {
$_ .= <>;
}
for (my $L=<>; $L; $L--) {
my ($n, $r) = split(' ', <>);
s/($r( |$){$n}/\1/gm;
View pnguncorrupt.jl
#!/usr/bin/env julia
using CRC
# crc computing function
const handler = crc(CRC_32)
# offsets of IDAT chunks (points to 'I' byte)
const offsets = [114,131197,262278,393361,524445,655526,786609,917691,1048775,1179858,1188429]
# correct crcs. No 0x0a in those so we can assume they're correct ;)
const crcs = [0xf55a745d, 0x06e15ebf, 0xa0bdc18a, 0xadefb326, 0x09c557f7,
@anthonyclays
anthonyclays / curious.jl
Last active Aug 29, 2015
Curious solution
View curious.jl
#!/usr/bin/env julia
# Adapted from https://github.com/pablocelayes/rsa-wiener-attack
using ContinuedFractions # Note: this needs my fork of ContinuedFractions.jl
# fast perfect square test (from project euler tools)
# returns -1 if n is not a perfect square
function perfect_square(n::Integer)
h = n & 0xF # last four bits
@anthonyclays
anthonyclays / break_caesar.jl
Last active Aug 29, 2015
Fully automated caesar rotation decryption using a 2D language entropy table
View break_caesar.jl
#!/usr/bin/env julia
const ENTROPY_MAP_2D = open("entropy.csv") do f
readdlm(f, ',')
end
# Returns index 1:26 for a-z, 27 for space
function get_index_for(ch)
if 'a' <= ch <= 'z'
return int(ch - 96)
@anthonyclays
anthonyclays / typesort.jl
Last active Aug 29, 2015
Typelevel quicksort (and integer arithmetic) in Julia
View typesort.jl
#!/usr/bin/env julia
# Peano arithmetic (https://en.wikipedia.org/wiki/Peano_axioms)
abstract Natural <: Integer
immutable Zero <: Natural end
immutable Successor{P<:Natural} <: Natural end
# Define a total order relation
<(::Type{Zero}, ::Type{Zero}) = false
<{P<:Natural}(::Type{Zero}, ::Type{Successor{P}}) = true
View generated_llvm
julia> code_llvm(g, (Int,))
define i64 @julia_g_20191(i64) {
top:
%1 = icmp sgt i64 %0, 0, !dbg !8
br i1 %1, label %L.preheader, label %L3, !dbg !8
L.preheader: ; preds = %top
%2 = add i64 %0, -1, !dbg !8
%3 = zext i64 %2 to i65
View sr830_repl.py
#!/usr/bin/env python
# encoding: utf-8
"""
Usage:
rlwrap ./srs_test.py
"""
import os
@anthonyclays
anthonyclays / partition.jl
Created Sep 11, 2015
Vector partitioning into n chunks
View partition.jl
chunks(l::AbstractVector, n::Int) = let part_l = length(l) / n
[let start = floor(Int, (i-1)*part_l + 1), stop = floor(Int, i*part_l);
l[start:stop] end for i in 1:n]
end
@anthonyclays
anthonyclays / perfect_squares.rs
Created Sep 14, 2015
Fast perfect square test in Rust
View perfect_squares.rs
fn isqrt(n: usize) -> usize {
n == 0 && return n;
let mut s = (n as f64).sqrt() as usize;
s = (s + n / s) >> 1;
if s * s > n { s - 1 } else { s }
}
fn perfect_sqrt(n: usize) -> isize {
match n & 0xf {
0 | 1 | 4 | 9 => {