Skip to content

Instantly share code, notes, and snippets.

View codesections's full-sized avatar

Daniel Sockwell codesections

View GitHub Profile
@codesections
codesections / omni-sigil.raku
Created December 21, 2022 14:26
A Raku class that implements all three of the Positional, Associative, and Callable roles
#| A class that implements the Positional, Associative, and Callable roles.
#| Accordingly, this type can be bound variables with any sigil
class Seuss does Positional does Associative does Callable does Iterable {
has @.pos handles <AT-POS EXISTS-POS DELETE-POS ASSIGN-POS BIND-POS elems>
= Nil, '🐠', '<°))))><';
has %.asc handles <AT-KEY EXISTS-KEY DELETE-KEY ASSIGN-KEY BIND-KEY>
= (:blue<🐟>, :red<🐡>);
method of { Mu }
@codesections
codesections / actix-web.rs
Created December 20, 2018 22:03
Basic static file server with actix-web
extern crate actix_web;
use actix_web::{fs, server, App};
fn main() {
server::new(|| {
App::new()
.handler(
"/",
fs::StaticFiles::new("./public")
.unwrap()
@codesections
codesections / main.rs
Last active May 16, 2022 23:48
Warp_proof_of_concept
use futures::{Async, Future, Poll};
use tokio::io::{AsyncRead, AsyncWrite, Error, ReadHalf, WriteHalf};
use tokio::net::TcpStream;
use warp::{path, Filter, Stream};
struct Receiver {
rx: ReadHalf<TcpStream>,
}
impl Stream for Receiver {
type Item = String;
@codesections
codesections / server.rs
Last active March 20, 2022 04:35
Naive static file server in rust
use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;
mod app;
fn main() {
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
for stream in listener.incoming() {
let stream = stream.unwrap();
handle_connection(stream);
@codesections
codesections / Handles.rakumod
Created February 21, 2022 20:22
Grammar::Handles, a Raku module for grammar delegation
# Grammar::Handles
my module Grammar::Handles::Helpers {
class X::Grammar::Can'tHandle is Exception {
has $.type is required;
multi method CALL-ME(|c) { die self.new(|c)}
method message { q:to/§err/.trim.indent(2);
The `handles` grammar trait expects a Grammar, the name
of a Grammar, a Pair with a Grammar value, or a list of
any of those types. But `handles` was called with:
@codesections
codesections / Subgrammar.rakumod
Created February 16, 2022 07:07
A role for using multiple grammars/action objects at once in Raku
role Subgrammar[::G :$grammar, :$actions] {
multi method slag(G) {
my $old-actions = self.actions;
self.set_actions: $actions;
my @wrapped = G.^methods(:local).map: -> &m {
with self.^methods.first({.name eq &m.name}) {
next if $_ === &m or .name eq 'BUILDALL';
.wrap: method (|c) { m self, |c } }
}
@codesections
codesections / top-dependencies_2021-11-24.md
Created December 7, 2021 18:35
Most depended on Raku packages (2021-11-24)

This list was generated using the Citation Indices module by Richard Hainsworth (finanalyst) and lists the 30 most-often-depended-modules in the Raku ecosystem as of 2021-11-24 (including both direct and transitive dependencies). For more info, see the ModuleCitation module; thanks, Richard!

Module Name Recursive Citation Index Module Description
JSON::Fast 42.37
MIME::Base64 31.45 Encoding and decoding Base64 ASCII strings
File::Directory::Tree 30.89 Port of File::Path::Tiny - create and delete directory trees
URI 28.44 A URI implementation using Raku grammars to implement RFC 3986 BNF
OpenSSL 24.11 OpenSSL bindings
File::Temp 23.35
@codesections
codesections / linkedList.js
Created January 6, 2019 23:01
A simple linked list implemented in JavaScript
const LinkedList = function() {
this.head = null;
this.tail = null;
};
LinkedList.prototype.addToTail = function(value) {
const newTail = { value, next: null };
if (this.tail) {
this.tail.next = newTail;
@codesections
codesections / pubsub_poc.rs
Last active November 4, 2021 10:04
A proof of concept showing streaming from a Redis pub/sub channel to Server Sent Events
use futures::{Async, Poll};
use redis;
use std::time::Duration;
use warp::{path, Filter, Stream};
struct OutputStream {
con: redis::Connection,
}
impl OutputStream {
@codesections
codesections / immitating-julia.raku
Created September 7, 2021 18:49
Raku is pretty flexible
constant gcd = &[gcd];
constant collect = *.bounds;
constant extrema = &minmax;
my &find_gcd = gcd ∘ collect ∘ extrema;