Skip to content

Instantly share code, notes, and snippets.

View joshkel's full-sized avatar

Josh Kelley joshkel

View GitHub Profile
@joshkel
joshkel / protobuf_test.py
Created September 25, 2018 02:23
Python Protocol Buffers differences
#!/usr/bin/env python3
# Test file demonstrating issues from
# https://github.com/protocolbuffers/protobuf/pull/5166
# Try running with PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
# and with PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
import subprocess
proto_definition = """
syntax = "proto2";
@joshkel
joshkel / LeftJoin2.cs
Created August 8, 2018 03:23
LeftJoin using a generator
// Based on https://gist.github.com/reidev275/f765c506aea0e3e3432da591b2c30c15#file-leftJoin-cs
public struct Join<A, B>
{
public A First { get; set; }
public B Second { get; set; }
}
public static IEnumerable<Join<A, B>> LeftJoin2<A, B, C>(this IEnumerable<A> from, IEnumerable<B> join,
Func<A, C> onFrom, Func<B, C> onJoin) where C : IComparable<C>
@joshkel
joshkel / protobuf-1450-workaround.md
Last active April 23, 2017 03:01
Google Protocol Buffers UBSan workarounds

A hack / workaround for google/protobuf#1450, to get a stock version of Protocol Buffers 2.6.1 to work under UBSan. This is useful for (e.g.) building applications on Ubuntu 14.04 or 16.04, where you want to continue using the distro-provided protobuf library packaging instead of upgrading or patching the source.

There are two steps.

Step 1

Replace every 16 in the generated .pb.cc files with this. For example, if you use GNU Make to generate your .pb.cc files:

%.pb.cc %.pb.h %_pb2.py: %.proto
'''
adminreverse from here http://djangosnippets.org/snippets/2032/
changed for working with ForeignKeys and updated for Django 1.8
'''
'''
reverseadmin
============
Module that makes django admin handle OneToOneFields in a better way.
A common use case for one-to-one relationships is to "embed" a model
@joshkel
joshkel / VclFormPtr.cpp
Created November 10, 2010 20:24
boost::scoped_ptr and boost::shared_ptr equivalents for C++Builder forms
/**Releases or immediately deletes a form, as appropriate. Deleting a form
* has unprocessed events or messages may cause memory errors, but calling
* Release() on a form that only exists in memory (with no corresponding window)
* needlessly creates a window (by accessing the Handle property). See
* CodeGear's documentation for TCustomForm::Release.
*/
inline void DeleteOrRelease(TCustomForm *f)
{
if (f->HandleAllocated()) {
f->Release();