Skip to content

Instantly share code, notes, and snippets.

View pepijndevos's full-sized avatar

Pepijn de Vos pepijndevos

View GitHub Profile
(def actions (atom {}))
(defn register [action function]
(swap! actions assoc action (conj (action @actions) function)))
(defn do-action [action arg]
(reduce #(%2 %1) arg (action @actions)))
(defmacro maze-thread [value & exprs]
(let [gen (gensym)]
(concat
`(let [~gen (atom ~value)])
(map (fn [expr] `(swap! ~gen (fn [~'%] ~expr))) exprs))))
(require 'clojure.contrib.lazy-seqs)
(defmacro fib [nr]
(let [fibfn (gensym fib)]
`(let [~fibfn (fn [nrs#] [(peek nrs#) (+ (first nrs#) (peek nrs#))])]
(-> [0 1] ~@(take nr (repeat fibfn))))))
(println (time (last (fib 10))))
(println (time (nth (clojure.contrib.lazy-seqs/fibs) 11)))
# implementation
from pymouse import PyMouseEventMeta
import systembridge
from threading import Thread
class PyMouseEvent(PyMouseEventMeta):
def __init__(self):
click_tap = systembridge.get_event_tap(mousepress | mouserelease)
move_tap = systembridge.get_event_tap(mousemove)
from Quartz import *
def MyFunction(*args):
print args
tap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, kCGEventLeftMouseDown, MyFunction, None)
runLoopSource = CFMachPortCreateRunLoopSource(None, tap, 0)
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode)
CGEventTapEnable(tap, True)
from Xlib.display import Display
from Xlib import X
from Xlib.ext import record
from Xlib.protocol import rq
# True if you want to stop events from reaching other apps
capture = True
def record_callback(reply):
data = reply.data
#!/usr/bin/python
#
# $Id: record_demo.py,v 1.2 2007/06/10 14:11:59 mggrant Exp $
#
# examples/record_demo.py -- demonstrate record extension
#
# Copyright (C) 2006 Alex Badea <vamposdecampos@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
from pymouse import PyMouseEvent
class event(PyMouseEvent):
def move(self, x, y):
print "Mouse moved to", x, y
def click(self, x, y, button, press):
if press:
print "Mouse pressed at", x, y, "with button", button
else:
import pythoncom, pyHook
from time import sleep
from pymouse import PyMouseMeta, PyMouseEventMeta
class PyMouseEvent(PyMouseEventMeta):
def __init__(self):
PyMouseEventMeta.__init__(self)
self.listen = True
self.start()
def run(self):
import pygame
from pymouse import PyMouse
from time import sleep
# edit this to reflect your joystick axis and buttons
action = {'x':0, 'y':1, 'multiplier':3, 'left':0, 'right':1}
pygame.init()
j = pygame.joystick.Joystick(0) # first joystick
j.init()