Skip to content

Instantly share code, notes, and snippets.

@mkomitee
mkomitee / update-subtrees.py
Created May 23, 2011 00:02
Manage git subtrees
#!/usr/bin/env python
# Copyright 2011 Michael Komitee. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
#include <stdio.h>
#include <krb5.h>
/*
In krb5.h ...
krb5_error_code is defined as:
typedef int krb5_int32
typedef krb5_int32 krb5_error_code;
krb5_context is defined as:
struct _krb5_context;
typedef struct _krb5_context * krb5_context;
extern crate libc;
use libc::*;
use std::ptr;
#[allow(non_camel_case_types)]
#[repr(C)]
type krb5_error_code = c_uint;
#[allow(non_camel_case_types)]
@mkomitee
mkomitee / gist:17ca562f2429e03f6227
Last active August 29, 2015 14:20
Still no idea
extern crate libc;
#[allow(non_camel_case_types)]
#[repr(C)]
type krb5_error_code = libc::c_int;
#[allow(non_camel_case_types)]
#[repr(C)]
struct krb5_context;
// My objective is to return an environment variable parsed as an integer,
// and if either the environment variable isn't set, or it can't be parsed as
// an integer, return a default value.
// This works, but is kind of ugly ...
fn u32_from_env_with_default(env: &str, default: u32) -> u32 {
let tmp_1 = std::env::var(env);
if tmp_1.is_ok() {
let tmp_2 = tmp_1.unwrap().parse::<u32>();
if tmp_2.is_ok() {
@mkomitee
mkomitee / gist:a67589d7f9d3c9b23105
Last active August 29, 2015 14:21
systemd stuff
# .../all-services-ready.target
[Unit]
Description=All Services Ready
AllowIsolate=yes
Wants=multi-user.target
After=multi-user.target
# .../manage-services.service
[Unit]
Description=Manage Services
fn main() {
let mut exit_code = 0;
{
// real work which may mutate exit_code
exit_code = 1;
}
process::exit(exit_code);
}