This file contains 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
// References: | |
// | |
// Wikipedia IPv4 / IPv6: | |
// - https://en.wikipedia.org/wiki/IPv4 | |
// - https://en.wikipedia.org/wiki/IPv6_packet | |
// | |
// Working implem: | |
// - https://www.binarytides.com/packet-sniffer-code-in-c-using-linux-sockets-bsd-part-2/ | |
#include <unistd.h> // close |
This file contains 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 python | |
from scapy.all import ARP, Ether, sniff, sendp | |
def arp_do_stuff(pkt): | |
if ARP not in pkt: | |
return | |
arp_display(pkt) |
This file contains 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 Object | |
alias TypeIdType = Int32 | |
end | |
# | |
# This is unsafe to store any class created through the ObjectPool, as as | |
# soon the ObjectPool is GC-ed, all pointers to classes inside that pool | |
# will have unknown behavior if used. | |
class ObjectPool(T) | |
@buffer : Pointer(UInt8) |
This file contains 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
#macro data(name, &block) | |
#end | |
# | |
# #### Ultimately I want to do this: | |
# and be able to make a pre-allocated buffer of Person, | |
# and be able to get a reference to a single Person (but pre-allocated | |
# in that buffer) | |
# | |
#data Person do | |
# property name : String |
This file contains 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
# Based on https://github.com/crystal-lang/crystal/blob/26635f1052b99ab5b52a8b051020a25435dba751/src/compiler/crystal/semantic/literal_expander.cr | |
macro expand_literal_ArrayLiteral_empty(node) | |
{% puts "--- expansion for: #{node}" %} | |
Array({{ node.of }}).new | |
{% debug %} | |
end |
This file contains 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
# How to use / how it works: | |
# | |
# NOTE: The server reads on STDIN, and writes on STDOUT | |
# | |
# Start the program. Now you can write something then press enter. | |
# The server will do something 'useful' with the input, and gives you the result. | |
# | |
# The requests/responses are handled asynchronously, and can handle multiple requests at the same time. | |
# | |
# So you can spam the input (write a lot of lines) then close the input (Ctrl-d on a terminal), and |
This file contains 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
# Following: https://fsharpforfunandprofit.com/posts/understanding-parser-combinators/ | |
require "spec" | |
# Result types | |
record Success(T), value : T, remaining : String do | |
def_equals_and_hash value, remaining | |
end |
This file contains 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
// Super Fast Blur v1.1 | |
// by Mario Klingemann <http://incubator.quasimondo.com> | |
// | |
// Tip: Multiple invovations of this filter with a small | |
// radius will approximate a gaussian blur quite well. | |
// | |
BImage a; | |
BImage b; | |
void setup() |
This file contains 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
# Compile it with: crystal build --prelude=empty --emit llvm-ir noprelude_exception.cr | |
lib LibC | |
alias SizeT = UInt64 | |
fun printf(format : UInt8*, ...) : Int32 | |
fun exit(exit_code : Int32) : NoReturn | |
end | |
require "callstack/lib_unwind" |
This file contains 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 Contract | |
# We put everything in `included` macro so the constants don't clashes | |
# when used in multiple classes | |
macro included | |
CONTRACTS_FOR_DEF = {} of _ => _ | |
macro __add_contract(contract) | |
\{% if CONTRACTS_FOR_DEF[:next_def] == nil %} | |
\{% CONTRACTS_FOR_DEF[:next_def] = [contract] %} | |
\{% else %} | |
\{% CONTRACTS_FOR_DEF[:next_def] << contract %} |