Skip to content

Instantly share code, notes, and snippets.

View davepape's full-sized avatar

Dave Pape davepape

View GitHub Profile
@davepape
davepape / LeapSample.py
Created November 21, 2013 14:50
Hacked version of Leap Motion's "Sample.py" from the v.1.0.9.8409 for Linux beta SDK. Takes the data from the Leap device and sends it out over UDP to a separate pyglet program.
################################################################################
# Copyright (C) 2012-2013 Leap Motion, Inc. All rights reserved. #
# Leap Motion proprietary and confidential. Not for distribution. #
# Use subject to the terms of the Leap Motion SDK Agreement available at #
# https://developer.leapmotion.com/sdk_agreement, or another agreement #
# between Leap Motion and you, your company or other organization. #
################################################################################
import Leap, sys
from Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture
@davepape
davepape / LeapPyglet-udp.py
Last active December 9, 2021 21:19
Pyglet program to receive hand & finger data from the hacked "LeapSample.py" program (via UDP) and render it in 2D
#
# Receive hand & finger data from "LeapSample.py" via UDP and render it in 2D
#
from pyglet.gl import *
# Create a UDP socket to receive the data
import socket
insock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Listen to port 5000
insock.bind(('',5000))
@davepape
davepape / LeapPyglet.py
Last active December 29, 2015 00:09
Single integrated program to read data from Leap Motion device and render it (in 2D) in pyglet
from pyglet.gl import *
window = pyglet.window.Window()
class Hand:
def __init__(self):
self.pos = [0,0,0]
self.ori = [0,0,0]
self.geom = pyglet.graphics.vertex_list(4, ('v2f', [-15,-10, 15,-10, 20,10, -20,10]))
def draw(self):
@davepape
davepape / map2.py
Created December 4, 2013 15:59
Draws a flat world map - 360x180 unit mesh of triangle strips, with biosphere map textured on it. Includes simple driving using the keyboard arrows.
from pyglet.gl import *
from math import *
tex = pyglet.image.load('biosphere.png').get_texture()
vlists = []
for lat in range(-90,90,30):
verts = []
texc = []
for lon in range(-180,181,30):
# Query the example "world" database using MySQLdb
import MySQLdb
db = MySQLdb.connect(host='localhost', port=3306, user='myusername', passwd='mypassword', db='world')
cur = db.cursor()
cur.execute("SELECT ID, Name, Population from City order by Name limit 3")
# Perform an 'update' query on the sample database, with data input by the user
import MySQLdb
db = MySQLdb.connect(host='localhost', port=3306, user='myusername', passwd='mypassword', db='world')
cur = db.cursor()
print 'enter new name for City 1:'
newname = raw_input()
#!/usr/bin/python
# Simple CGI python script that generates a web page dynamically
print '''Content-type: text/html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML form example</title>
</head>
<body>
<form method="post" action="world.cgi">
Country name? <input type="text" name="name" size="40" value="">
<br>
#!/usr/bin/python
# Query the 'world' database for a country whose name (or partial name) was entered via queryform.html
import MySQLdb
db = MySQLdb.connect(host='localhost', port=3306, user='myusername', passwd='mypassword', db='world')
cur = db.cursor()
cur.execute("set names 'utf8'")
# Script to insert a new city into the example 'world' database
import MySQLdb
db = MySQLdb.connect(host='localhost', port=3306, user='myusername', passwd='mypassword', db='world')
cur = db.cursor()
print "enter new city's name:"
name = raw_input()
print "enter new city's country code:"