Skip to content

Instantly share code, notes, and snippets.

View jeffs's full-sized avatar

Jeff Schwab jeffs

View GitHub Profile
@jeffs
jeffs / death.sh
Created July 25, 2019 02:52
Launch a process in the background, then kill it after an hour.
# Dummy function. In your case, blast2 is a real program.
blast2() {
let 'i = 0'
while true; do
let 'i++'
echo $i
sleep 1
done
}
@jeffs
jeffs / bashrc
Created December 14, 2018 20:56
Touching files in new directories
touch() {
for f in "$@"; do
mkdir -p "$(dirname "$f")" && /usr/bin/touch "$f"
done
}
@jeffs
jeffs / Dockerfile
Created July 29, 2018 21:14
Alpine prerequisites for `pip install apache-airflow`
FROM alpine
RUN apk update \
&& apk add alpine-sdk linux-headers \
python py3-pip python3-dev \
py3-libxml2 libxml2-dev libxslt-dev
# ====================================================================
# All commands below this paragraph are from the quick-start guide at:
# http://airflow.apache.org/installation.html
@jeffs
jeffs / CMakeLists.txt
Created March 18, 2018 20:18
Build file
cmake_minimum_required(VERSION 3.9)
project(Play LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
include_directories(${PROJECT_SOURCE_DIR})
add_executable(main main.cpp)
@jeffs
jeffs / README.md
Last active May 16, 2020 13:19
Jeff Schwab's Resume
@jeffs
jeffs / main.cpp
Created June 16, 2017 16:35
elements of constexpr arrays are constexpr
// c++ -std=c++1z -pedantic -Wall main.cpp
constexpr int xs[]{ 1, 2 };
constexpr int ys[*xs]{};
template<int N> struct wrap { enum { value = *xs }; };
template<int N> constexpr int wrap_v = wrap<N>::value;
int main() {
static_assert(xs[0] == 1, "head of xs must be 1");
@jeffs
jeffs / Main.java
Last active May 29, 2017 23:33
counting the days
import java.io.PrintWriter;
class Main {
public static void main(String[] args) {
final double seconds = 400_000;
final double minutes = seconds / 60;
final double hours = minutes / 60;
final double days = hours / 24;
PrintWriter out = new PrintWriter(System.out, true);
out.println(days);
@jeffs
jeffs / bylen.cpp
Created May 13, 2017 00:22
Program to count lines by length
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <map>
#include <unordered_set>
#include <string>
template <class K, class V> using Map = std::map<K, V>;
template <class T> using Set = std::unordered_set<T>;
@jeffs
jeffs / library.cpp
Created September 3, 2016 16:01
trailing bools
struct some { };
// before: a function that does *almost* what someone wants
void f(some args) { /* ... */ }
// after: trailing bool with default value (so existing callers don't break)
void f(some args, bool b =true) {
// ...
if (b) /* old behavior */ ;
else /* new behavior */ ;
@jeffs
jeffs / pig.cpp
Last active June 23, 2016 21:39
Purely functional Pig Latin.
/** @file pig.cpp Purely functional Pig Latin.
*
* \code{.sh}
* $ clang++ -o pig -std=c++14 -pedantic -Wall pig.cpp
* $ ./pig hello world
* ellohay orldway
* \endcode
*
* @todo Preserve case.
* @todo Respect punctuation.