Skip to content

Instantly share code, notes, and snippets.

@allyourcode
allyourcode / nested_list.cc
Created July 21, 2021 04:54
In Python, we can do nested lists right out of the box. E.g. [1, [2, 3], 4, [5, [6]], 7]. In C++, we must jump through some hoops, but it can be done.
#include <iostream>
#include <initializer_list>
#include <vector>
using namespace ::std;
template <typename E>
class NestedList {
public:
class Element {
@allyourcode
allyourcode / .gitignore
Last active December 15, 2019 09:57
The purpose of this code is to solve the following problem: Make a sudoku puzzle whose clues are the first 9 digits of pi in the same order.
**/__pycache__
@allyourcode
allyourcode / .gitignore
Last active July 30, 2018 00:36
Tools forbreaking a video down into a series of still images.
*.pyc
*~
@allyourcode
allyourcode / panelize.py
Created July 26, 2018 11:06
Tools forbreaking a video down into a series of still images.
from __future__ import print_function
import csv
import os
import sys
import cv2
def freak_out(msg):
@allyourcode
allyourcode / convex_hull.py
Created August 24, 2015 23:39
Seems to work. Haven't tested thoroughly though.
import math
import operator
def normalize_azimuth_radians(angle):
positive = (angle % 2 * math.pi)
return positive if positive <= math.pi else positive - 2 * math.pi
class Vector(object):
def __init__(self, x, y):
-module(running_total).
-export([new/2, update/2, update_silently/2]).
-export([sum/0, truncated_sum/1]).
new(Reducer, Initial) ->
spawn_link(fun() -> run(Reducer, Initial) end)
.
-module(assassin).
-export([linked/2]).
% Monitors a gen_server2 for responsiveness by periodically sending
% is_healthy requests, and expecting a response in an amount of time
% specified by user of this module.
%
% Like supervisor, N out of M failures are allowed (where failure
% means response took too long).
@allyourcode
allyourcode / reenter.html
Created February 19, 2015 19:54
Inspired by gopherjs.
<!doctype html>
<html>
<head>
<title>Wat</title>
</head>
<body>
<script>
/* Support */
-module(id_server).
-behavior(gen_server).
-export([init/1, code_change/3, terminate/2]).
-export([handle_call/3, handle_cast/2, handle_info/2]).
% Unlike Snowflake (Twitter) or Flake (boundary), one of the goals here is for
% IDs to be scattered. This is because it is assumed that there will be some
% kind of sorted index on IDs. In that case, IDs that correlate with time would
-module(click_server).
-behavior(gen_server).
% For gen_server behavior.
-export([
% life cycle functions
init/1, code_change/3, terminate/2,
% handle_* service provider functions
handle_call/3, handle_cast/2, handle_info/2]).
% For users of this module.