Skip to content

Instantly share code, notes, and snippets.

# 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'],
@chadaustin
chadaustin / tmpfile.cpp
Last active January 11, 2018 00:30
How to atomically write a file without giving it a temporary name
#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>
@chadaustin
chadaustin / ub.md
Last active June 14, 2017 00:09
Undefined Behavior in Unit Test

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;
 }
clang-32-opt:
file - avg - min
---- - --- - ---
testdata/apache_builds.json - 0.302 ms - 0.293 ms
testdata/github_events.json - 0.156 ms - 0.148 ms
testdata/instruments.json - 0.570 ms - 0.554 ms
testdata/mesh.json - 3.180 ms - 3.091 ms
testdata/mesh.pretty.json - 4.802 ms - 4.628 ms
testdata/nested.json - 0.154 ms - 0.151 ms
testdata/svg_menu.json - 0.004 ms - 0.003 ms