Skip to content

Instantly share code, notes, and snippets.

View tef's full-sized avatar
💭
Please don't try to contact me over GitHub.

tef tef

💭
Please don't try to contact me over GitHub.
View GitHub Profile

When I was a younger, petulant mess of a programmer, I too waltzed into python and the explicit self. I'd done Java, JavaScript, and a handful of terrible languages not even worth mentioning. I didn't like it much, but I'd often used /this.foo/ instead of /foo/ in Java. I liked to be able to see what I was doing. I wasn't so keen on what seemed to be self sneaking into my method arguments. Now I've been using python for a bit, it's probably the best feature of python.

Let's take a step back and look why it's there and what it does for us: Python doesn't have methods: It has functions in classes. This means you can call a method explicitly on an object, ClassName.method(object, args). This also means you can pull the function out and assign it to other classes, ClassOne.foo = ClassTwo.foo. It also means that obj.foo() is actually two operations, method = obj.foo; method(). The choice of making methods out functions gives us unique ways to build classes, and also lets us take a method and pass it around as a

$ cat foo.py
def foo(x):
return x
$ cat bar.py
from foo import foo
def bar():
return foo.x
$ cat baz.py
from foo import foo
irb(main):056:0> Object::Object
=> Object
irb(main):057:0> Object.new::Object
TypeError: #<Object:0x007ff1fa842b48> is not a class/module
	from (irb):57
	from /usr/local/var/rbenv/versions/2.2.2/bin/irb:11:in `<main>'
# tilda example
import ugfx
import buttons
import pyb
import math
from imu import IMU
ugfx.init()
buttons.init()
#!/bin/bash -x
PID=`docker run -v $(pwd):/workdir -d --privileged -i --rm ubuntu /bin/bash`
docker exec $PID apt-get -q -y update
docker exec $PID apt-get -q -y install debootstrap
docker exec $PID debootstrap --arch amd64 xenial /rootfs http://archive.ubuntu.com/ubuntu
docker exec $PID cp -r /rootfs/ /workdir
echo exit | docker attach $PID
echo "Dockerfile" > rootfs/.dockerignore
@tef
tef / twmrc
Created September 2, 2017 02:29
## tef's theme
#
# How to use my key config.
#
# On Desktop Windows
# Meta+Mouse1 = Move or Raise
# Meta+Mouse2 = Hide
# Meta+Mouse3 = Resize or Lower
#
# On Icon Bar
@tef
tef / catbus.md
Last active February 8, 2018 16:52

The Client

$ export CATBUS_URL='http://127.1:8888/test'
$ alias catbus='pipenv run python3 -m catbus.client'

$ catbus
DEBUG Fetching http://127.1:8888/test

    url: http://127.1:8888/test/
import csv
import collections
import datetime
dates = {}
with open('tweets.csv') as fh:
fh.readline()
reader = csv.reader(fh)
for row in reader:
@tef
tef / README.md
Last active October 21, 2024 00:14

undo/redo persistent example

$ ./undo.py do 1
do: 1

$ ./undo.py do 2
do: 2

$ ./undo.py do 3
@tef
tef / vex
Created April 24, 2018 15:50
$ vex
vex -- a database for files
usage: vex [help] <init|undo|redo|status|log|diff|...> [--help]
description:
vex is a command line program for saving changes to a project, switching between different versions, and sharing those changes.
vex supports bash completion: run `complete -o nospace -C vex vex`