Skip to content

Instantly share code, notes, and snippets.

@emk
emk / phase.ks
Created February 18, 2018 20:36
Kerbal Space Program satellite orbit phasing using kOS and MechJeb
// Change the phase of your orbit, that is, advance yourself a certain
// amount of time along the same orbit path.
//
// See https://en.wikipedia.org/wiki/Orbit_phasing for the math and lots
// of explanations.
//
// AUTHOR: Eric Kidd.
//
// REQUIREMENTS: To run this, you'll need Kerbel Space Program, the kOS mod,
// and a computer on your craft.
@emk
emk / nginx-proxy-taskdef-draft.json
Created May 14, 2017 21:22
nginx-proxy ECS config (untested)
{
"containerDefinitions": [
{
"name": "nginx-proxy",
"image": "771600087445.dkr.ecr.us-east-1.amazonaws.com/nginx-proxy:latest",
"memory": "128",
"essential": true,
"portMappings": [
{
"hostPort": "443",
@emk
emk / Application.elm
Created December 1, 2015 13:06
Elm case matching on complex records?
type alias Model =
{ errorMessage: Maybe String -- This is what Rails would call a "flash": we just show it.
, video: Maybe Video.Model -- Information about a video and subtitles.
, player: Maybe VideoPlayer.Model -- Player state: URL, playing/paused, time.
}
type Action
= VideoLoaded Video.Model
| VideoPlayerAction VideoPlayer.Action
@emk
emk / fn_trait.rs
Last active August 29, 2015 14:21
Implementing traits for function types?
// Based on:
// https://github.com/emk/jit.rs/blob/master/src/macros.rs#L41-L64
// https://github.com/emk/jit.rs/blob/master/src/compile.rs#L105-L109
// https://github.com/emk/jit.rs/blob/master/examples/hello_world.rs#L22
// Build on branch:
// https://github.com/emk/jit.rs/tree/rust-beta-updates
trait Foo {}
impl Foo for fn() {}
@emk
emk / gist:51dee73348e2cc5f4077
Created April 29, 2015 18:45
Vault's GitHub auth module doesn't explain its config options
$ vault help auth/github/config
Error reading help: Error making API request.
URL: GET http://127.0.0.1:8200/v1/auth/github/config?help=1
Code: 500. Errors:
* unsupported operation
@emk
emk / keybase.md
Created February 25, 2015 19:51
keybase.md

Keybase proof

I hereby claim:

  • I am emk on github.
  • I am emk (https://keybase.io/emk) on keybase.
  • I have a public key whose fingerprint is C641 D85B 8218 678E 41F5 7961 5533 ABC9 38D4 BE26

To claim this, I am signing this object:

@emk
emk / csv2pbo
Created December 23, 2014 16:40
Convert CSV files to PBO parallel bilingual books
#!/usr/bin/env ruby
#
# Usage:
# csv2pbo book.csv > book.pbo
require 'csv'
path = ARGV[0]
# PBO format _looks_ like XML, but the parser is very fragile. So we
@emk
emk / multithreaded-traits.rs
Created December 15, 2014 23:00
Multithreaded trait access
use std::sync::Arc;
use std::sync::RWLock;
use std::task::spawn;
trait Common : Sized + Send + Sync {
fn munge(&mut self);
}
#[deriving(Show)]
struct Foo { i: int }
@emk
emk / call.rs
Created December 12, 2014 11:09
Can't call through trait
/// Call the global JavaScript function named `fn_name` with `args`, and
/// return the result.
pub fn call<'a>(&mut self, fn_name: &str,
args: &[&Encodable<Encoder<'a>, DuktapeError>]) ->
DuktapeResult<Value<'static>>
{
unsafe {
assert_stack_height_unchanged!(self, {
duk_push_global_object(self.ptr);
fn_name.with_c_str(|c_str| {
@emk
emk / context_error.rs
Created December 10, 2014 19:16
Having trouble with Rust encoder lifetime & trait
// Try this on http://play.rust-lang.org/
extern crate libc;
extern crate serialize;
use std::ptr::null_mut;
use libc::c_void;
// This needs to be mutable in practice.
pub struct Context;