Skip to content

Instantly share code, notes, and snippets.

View U007D's full-sized avatar

Brad Gibson U007D

View GitHub Profile
@U007D
U007D / main.cpp
Last active September 11, 2016 01:10
Compiler-Enforced Semantic Types Sample Implementation (based on Bjarne Stroustrup's talk at https://youtu.be/0iWb_qi2-uI?t=19m6s)
//Compiled with clang -std=c++14 -Weverything -Wno-c++98-compat main.cpp -o main
#include <iostream>
#include <string>
template<int M, int K, int S> //Meters, Kilograms, Seconds (MKS)
struct Unit
{
enum { m=M, kg=K, s=S };
};
@U007D
U007D / BowlingGame.cpp
Last active December 21, 2016 14:34
Bowling Game Kata in C++14 (using range-v3)
//Can be called by client as follows: ScoreRollsByFrame({10, 3, 5, /* ... valid set of rolls */ })
//Note: Cast required since C++'s usual arithmetic conversions yield u16 + u8 -> i32 (!)
#include "range/v3/all.hpp"
uint16_t Score(const std::vector<uint8_t>& rolls, const uint8_t frame)
{
return frame > 10 || ranges::empty(rolls)
? 0
: static_cast<uint16_t>(ranges::accumulate(rolls
| ranges::view::take(rolls[0] + rolls[1] >= 10 ? 3 : 2), 0)
@U007D
U007D / gist:82a36ecf327e89e453efbc92a736d913
Last active February 17, 2017 18:50
Installing TensorFlow
(IntroToTensorFlow) Socrates:udacity-sdc bRad$ python3
Python 3.6.0 |Anaconda 4.3.0 (x86_64)| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/bRad/anaconda3/envs/IntroToTensorFlow/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/Users/bRad/anaconda3/envs/IntroToTensorFlow/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 44, in <module>
#include <iostream>
using namespace std;
using Range = std::pair<double, double>;
using Range2D = std::pair<Range, Range>;
inline Range2D MakeIt(double xMin, double xMax, double yMin, double yMax)
{
return Range2D(Range(xMin, xMax), Range(yMin, yMax));
}
cat ~/.cargo/config
[target.arm-none-eabi]
linker = "arm-none-eabi-gcc"
Socrates:hello bRad$ cargo build --target=arm-none-eabi
error: failed to run `rustc` to learn about target-specific information
To learn more, run the command again with --verbose.
Socrates:hello bRad$ cargo build --target=armv7-unknown-linux-gnueabihf
Compiling hello v0.1.0 (file:///Users/bRad/Development/bg/experiments/rust/rpi3/hello)
error: linking with `arm-none-eabi-gcc` failed: exit code: 1
|
= note: "arm-none-eabi-gcc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-L" "/Users/bRad/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/armv7-unknown-linux-gnueabihf/lib" "/Users/bRad/Development/bg/experiments/rust/rpi3/hello/target/armv7-unknown-linux-gnueabihf/debug/deps/hello-482a13dcff2890d3.0.o" "-o" "/Users/bRad/Development/bg/experiments/rust/rpi3/hello/target/armv7-unknown-linux-gnueabihf/debug/deps/hello-482a13dcff2890d3" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/Users/bRad/Development/bg/experiments/rust/rpi3/hello/target/armv7-unknown-linux-gnueabihf/debug/deps" "-L" "/Users/bRad/Development/bg/experiments/rust/rpi3/hello/target/debug/deps" "-L" "/Users/bRad/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/armv7-unknown-linux-gnueabihf/lib" "-Wl,
@U007D
U007D / workspace.sh
Created February 26, 2017 16:54 — forked from dixson3/workspace.sh
Create and manage a case-sensitive disk-image on OSX. This is great when you have a need to work with case-sensitive repos on a mac.
#!/bin/bash
# where to store the sparse-image
WORKSPACE=~/Documents/workspace.dmg.sparseimage
create() {
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 60g -volname workspace ${WORKSPACE}
}
detach() {
@U007D
U007D / workspace.sh
Created February 26, 2017 16:54 — forked from dixson3/workspace.sh
Create and manage a case-sensitive disk-image on OSX. This is great when you have a need to work with case-sensitive repos on a mac.
#!/bin/bash
# where to store the sparse-image
WORKSPACE=~/Documents/workspace.dmg.sparseimage
create() {
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 60g -volname workspace ${WORKSPACE}
}
detach() {
xargo run --target armv7-unknown-linux-steedeabihf
Compiling core v0.0.0 (file:///Users/bRad/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore)
Compiling std_unicode v0.0.0 (file:///Users/bRad/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd_unicode)
Compiling alloc v0.0.0 (file:///Users/bRad/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/liballoc)
Compiling collections v0.0.0 (file:///Users/bRad/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcollections)
Finished release [optimized] target(s) in 19.41 secs
Compiling rand v0.0.0 (file:///Users/bRad/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/librand)
Finished release [optimized] target(s) in 1.58 secs
Updating git repository `https://github.com/japaric/steed`
Updating git repository `https://github.com/redox-os/ralloc`
trait ArgsExtensionMethods {
fn getOutputFilename(self) -> Option<String>;
// fn removeOutputFile(&self) -> Args;
// fn removeNoStartFiles(&self) -> Args;
// fn removeWlSwitches(&self) -> Args;
}
//
impl<T> ArgsExtensionMethods for T where T: IntoIterator<Item=String> {
fn getOutputFilename(self) -> Option<String> {
self.skip_while(|ref el| *el != "-o").next()