Skip to content

Instantly share code, notes, and snippets.

View obmarg's full-sized avatar

Graeme Coupar obmarg

  • London
  • 18:57 (UTC +01:00)
View GitHub Profile
@seanjensengrey
seanjensengrey / rust-python-cffi.md
Last active April 3, 2024 11:55
Calling Rust from Python/PyPy using CFFI (C Foreign Function Interface)

This is a small demo of how to create a library in Rust and call it from Python (both CPython and PyPy) using the CFFI instead of ctypes.

Based on http://harkablog.com/calling-rust-from-c-and-python.html (dead) which used ctypes

CFFI is nice because:

  • Reads C declarations (parses headers)
  • Works in both CPython and PyPy (included with PyPy)
  • Lower call overhead than ctypes
@andytill
andytill / Covering more with unit tests.md
Created May 25, 2015 15:20
Covering more with unit tests

Covering more with unit tests

Unit tests are quick to run, quick to write in bulk, target a small area of code, are not prone to timing issues and other intermittent failures and have excellent reporting tools.

However, actual usage is often prevented by side effects which require resources such as processes, ports and ets tables to exist or will crash the test.

Separating code into pure and impure functions can help and is typically beneficial. It can also harm readability, and even then not enable full coverage using unit testing. For example:

receive_message(Msg) ->
@skippy
skippy / cloud-config.yml
Created December 31, 2014 18:38
modifying fleet metadata (from aws meta-data service) before fleet.service start; this is a proof of concept (but it works!)
#cloud-config
---
coreos:
units:
- name: update-fleet-metadata.service
command: start
content: |-
[Unit]
Description=Update Fleet metadata tag
Before=fleet.service
@gvx
gvx / named.py
Created December 11, 2014 23:28
An alternative namedtuple
from collections import OrderedDict
from inspect import Parameter, signature
from itertools import chain, starmap
from operator import itemgetter
__all__ = ['namedtuple']
dict_property = property(lambda self: OrderedDict(zip(self._fields, self)),
doc='dictionary for instance variables (if defined)')
@paf31
paf31 / 24days.md
Last active August 8, 2023 05:53
24 Days of PureScript

This blog post series has moved here.

You might also be interested in the 2016 version.

@joakimk
joakimk / README.md
Last active January 1, 2022 23:21
CircleCI elixir build example

This runs a build for a small elixir (phoenix) project in about 40 seconds by caching as much of the compiled files as possible.

We've been using this for months in multiple projects without any issues. Please ping be if there is any issues with this script and I'll update it.

It should be generic enough to work on any elixir app using mix.

If you have a elixir_buildpack.config, then enable that section in the build script to keep versions in sync!

2016-08-09: Updated to newer Erlang and Elixir and fixed curl command.

(Chapters marked with * are already written. This gets reorganized constantly
and 10 or so written chapters that I'm on the fence about aren't listed.)
Programmer Epistemology
* Dispersed Cost vs. Reduced Cost
* Verificationist Fallacy
* Mistake Metastasis
The Overton Window
Epicycles All The Way Down
The Hyperspace Gates Were Just There
@eevee
eevee / weakproperty.py
Last active August 29, 2015 14:02
weakproperty
class WeakProperty:
"""Descriptor that automatically holds onto whatever it contains as a weak
reference. Reading this attribute will never raise `AttributeError`; if
the reference is broken or missing, you'll just get `None`.
The actual weak reference is stored in the object's `__dict__` under the
given name, so this acts as sort of a transparent proxy that lets you
forget you're dealing with weakrefs at all.
Of course, if you try to assign a value that can't be weak referenced,
@staltz
staltz / introrx.md
Last active May 3, 2024 13:00
The introduction to Reactive Programming you've been missing