Imagine an API like this:
bool double_if_positive(float input, float* output) {
if (input > 0) {
*output = input * 2.0f;
return true;
} else {
return false;
}
fn imagehash(path: &Path) -> std::io::Result<Digest> { | |
let mut f = File::open(path)?; | |
let mut buffer = [0u8; 1024*1024]; | |
let mut context = Context::new(); | |
loop { | |
let read = f.read(&mut buffer)?; | |
if 0 == read { | |
return Ok(context.compute()); | |
} |
# Append history | |
shopt -s histappend | |
#HISTCONTROL="ignorespace:ignoredups:erasedups" | |
HISTCONTROL=ignorespace:erasedups | |
HISTSIZE=100000 | |
HISTFILESIZE=-1 | |
CAA_AT_PROMPT=1 | |
function __caa_before_command { | |
if [ -z "$CAA_AT_PROMPT" ]; then |
#!/usr/bin/env run-cargo-script | |
use std::process::Command; | |
fn main() -> std::io::Result<()> { | |
let args: Vec<std::ffi::OsString> = std::env::args_os().collect(); | |
if args.len() > 1 { | |
eprintln!("no arguments allowed"); | |
std::process::exit(1); | |
} |
#!/usr/bin/env run-cargo-script | |
//! ```cargo | |
//! [dependencies] | |
//! ``` | |
use std::process::Command; | |
fn main() -> std::io::Result<()> { | |
let mut path = std::env::current_dir()?; |
import collections | |
import yaml | |
# Try to preserve order in the front matter. | |
def dict_representer(dumper, data): | |
return dumper.represent_dict(data.items()) | |
def dict_constructor(loader, node): | |
return collections.OrderedDict(loader.construct_pairs(node)) |
#!/usr/bin/env python3 | |
from xfinity_usage.xfinity_usage import XfinityUsage | |
import datetime | |
import json | |
import os | |
results = XfinityUsage( | |
os.environ['XFINITY_USER'], | |
os.environ['XFINITY_PASSWORD'], |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
// Can't get O_TMPFILE to work for some reason. | |
#ifndef __O_TMPFILE | |
# define __O_TMPFILE (020000000 | __O_DIRECTORY) | |
#endif |
// g++ -Wall -o mmaptest mmaptest.cpp | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <fcntl.h> | |
#include <sys/mman.h> | |
#include <sys/stat.h> | |
#include <assert.h> | |
int main() { |
#include <stdio.h> | |
#include <typeinfo> | |
#include <functional> | |
#include <string> | |
#include <type_traits> | |
#include <vector> | |
struct Unit {}; | |
template<typename Result, typename Error> |
Imagine an API like this:
bool double_if_positive(float input, float* output) {
if (input > 0) {
*output = input * 2.0f;
return true;
} else {
return false;
}