Skip to content

Instantly share code, notes, and snippets.

View Daniel-Worrall's full-sized avatar

Daniel Worrall Daniel-Worrall

View GitHub Profile
@Daniel-Worrall
Daniel-Worrall / download.cr
Created June 21, 2020 04:00
twist.moe Downloader Crystal
require "./twist"
CHUNK_SIZE = 1024
name = ""
path = ""
Dir.mkdir_p(path)
Twist.get_sources(name).each do |source|
filename = "#{path}/#{name} E#{source.number.to_s.rjust(2, '0')}.mp4"
@Daniel-Worrall
Daniel-Worrall / pre-commit
Last active July 31, 2021 11:47
Crystal pre-commit - Just put in .git/hooks folder
#!/bin/sh
changed_cr_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.cr$')
[ -z "$changed_cr_files" ] && exit 0
crystal tool format $changed_cr_files
shards check || exit 1
bin/ameba -f flycheck $changed_cr_files || exit 1
@Daniel-Worrall
Daniel-Worrall / sieve.cr
Last active March 22, 2022 22:53
Factorisation Sieve
module Sieve
protected class_getter sieve = Hash(Int32, Int32).new { |h, k| k }
@@calculated = 1
class Factors
include Iterator(Int32)
def initialize(@n : Int32)
end