Skip to content

Instantly share code, notes, and snippets.

View adamkewley's full-sized avatar

Adam Kewley adamkewley

View GitHub Profile
@adamkewley
adamkewley / SerialPortExtensions.cs
Created December 4, 2015 20:33
Extension methods to make System.IO.Ports.SerialPort easier to use with .NET 4.5 async workflows (Does not support timeouts)
using System.IO.Ports;
namespace AsyncExtensions {
public static class SerialPortExtensions
{
/// <summary>
/// Read a line from the SerialPort asynchronously
/// </summary>
/// <param name="serialPort">The port to read data from</param>
/// <returns>A line read from the input</returns>
@adamkewley
adamkewley / JwtAuthFilter.java
Created December 22, 2016 09:43
Dropwizard JWT Authentication Filter
import io.dropwizard.auth.AuthenticationException;
import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.Authorizer;
import javax.annotation.Priority;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.SecurityContext;
import java.io.IOException;
@adamkewley
adamkewley / calculate-scouting-success.rb
Last active December 31, 2016 11:20
Calculting monty hall effect for starcraft zergling scouting (Sam)
class Array
def select_random
return self.sample
end
def select_random_that_isnt(*excluded_vals)
selected_value = self.select_random
if excluded_vals.include? selected_value
return self.select_random_that_isnt(*excluded_vals)
@adamkewley
adamkewley / tests.yml
Created May 18, 2018 13:13
Tests file used by internal jobson test framework
---
tests:
should_work:
inputs:
somestring: someval
somelist:
- val1
expectations:
isAccepted: true
@adamkewley
adamkewley / jobson_test.py
Created May 18, 2018 13:15
High-level script for testing specs via a Jobson API
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#include <vector>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cerrno>
#include <chrono>
#include <string>
using std::chrono::time_point;
using std::chrono::microseconds;
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#include <iostream>
#include <iterator>
#include <vector>
#include <string>
#include <immintrin.h>
using std::istream;
using std::ostream;
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#include <iostream>
#include <string>
#include <immintrin.h>
using std::istream;
using std::ostream;
using std::runtime_error;
using std::string;
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#include <iostream>
#include <string>
#include <immintrin.h>
#include <array>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <iostream>
#include <string>
#include <immintrin.h>
#include <array>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <vector>