Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
I may be slow to respond.

Daniel Worrall Daniel-Worrall

🏠
I may be slow to respond.
View GitHub Profile
@Daniel-Worrall
Daniel-Worrall / sieve.cr
Last active Mar 22, 2022
Factorisation Sieve
View sieve.cr
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
@Daniel-Worrall
Daniel-Worrall / download.cr
Created Jun 21, 2020
twist.moe Downloader Crystal
View download.cr
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 / twist.moe.cr
Created Jun 21, 2020
Unencryption for video links on twist.moe
View twist.moe.cr
require "openssl"
data = ""
KEY = "LXgIVP&PorO68Rq7dTx8N^lP!Fa5sGJ^*XK"
cipher = OpenSSL::Cipher.new("aes-256-cbc")
encrypted = Base64.decode_string(data)
salt = encrypted.to_slice[8, 8]
my_data = KEY + String.new(salt)
View gist:f3e1bd81b74bbf843d0ad5784f5c05ff
day = 12
suffix = case {day % 10, day % 100}
when {.==(1), .!=(11)}
"st"
when {.==(2), .!=(12)}
"nd"
when {.==(3), .!=(13)}
"rd"
else
View config.yml
version: 2
jobs:
build:
working_directory: ~/<%= config.name %>
docker:
- image: crystallang/crystal:latest
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "shard.lock" }}
View twist.cr
class Anime
include JSON::Serializable
property id : Int32
property title : String
property alt_title : String?
property season : Int32
@[JSON::Field(converter: BoolConverter)]
property ongoing : Bool
property hb_id : Int32?
@[JSON::Field(converter: TimeConverter)]
@Daniel-Worrall
Daniel-Worrall / pre-commit
Last active Jul 31, 2021
Crystal pre-commit - Just put in .git/hooks folder
View pre-commit
#!/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 / Console
Created Sep 10, 2019
Link Header Parsing Crystal Lang
View Console
crystal ./src/test.cr --release
{"hub" => "https://api.twitch.tv/helix/webhooks/hub",
"self" => "https://api.twitch.tv/helix/users/follows?first=1&from_id=1337"}
{"hub" => "https://api.twitch.tv/helix/webhooks/hub",
"self" => "https://api.twitch.tv/helix/users/follows?first=1&from_id=1337"}
{"hub" => "https://api.twitch.tv/helix/webhooks/hub",
"self" => "https://api.twitch.tv/helix/users/follows?first=1&from_id=1337"}
{"hub" => "https://api.twitch.tv/helix/webhooks/hub",
"self" => "https://api.twitch.tv/helix/users/follows?first=1&from_id=1337"}
1 325.74k ( 3.07µs) (± 7.74%) 2.16kB/op 2.30× slower
@Daniel-Worrall
Daniel-Worrall / backup.rb
Last active Jul 30, 2019
Backup all named local volumes on docker
View backup.rb
folder_name = "" # Dir.pwd
volumes = %x`docker volume ls`
arr = []
volumes.scan(/local\s*(\w*)/) { |x| arr << x[0] }
arr.reject!{ |x| x =~ /^[0123456789abcdef]+$/ }
arr.each do |volume_name|
p %x`docker run --rm -v #{volume_name}:/volume_data -v #{folder_name}:/backup ubuntu tar cvf /backup/#{volume_name}.tar /volume_data`
end
@Daniel-Worrall
Daniel-Worrall / discord-custom.css
Last active Jul 30, 2019
Discord Double Width Server List
View discord-custom.css
.wrapper-1Rf91z {
width: 130px !important;
}
.wrapper-1Rf91z .scrollerWrap-2lJEkd {
width: 148px;
}
.scroller-2TZvBN {
padding-left: 0px;
}
.scroller-2TZvBN > div[class=""] {