Skip to content

Instantly share code, notes, and snippets.

import os
import crc32
import strformat
import strutils
import nre except toSeq
import ../lib/die
let pat = re(r".*\[([0-9A-Fa-f]{8})\].*")
interface UserAgentInfoPart {
name: string;
version?: string;
detail?: string[];
}
type UserAgentInfo = UserAgentInfoPart[];
const re = /(\w+)(\/([0-9.]+))?( \((.*)\))?/g;
# a - alphabet
# n - sequence length
#
# Example
#
# cartperm([0, 1], 3)
# # => [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]
#
def cartperm(a, n)
a.product(* [a] * (n - 1))
class Hash
def iloc(i, *rest, set: nil)
if rest.empty?
self[i] = set if set
self[i]
else
self[i] = Hash.new if not self[i]
self[i].iloc(*rest, set: set)
end
end
def roll(probs)
r = rand
cum = 0
outcome = probs.keys.first
outcome_prob = 0
probs.each do |key, prob|
cum += prob
if cum >= r
outcome = key
outcome_prob = prob
:root {
/*--z-color-accent: #F0360D;*/
--z-color-accent: #E25821;
--z-color-background-dark: #212121;
--z-color-background-light: #424242;
}
/* colors */
html#main-window {
def pickle_load(filename):
return pickle.load(open(filename, "rb"))
def pickle_dump(data, filename):
return pickle.dump(data, open(filename, "wb"))
def pickle_get(filename, fn, *args, fresh=False, verbose=False):
"""Try to load data from a pickle file. Compute it with `fn` and save it if it doesn't exist."""
if not fresh and file_exists(filename):
if verbose:
.bar {
border: solid 1px rgba(0, 0, 0, 0.3);
}
const re = /(\w+)(\/([0-9.]+))?( \((.*)\))?/g;
/**
* Parse a user agent string into logical parts.
*
* @param {string} userAgentStr - The user agent string to parse
* @return {object[]} The information parsed from the user agent string
*/
function parseUserAgent(userAgentStr) {
const parsed = [];
#include <stdlib.h>
#include "ll.h"
struct ll* ll_create() {
struct ll* list = (struct ll*) malloc(sizeof(struct ll));
list->head = NULL;
list->length = 0;
return list;
}