Skip to content

Instantly share code, notes, and snippets.

View anowell's full-sized avatar

Anthony Nowell anowell

View GitHub Profile
@anowell
anowell / acurl.sh
Last active August 29, 2015 14:26
A bash function to simplify repetitive curling with API key and full URL
# Add to .bashrc or .profile or .zshrc or whatever you use... :)
#
# Examples:
# acurl algo/anowell/Pinky -X POST -d '"pondering"' -H "Content-Type: application/json"
# acurl data/.my/some_collection?force=true -X DELETE
function acurl() {
local aroute=$1
local ahost=${ALGORITHMIA_API-https://api.algorithmia.com}
shift
@anowell
anowell / wkhtmltopdf-release-segfault.rs
Created July 21, 2016 16:49
Minimal wkhtmltopdf snippet that works in debug but segfaults in --release
extern crate libwkhtmltox_sys as libwkhtmltox; // https://github.com/anowell/libwkhtmltox-sys
use libwkhtmltox::*;
use std::ffi::{CString, CStr};
use std::os::raw::{c_char, c_int, c_uchar};
unsafe extern fn finished_callback(converter: *mut wkhtmltopdf_converter, val: c_int) {
println!("finished_callback: {}", val);
// Read the PDF output
@anowell
anowell / bench_json_zeroes.rs
Last active November 1, 2016 06:30
Basic microbench of decoding large arrays of zeroes
#![feature(test)]
extern crate serde_json;
extern crate json;
extern crate test;
#[cfg(test)]
mod tests {
use json::{self, JsonValue};
use serde_json::{self, Value};
use test::Bencher;
@anowell
anowell / algo_entrypoint.rs
Last active November 13, 2016 16:59
First draft experiment at reducing boilerplate for algorithm entrypoint
/*
Example usage:
Note: in all of these cases, the return value must be `Result<T, E>` where:
- `T` has a conversion to `AlgoOutput` (e.g. String, Vec<u8>, JsonValue, (), or anything Serializeable)
- `E` has a conversion to `Box<Error>` (e.g. String or any custom type that `impl Error`)
-------------Text-----------------------
algo_entrypoint! { text => hello }
fn hello(input: &str) -> Result<String, String> {
Ok(format!("Hello {}", input))
@anowell
anowell / gist:144f2a4b4e699a35536b0c09a43485ce
Created November 23, 2016 21:16
algorithmia_nginx_proxy
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
@anowell
anowell / random-filters.rb
Last active December 21, 2016 20:53
Apply random deep style filters to a bunch of images
#!/usr/bin/env ruby
#
# Takes an arbitrary number of files as arguments
# and randomly generates PER_IMAGE filtered versions
# of each image while using each filter an equal
# number of times (approx).
#
# It uses batch inputs to minimize API calls,
# but still expect at least 1 API call per filter
#
@anowell
anowell / all-the-filters.sh
Created December 18, 2016 08:09
For a single image, generate every DeepFilter style transfer variant of that image
#!/bin/bash
set -e
function die {
echo >&2 $1
exit 1
}
command -v algo >/dev/null 2>&1 || die "Have you installed the Algorithmia CLI"
@anowell
anowell / todo.rs
Last active January 23, 2017 19:24
Quasar To Do Concept (using maud templating)
use quasar::*;
struct TodoItem {
label: String,
complete: bool,
}
struct TodoList {
items: Vec<TodoItem>,
}
@anowell
anowell / Cargo.toml
Last active February 12, 2017 04:27
My preferred rust template for Algorithmia algorithms
# You'll need at least these dependencies
[dependencies]
algorithmia = "2.0.0"
base64 = "0.3.0"
serde = "0.9.0"
serde_derive = "0.9.0"
serde_json = "0.9.0"
error-chain = "0.9.0"
@anowell
anowell / benchmarks
Last active June 13, 2018 23:09
bench iterators and loops of Zip-Map-Sum
(Benchmark disclaimers apply. Don't trust the numbers without double checking my code.)
Scala (functional): 697,099 ns/iter
Scala (for loop): 20,467 ns/iter
Rust (functional): 4,984 ns/iter
Rust (for loop): 4,983 ns/iter // Note: this required adding assertions to prevent bounds checking
C (for loop): 6,172 ns/iter // Note: this used -O2 optimization