Skip to content

Instantly share code, notes, and snippets.

View softprops's full-sized avatar
®️
Rustling

Doug Tangren softprops

®️
Rustling
View GitHub Profile
#!/bin/env bash
# git branch freshness test.
# branch-rot.sh [expiration-date-epoc-seconds]
# default expiration date is about one month ago
# seconds*minutes*hours*days*weeks*months ~ one month ago
expiration_date=$(( $(date +%s) - 60*60*24*7*4 ))
if [[ $# -eq 1 ]]; then
expiration_date=$1
fi
require 'net/http'
def instance_zone
uri = URI("http://metadata.google.internal/computeMetadata/v1/instance/zone")
req = Net::HTTP::Get.new(uri)
req['Metadata-Flavor'] = 'Google'
begin
resp = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }
resp.body.split("/").last
rescue Exception => msg
puts "failed to request instance zone: #{msg}"
# vscode rust seti[
use vscode-rust ( not rusty )
rustup component install rust-src
rustup component install rust-docs
rustup update
rustup which rust-src ( save this path )
cargo install --force racer
cargo install --force rustfmt
cargo install --force rustsym
#!/bin/bash
jarfile1=$1
jarfile2=$2
tmpdir=`mktemp -d -t jiff-XXX`
echo $tmpdir
mkdir -p $tmpdir/{dir1,dir2}
cp $jarfile1 $tmpdir/dir1
cp $jarfile2 $tmpdir/dir2
cd $tmpdir/dir1
jar xvf $(basename $jarfile1)
// env! gets inserted at compile time, not run time
// https://doc.rust-lang.org/std/macro.env.html
const BUILD: &str = env!("BUILD_NUM");
fn main() {
println!("was built with {}", BUILD);
}
#!/bin/bash
# prints differences in files
first=$1
second=$2
diff \
<(tar -tvf $first | awk '{printf "%10s %-100s %s\n",$3,$6,$1}'|sort -k2) \
<(tar -tvf $second |awk '{printf "%10s %-100s %s\n",$3,$6,$1}'|sort -k2)
@softprops
softprops / graph-workspace.sh
Last active February 27, 2017 04:55
create a high level graph of library dependencies within a given bazel workspace ( targets scala and java projects )
#!/bin/bash
bazel query --noimplicit_deps 'kind("(scala|java)_*", deps(//...))' --output graph > build.dot
dot -Tpng < build.dot > build.png
# starts, when needed, a daemonized bazel container which receives
# sets of bazel arguments
docker_bazel() {
local project=$(echo $PWD | base64)
project=${project%%=*}
docker inspect bazel-$project >/dev/null
if [ $? -ne 0 ]; then
docker run --privileged=true -d -it --name bazel-$project -v "$PWD":/usr/src/app insready/bazel
if [ $? -ne 0 ]; then
echo "failed to start bazel container. bailing"
struct Config {
secret: String,
coolfactor: f32,
prize: Option<usize>
}
extern crate envy;
use std::env;
#[derive(Deserialize, Debug)]
struct Config {
secret: String,
coolfactor: f32,
prize: Option<usize>
}