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
#!/bin/sh | |
# | |
# Example usage: | |
# cat tcpdump.pcap | ./readtcpcap.sh 1 > stream1 | |
# | |
if [ -z "$1" ]; then | |
echo 'You have to specify a TCP stream!' | |
exit 1 |
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 main; | |
import core.stdc.string : strcmp; | |
import core.stdc.time : clock, clock_t, CLOCKS_PER_SEC; | |
import core.stdc.stdlib : rand, srand; | |
import eris.math : Accumulator; | |
// ^ tracks a stream of values and computes some statistics (min, max, avg, var, std) in constant space | |
alias stringz = char*; |
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
import gyre.mnemonics; | |
Graph graph; | |
graph.initialize(MacroNode.ID(42)); | |
scope(exit) graph.dispose(); | |
assert(graph.exported == 0); | |
assert(graph.length == 0); | |
// imagine we're compiling something like |
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
(import (scheme base)) | |
(define-syntax hornify | |
(syntax-rules () | |
((_ x an) an) | |
((_ x a pn ...) | |
(+ a (* x (hornify x pn ...)))))) | |
(define-syntax poly | |
(syntax-rules () |
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 Combinatorial ( | |
combine, | |
permutations, | |
matrices, | |
) where | |
-- inserts a value in a list at every possible position | |
combine :: t -> [t] -> [[t]] | |
combine x [] = [[x]] |
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
;;; Gabriel B. Sant'Anna <baiocchi.gabriel@gmail.com> | |
;;; Explained in pt-br at <https://baioc.github.io/scheme/> | |
;; binary-recursive aka dumb fibonacci | |
(define (fib n) | |
(cond ((= n 0) 0) | |
((= n 1) 1) | |
(else (+ (fib (- n 1)) | |
(fib (- n 2)))))) |
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
#ifndef UTIL_UNIQUE_PTR_HPP | |
#define UTIL_UNIQUE_PTR_HPP | |
#include <utility> | |
namespace util { | |
template <typename T> | |
class unique_ptr { | |
public: |
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
/* | |
* See the full version at <https://gitlab.com/snippets/1849449> | |
* and a pure C implementation at <https://gitlab.com/snippets/1837083> | |
*/ | |
#include <stack> | |
#include <string> | |
bool balanced(const std::string& xml) |
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
.text | |
# void lock(mutex) | |
lock: | |
ll $t0, 0($a0) # read the mutex (and set LLbit) | |
bne $t0, $zero, lock # if occupied (1), start over | |
addi $t1, $zero, 1 | |
sc $t1, 0($a0) # try grabing the mutex | |
beq $t1, $zero, lock # if wasn't atomic (0), start over |
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
;; make a function that caches its past results | |
(define (memoize proc) | |
(let ((cache (make-table))) | |
(define (delegate . args) | |
(let ((hit (lookup cache args))) | |
(or hit ; or miss | |
(let ((result (apply proc args))) | |
(insert! cache args result) | |
result)))) | |
delegate)) |
NewerOlder