Skip to content

Instantly share code, notes, and snippets.

@probablytom
probablytom / pdsf.py
Created June 2, 2020 09:13
PyDySoFu version 3
from inspect import isfunction, isclass, ismethod
import re
import builtins
from functools import wraps, partial, reduce
from copy import deepcopy
import ast
import copy
import inspect
@probablytom
probablytom / pdsf3.py
Last active May 19, 2020 08:45
A Python3 compatible Asp implementation
class AspectHooks:
pre_rules = list()
around_rules = list()
post_rules = list()
def __enter__(self, *args, **kwargs):
self.old_import = __import__
import builtins
@app.route("/dereferences")
@app.route("/dereferences/<format>")
def new_fix_dereferences(format="json"):
bad_games = []
checked = []
for player in players.find({'Username': {'$exists': True}}):
for game_id in player['Games']:
if game_id != 'none' and game_id != 'waiting' and game_id not in checked:
@probablytom
probablytom / api_sample.py
Last active November 4, 2019 15:56
Flask API sample for William
# The easiest way to make REST apis in Python is usually to use flask. You can use Django if you want too, but it's heavier, and this will get the job done fine (and help you unerstand more about what it is that's going on).
from flask import Flask, request
from bson.json_util import dumps
import ast
import json
app = Flask(__name__)
domain = "tom.coffee"
@probablytom
probablytom / sicsa_post.md
Created October 19, 2018 12:18
SICSA blog article from Tom

PWSAfrica 2018

This July, five adventurers from Glasgow University set foot in Nigeria to run Programming Workshops for Scientists in Africa (PWSAfrica)'s first event. The workshop was certainly successful, supporting 120 attendees in learning the basics of Python programming over two weeks, and we're very proud of what we've achieved!

Naturally, in running an event like this, there were all sorts of details to be covered if our efforts were to be fruitful. What would we teach? How would it be

@probablytom
probablytom / incrementing_structs.go
Last active July 18, 2018 16:53
Weird incrementing structs
package SelfIncrementingStruct
import "SelfManagingStructs/TomTypes"
var (
runAlready = false
CollectionSize = 5
usageLimit = 3
SMSCollection = make(chan TomTypes.SelfManagingStruct, CollectionSize)
@probablytom
probablytom / incrementing_structs.go
Last active July 18, 2018 15:34
Self-Managing, configurable structs for Edinburgh's Golang Developer Meetup, July '18
package SelfIncrementingStruct
import "SelfManagingStructs/TomTypes"
var (
runAlready = false
CollectionSize = 5
usageLimit = 3
SMSCollection = make(chan TomTypes.SelfManagingStruct, CollectionSize)
@probablytom
probablytom / aop.py
Created June 4, 2018 22:15
A really simple example of the mechanism ASP uses for AOP
from functools import partial
def weave(target_class, advice):
original_getattribute = target_class.__getattribute__
# Hack around bound / unbound methods
for target, adv in advice.items():
advice[target.im_func] = adv
def __new_getattribute__(self, item):
@probablytom
probablytom / README.md
Last active November 20, 2017 21:59
Easy ssh to SAND

Getting easy ssh

Take the below configuration, edit in your username for both entries, and copy it into ~/.ssh/config on your local machine.

When you want to access sibu, try:

ssh sibu
@probablytom
probablytom / ChannelTest.go
Last active May 9, 2023 07:32
An experiment to see whether Golang channels evaluate the values to pass along a blocking channel before or after the blocking channel is called upon for a value by another routine.
package main
import "time"
func main() {
// Variables we'll need
x := make(chan int)
y := make(chan int, 1)
// If chaining channels together will present old values rather than new ones, we'll see a deadlock instead of 6.