Skip to content

Instantly share code, notes, and snippets.

View garyp's full-sized avatar

Gary Peck garyp

View GitHub Profile
@garyp
garyp / Base64.kt
Created June 14, 2020 21:56
Base64 encoding/decoding implementation that can be used from the `common` sourceset of a Kotlin Multiplatform project.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
@garyp
garyp / PBAndKConverter.kt
Created January 6, 2020 21:26
Pbandk Retrofit converter
/*
* (C) Copyright 2019 Streem, Inc.
*
* 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
*
* Unless required by applicable law or agreed to in writing, software
@garyp
garyp / ifnull.kt
Created August 8, 2019 18:43
Kotlin `ifNull` and `ifNullAlso` functions
/**
* If [this] is not null, returns [this]. Otherwise returns the result of calling [block].
*
* This function can be used in two ways:
* 1. [block] provides a fallback value when [this] is null.
* 2. [block] provides an early return from the enclosing method when [this] is null:
* ```
* fun foo() {
* functionThatMightReturnNull().ifNull {
* log.warn("Got a null value")
@garyp
garyp / after.html
Last active March 6, 2016 19:35
Script for rendering a Markdown-formatted financial report (from generate_report.py) as a PDF
</div>
</div>
</div>
@garyp
garyp / generate_report.py
Created March 6, 2016 19:08
Script to generate Markdown-formatted financial reports for IO Coop based on beancount accounting data
#!/usr/bin/env python3
"""
Generates Markdown-formatted financial reports for the specified date range.
"""
import argparse
from collections import defaultdict
from datetime import date, datetime, timedelta
import sys
@garyp
garyp / tuple_invoker.cpp
Last active August 8, 2019 18:49
Invoke a function, using a tuple that contains the arguments to be passed to the function
#include <cstddef>
#include <iostream>
#include <future>
#include <thread>
#include <tuple>
#include <utility>
////
//// implementations of index_sequence and related types, based on C++14
////
@garyp
garyp / fn_args.cpp
Last active August 8, 2019 18:49
Declare a tuple whose type matches a function's arguments
// Example program
#include <iostream>
#include <tuple>
template <typename T>
struct fn_args {};
template <typename F, typename ...Args>
struct fn_args<F(Args...)> {
using tuple = std::tuple<Args...>;

Keybase proof

I hereby claim:

  • I am garyp on github.
  • I am garyp (https://keybase.io/garyp) on keybase.
  • I have a public key whose fingerprint is 1646 97C5 8260 A737 7D8E 44B1 0FA5 001F EAAE 4D44

To claim this, I am signing this object:

// Background average sample code done with averages and done with codebooks
/*
************************************************** */
//#include <cv.h>
//#include "cvaux.h"
//#include "cxmisc.h"
//#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
@garyp
garyp / gist:1408478
Created November 30, 2011 09:06
cyanogenmod gerrit push error
$ git push ssh://gary@review.cyanogenmod.com:29418/CyanogenMod/cm-kernel HEAD:refs/for/android-msm-2.6.37
Counting objects: 5675, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1277/1277), done.
Writing objects: 100% (5660/5660), 3.27 MiB | 2.21 MiB/s, done.
Total 5660 (delta 4393), reused 5551 (delta 4314)
To ssh://gary@review.cyanogenmod.com:29418/CyanogenMod/cm-kernel
! [remote rejected] HEAD -> refs/for/android-msm-2.6.37 (you are not committer charles)
error: failed to push some refs to 'ssh://gary@review.cyanogenmod.com:29418/CyanogenMod/cm-kernel'