This file contains hidden or 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
module Core | |
end | |
class Base(T) | |
include Core | |
end | |
class Foo < Base(String) | |
end |
- https://github.com/maiha/try.cr Try
- https://github.com/dry-cr/dry-monads Maybe, Either
- https://github.com/jdantonio/edge.cr Either, Maybe, Optional
- https://github.com/dhruvrajvanshi/crystal-futures Future
This file contains hidden or 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
def parse(str) | |
JSON.parse(str) | |
end | |
pp parse("1") # => 1 | |
pp parse("x") # raise JSON::ParseException | |
begin | |
v = parse("1") | |
# use v |
This file contains hidden or 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
module Core(T) | |
@a : Bool | |
end | |
class Base(T) | |
include Core(Int32) | |
def initialize | |
@a = true | |
end |
This file contains hidden or 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
class Changeset(T) | |
def initialize(@instance : T) | |
end | |
end | |
module Cset(T) | |
def changeset(instance) | |
Changeset(T).new(instance) | |
end | |
end |
This file contains hidden or 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/bin/env zsh | |
set -e | |
# for shards-0.7 | |
rm -rf shard.lock libs | |
shards update | |
echo "/lib/" >> .gitignore | |
# MemoryIO | |
sed -i "s/MemoryIO/IO::Memory/g" {src,spec}/**/*.cr |
This file contains hidden or 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
% git clone [email protected]:crystal-lang/crystal_lib.git | |
% cd crystal_lib | |
% cat > lib_ntohl.cr | |
@[Include("arpa/inet.h")] | |
lib LibC | |
fun ntohl | |
end | |
% crystal src/main.cr -- lib_ntohl.cr | |
lib LibC |
This file contains hidden or 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
alias Entry = Hash(Symbol, File::Stat | String) | |
def awalkDir(dir, block : Entry -> Nil) | |
Dir.entries(dir).each do |fname| | |
next if fname == "." || fname == ".." | |
current = File.join(dir, fname) | |
begin |
This file contains hidden or 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
127.0.0.1:6379> zadd zset 100 a | |
(integer) 1 | |
127.0.0.1:6379> zadd zset 200 b | |
(integer) 1 | |
127.0.0.1:6379> eval "return {redis.call('ZSCORE',KEYS[1],KEYS[2]),redis.call('ZRANK',KEYS[1],KEYS[2])}" 2 zset b | |
1) "200" | |
2) (integer) 1 | |
127.0.0.1:6379> script load "return {redis.call('ZSCORE',KEYS[1],KEYS[2]),redis.call('ZRANK',KEYS[1],KEYS[2])}" | |
"b6b9e64ed4cc349469e0f24c49469c6d6fcdfc5a" |