Skip to content

Instantly share code, notes, and snippets.

Chad Austin chadaustin

Block or report user

Report or block chadaustin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View yaml_overrides.py
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))
View datausage.py
#!/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 Jan 11, 2018
How to atomically write a file without giving it a temporary name
View tmpfile.cpp
#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
View mmaptest.cpp
// 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() {
View Promise.cpp
#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 Jun 14, 2017
Undefined Behavior in Unit Test
View ub.md

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;
  }
View after (avx2).txt
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
View enum-from-any.swift
import Foundation
enum Enum: Int {
case one = 1
case two = 2
}
func enumFromAny<T>(_ ctor: (Int) -> T?, _ v: Any) -> T? {
if let n = v as? NSNumber {
return ctor(n.intValue)
View deinit.swift
var count: Int = 1234
class C {
init() {
myThing = count
count += 1
Swift.print("🇺🇸 Entry")
}
deinit {
You can’t perform that action at this time.