Skip to content

Instantly share code, notes, and snippets.

@virtuald
virtuald / rawperf.py
Created June 3, 2016 20:22
NSQ performance tester
#!/usr/bin/env python
#
# Run this in three different terminal windows (presumes download of NSQD):
# - rm *.dat && ./nsqd
# - ./raw_perf.py read
# - ./raw_perf.py write
#
from __future__ import print_function
@virtuald
virtuald / context_local.py
Last active June 18, 2020 08:10
Implements a threadlocal-like mechanism for Tornado
'''
This is significantly derived from StackContext, Apache 2.0 license
'''
from tornado.stack_context import StackContextInconsistentError, _state
class ContextLocal(object):
'''
Implements a threadlocal-like mechanism that can be used to track data
across tornado asynchronous calls. This is very similar to (and based
@virtuald
virtuald / exposure_control.py
Created March 31, 2016 14:36
Allows setting the exposure at runtime on a RoboRIO (auto means you can see, dark limits the exposure for camera tracking)
import os
import shutil
import threading
import hal
import wpilib
import logging
logger = logging.getLogger('exposure_control')
#! /usr/bin/env python3
import wpilib
from robotpy_ext.control import xbox_controller
import magicbot
class MyRobot(magicbot.MagicRobot):
def createObjects(self):
self.driveStick = xbox_controller.XboxController(0)
#!/usr/bin/env python3
import threading
import wpilib
class MyRobot(wpilib.SampleRobot):
def robotInit(self):
c = threading.Condition()
@virtuald
virtuald / robot.py
Created January 21, 2016 04:39
Checking timing of IterativeRobot
#!/usr/bin/env python3
import collections
import time
import wpilib
class MyRobot(wpilib.IterativeRobot):
'''Main robot class'''
def robotInit(self):
package io.takari.incrementalbuild.spi;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@virtuald
virtuald / IndirectBuildContext.java
Created November 13, 2015 19:04
Takari incremental build context with indirect dependency support
package io.takari.incrementalbuild.spi;
import java.io.File;
import java.util.HashSet;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.maven.execution.scope.MojoExecutionScoped;
@virtuald
virtuald / download.sh
Created October 31, 2015 17:00
Download and unpack source RPM in one command
#!/bin/bash -e
PKG="$1"
SRPM=$(dnf download --source -v $PKG | tee /dev/stderr | grep -o '.*--> Package \:.*\:.*\.src\.rpm$' | rev | cut -f 1 -d' ' | rev | uniq)
rpm2cpio $SRPM | cpio -idmv
@virtuald
virtuald / treetest.py
Last active August 16, 2016 06:11
Buggy DnD behavior in PyGObject (fix at https://github.com/virtuald/pygi-treeview-dnd)
#!/usr/bin/env python
#
# Demonstrates potential buggy behavior in PyGObject+Treeview DnD
#
# Bug is that when do_drag_data_get is called, the selection_data argument
# appears to be discarded and never used, regardless of the return value
#
# This sample program should be executed like so:
#
# python treetest.py ~/some/path/*