Skip to content

Instantly share code, notes, and snippets.

@internetimagery
internetimagery / do_notation_comprehension.py
Last active September 6, 2021 02:41
Do notation as for comprehension in python
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@ssokolow
ssokolow / Cargo.toml
Last active April 14, 2021 21:43
Simple example of getting the rust-cpython and setuptools-rust examples working together
[package]
name = "unimportant_if_subsumed_by_setuptools"
version = "0.1.0"
authors = ["Your Name Here <your@email.com>"]
[lib]
name = "unimportant_if_subsumed_by_setuptools"
crate-type = ["cdylib"]
[dependencies.cpython]
"""
Utilities for building concurrent PyQt5 applications.
"""
from __future__ import absolute_import
import threading
import weakref
import logging
import warnings

The logical relations between Go scoring systems

What is the simplest Go scoring system? It's this:

  • Stone Scoring: just count the stones on the board

At the end of the game, both players will want to fill in as much of their own territory as they can, while allowing two eyes per group (so they aren't captured). Then the winner is just the player with more stones on the board. Note that prisoners are not counted.

But nobody wants to play all these extra stones at the end. So we can instead use:

@internetimagery
internetimagery / __init__.py
Last active October 6, 2015 16:16
Auto load submodules in a package as they're used
# Stick the following in the bottom of your __init__.py, then simply import the base package. Use submodules as you need them and they'll be imported as you go.
import sys as _sys
class Package(object):
def __init__(s, local):
import os.path
s.cache = {}
s.local = dict((k, local[k]) for k in local)
s.root = os.path.realpath(os.path.dirname(s.local["__file__"]))
def __getattr__(s, k):
if k in s.local: return s.local[k]
@bboyle
bboyle / GraphEditorToggle
Created March 21, 2015 02:36
Open/close Maya graph editor (MEL script)
if (`window -q -ex graphEditor1Window`)
deleteUI graphEditor1Window;
else
tearOffPanel "Graph Editor" "graphEditor" true;
@aperley
aperley / vector.py
Last active October 26, 2015 13:07
Vector.py
class Vector(object):
def __init__(self, components):
self.components = components
self.dims = len(components)
def __add__(self, other):
self._check_dims(other)
return self.__class__([comp1 + comp2 for comp1, comp2 in zip(self.components, other.components)])
def __sub__(self, other):
@JeffBelgum
JeffBelgum / list_comprehensions.rs
Created September 26, 2014 00:03
Python list comprehensions in Rust
#![feature(macro_rules)]
/// MIT license etc. etc.
///
/// Experimenting with Python-like list comprehensions.
///
/// An attempt to explore the possibility space for ergonomic improvements
/// in Rust that can come post v1.0. Notice that there are not type declerations.
/// Aside from the "c!" macro invocation, Rust allows for an exact copy of the
/// Python comprehension syntax.
def download(url, dest):
with urllib.request.urlopen(url) as response, open(dest, 'wb') as out_file:
shutil.copyfileobj(response, out_file)
@motemen
motemen / git-commit-file-to-branch.sh
Created April 29, 2012 13:37
Commit a file to another branch
#!/bin/sh
BRANCH=$1
FILE=$2
if [ -z "$BRANCH" ]; then
echo "Usage: $0 <branch> <file>"
exit 1
fi