Skip to content

Instantly share code, notes, and snippets.

View maxbeutel's full-sized avatar

Max maxbeutel

View GitHub Profile
let coords = pixels(&image_size);
let accumulator = coords
.iter()
.filter(|coords| is_edge(coords))
.map(|coords| invert_y(coords))
.flat_map(|coords| (0..theta_axis_size).map(|theta| (theta, calculate_rho(theta, &coords))).collect::<Vec<_>>())
.fold(
DMatrix::from_element(theta_axis_size as usize, rho_axis_size as usize, 0),
|mut a, x| {
a[(x.0 as usize, x.1 as usize)] += 1;
#include <vector>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
@maxbeutel
maxbeutel / iterate_directory_recursive.cpp
Created February 5, 2017 09:01
Iterate a directory recursive and filter for php files
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <string>
const char *get_filename_ext(const char *filename)
{
const char *dot = strrchr(filename, '.');
<?php
$now = microtime(true);
$start = round(($now - (150 * 24 * 60 * 60)) * 1000);
$end = round($now * 1000);
$filterPattern = escapeshellarg('{ $.object.msg = "access" }');
function getLogs($nextToken, $start, $end, $filterPattern, $depth = 1) {
$cmd = sprintf(
'aws logs filter-log-events --log-group-name live-sg --log-stream-name web2.live-sg --start-time %d --end-time %d --filter-pattern %s --page-size 100 --max-items 10000',
@maxbeutel
maxbeutel / lua_from_cpp.cpp
Created December 30, 2016 09:09
Calling Lua from C++, registering class methods as callback
#include <lua5.3/lua.hpp>
#include <stdlib.h>
#include <stdio.h>
static int draw_rectangle(lua_State *L)
{
printf("function called\n");
return 1;
static void handle_file(struct evhttp_request *req, void *arg)
{
UNUSED(arg);
const char *uri = evhttp_request_get_uri(req);
// only GET requests allowed
if (evhttp_request_get_command(req) != EVHTTP_REQ_GET) {
evhttp_send_error(req, HTTP_BADREQUEST, 0);
return;
enum class URI_TO_PATH_STATUS : std::int8_t {
SUCCESS = 0,
FAILURE_URI_PARSE,
FAILURE_URI_TO_PATH,
FAILURE_PATH_DECODE,
};
std::tuple<std::string, URI_TO_PATH_STATUS> uri_to_path(const char *uri) {
assert(uri != NULL);
int main(int argc, char **argv)
{
UNUSED(argc);
struct event_base *base;
struct evhttp *http;
struct evhttp_bound_socket *handle;
const ev_uint16_t port = 8881;
const char *host = "0.0.0.0";
project(webserver)
cmake_minimum_required(VERSION 3.2)
SET(LIBEVENT_NAME "event" CACHE STRING "Name of the libevent library (as used in the linker argument).")
SET(LIBEVENT_LIB_DIR "/usr/local/lib" CACHE STRING "Path to libevent libraries.")
SET(LIBEVENT_INCLUDE_DIR "/usr/local/include" CACHE STRING "Path to libevent headers.")
MESSAGE("LIBEVENT_NAME: " ${LIBEVENT_NAME})
MESSAGE("LIBEVENT_LIB_DIR: " ${LIBEVENT_LIB_DIR})
(defn generate-prices
([low high]
(generate-prices (random-in-range low high)))
([last-price]
(iterate (fn [{:keys [last]}]
(let [low (- last 5)
high (+ last 5)