links · people · groups · tags | My: links · tags · groups · watchlists · notes login · sign up now! | help · blog
Simpy simpy
 
Michael Shook, member since May 27, 2004
.
Search Everyone: "code",

Top "code" experts: glassesofkekkonen, myspacelayoutgraphics, fredb, adski, brillig, yabbas,

Groups about "code": codes, Medical coding, mobile Unlock codes, Success Code, Programming, House Info,

1 - 10 of 57 next »   Watch mshook
 
# Server program

from socket import *

# Set the socket parameters
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)

# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)

# Receive messages
while 1:
	data,addr = UDPSock.recvfrom(buf)
	if not data:
		print "Client has exited!"
		break
	else:
		print "nReceived message '", data,"'"

# Close socket
UDPSock.close()

# Client program

from socket import *

# Set the socket parameters
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)

# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)

def_msg = "===Enter message to send to server===";
print "n",def_msg

# Send messages
while (1):
	data = raw_input('>> ')
	if not data:
		break
	else:
		if(UDPSock.sendto(data,addr)):
			print "Sending message '",data,"'....."

# Close socket
UDPSock.close()
by mshook 2009-11-14 18:27 test · python · udp · example · code · simple · useful · works
http://www.evolt.org/node/60276 - cached - mail it - history
/*send the packet*/
send_result = sendto(s, buffer, ETH_FRAME_LEN, 0, 
	      (struct sockaddr*)&socket_address, sizeof(socket_address));
if (send_result == -1) { errorhandling... }

Example 1.6. Receive a RAW ethernet frame

void* buffer = (void*)malloc(ETH_FRAME_LEN); /*Buffer for ethernet frame*/
int length = 0; /*length of the received frame*/ 
...
length = recvfrom(s, buffer, ETH_FRAME_LEN, 0, NULL, NULL);
if (length == -1) { errorhandling .... }
by mshook 2009-10-15 22:15 ethernet · 802 · packet · howto · code · mac · ip · c · example
http://aschauf.landshut.org/fh/linux/udp_vs_raw/ch01s03.html - cached - mail it - history

* is Unix

Jacob Kaplan-Moss

October 7, 2009

by mshook 2009-10-08 00:07 c · ruby · python · example · code · minimal · server · viapopular · good · linux · perl · how · network · socket · process
http://jacobian.org/writing/star-is-unix/ - cached - mail it - history
via
http://twitter.com/programmingjoy
Javascript as Compiler Target: Clamato, GWT Smalltalk, Python, Scheme
http://www.infoq.com/news/2009/09/javascript-compilation-target

(require moby/stub/world)

(define WIDTH 320)
(define HEIGHT 480)

(define (render w)
  (place-image 
   (text "Hello World" 10 "Black")
   20
   20
   (empty-scene WIDTH HEIGHT)))

(big-bang WIDTH HEIGHT 10 0)
(on-redraw render)

After a few minutes of poking around, I was able to compile this to Java and then run it on the Android Emulator:

by mshook 2009-10-01 16:40 scheme · android · javascript · compiler · lisp · java · mobile · example · code · interesting
http://benjisimon.blogspot.com/2009/03/plt-scheme-meets-android-platform.html - cached - mail it - history
//dirt cheap wireless TX
//generates 38kHz carrier wave on pin 9 and 10
//sends data via TX every 500ms
void setup()
{
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);

  // Clear Timer on Compare Match (CTC) Mode
  bitWrite(TCCR1A, WGM10, 0);
  bitWrite(TCCR1A, WGM11, 0);
  bitWrite(TCCR1B, WGM12, 1);
  bitWrite(TCCR1B, WGM13, 0);

  // Toggle OC1A and OC1B on Compare Match.
  bitWrite(TCCR1A, COM1A0, 1);
  bitWrite(TCCR1A, COM1A1, 0);
  bitWrite(TCCR1A, COM1B0, 1);
  bitWrite(TCCR1A, COM1B1, 0);

  // No prescaling
  bitWrite(TCCR1B, CS10, 1);
  bitWrite(TCCR1B, CS11, 0);
  bitWrite(TCCR1B, CS12, 0);

  OCR1A = 210;
  OCR1B = 210;

  Serial.begin(2400);
}

void loop()
{
  Serial.println("testing testing testing");
  delay(500);
}


by mshook 2009-09-27 21:21 arduino · avr · code · timer · ir · infrared · receiver · transmitter · serial · howto · circuitled · modulation · c
http://tthheessiiss.wordpress.com/2009/08/05/dirt-cheap-wireless/ - cached - mail it - history
via http://tinyurl.com/ir-remote-control
To decode what the remote was sending, I used an oscilloscope and a small photodiode. The photodiode generates a small amount of voltage when light hits it, and responds to changes in light level quickly enough that the oscilloscope can draw a really nice plot of the signal. I have a Parallax USB oscilloscope, which is perfect for showing the command pulses and is just fast enough to find the modulation frequency. As an aside, I’m really happy with the Parallax oscilloscope for projects like this. It is simple to use and I love being able to save images to share with people.
Here’s what two of the commands from the dimmer remote look like. The top signal is the “fade lights up” command, and the bottom one is “fade lights down”:
oscilloscope image of 2 commands
by mshook 2009-09-22 22:48 ir · howto · oscilliscope · modulation · avr · arduino · project · code · infrared · control · wishlist · remote · usb
http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ - cached - mail it - history
I'm working on a project that uses data in JSON format  (www.json.org).  It took me a while to get it going in processing, so I thought I'd post what I did here.  If there's a better way (which undoubtedly there is!), please let me know.

Andrew Odewahn

--
Here are the steps I took (on Windows):

1.  Download http://www.json.org/java/json.zip from json.org.  Save it in a some directory, which I'll call %DOWNLOAD_HOME%.

2.  Unzip it.  Be sure you preserve the archive's directory structure (/org/json/) when you unzip the file.  

3.  Change directory into %DOWNLOAD_HOME%orgjson
by mshook 2009-09-22 10:48 processing · howto · json · java · code · library · emon
http://processing.org/discourse/yabb2/YaBB.pl?board=Integrate%3Baction=display%3Bnum=1163101573 - cached - mail it - history
SELECT CONCAT( "[", GROUP_CONCAT( CONCAT("{name:'",`name`,"'"), CONCAT(",email:'",`email`,"'}") ) ,"]") AS json FROM users; CREATE TABLE `user`( `id` int not null auto_increment, `name` varchar(100), `email` varchar(50), PRIMARY KEY(id) ) ENGINE = InnoDB; INSERT INTO `user` (`name`, `email`) VALUES ('Cesar', 'cesar@craftyman.net'), ('Maria', 'maria@gmail.com'), ('Jose', 'j0s3@hotmail.com'), ('Albert','albertpr@yahoo.com');
by mshook 2009-08-10 08:54 via · json · popular · mysql · sql · howto · code · example
http://craftyman.net/mysql-to-json/ - cached - mail it - history
Left to right: John Maloney (MIT/Scratch), Golan Levin (CMU), Tom McMail (Microsoft Research), Ira Greenberg (Miami U. Ohio), Hans-Christoph Steiner (NYU/ Pure Data), Evelyn Eastmond (MIT/Scratch), Casey Reas (UCLA/Processing), Zachary Lieberman (Parsons/openFrameworks), Theodore Watson (openFrameworks), Ben Fry (Seed Visualization Lab/Processing), Arturo Castro (openFrameworks), Sebastian Oschatz (Meso/VVVV), Daniel Shiffman (NYU), Luke DuBois (NYU/Cycling74), Dr. Woohoo (ExtendScript), Why the Lucky Stiff (Hackety Hack). Not pictured but also presenting: Don Slater (CMU/Alice), Wanda Dann (CMU/Alice).
by mshook 2009-08-07 16:55 adobe · art · code · conference · march · 2009 · mit · cpp · photo · javascript
http://www.flickr.com/photos/golanlevin/3344190502/ - cached - mail it - history
1. $(document).ready () All The Way
2. Use $(window).load ()
3. Load Only What You Really Need
4. Learn What The ‘data’ Method Is And Use It
5. Built-In Custom Selectors
6. Flag With Classes
7. Don’t Call the Same Selector Hundreds of Times
8. Chain (Almost) Everything
9. toggleClass Utility
10. Store jQuery Results

var $p = $('p.hello');
$p.css ('color', '#000000');
$p.text ('hello');
$p.addClass ('paragraph');
$p.fadeTo (1000, 1);

$('p.hello').css ('color', '#000000').text ('hello').addClass ('paragraph').fadeTo (1000, 1);
                  
by mshook 2009-08-05 18:46 jquery · javascript · useful · tips · tip · example · code · short
http://www.myinkblog.com/2009/08/04/10-tips-for-writing-better-jquery-code/ - cached - mail it - history
1 - 10 of 57 next »  
Related Tags
 
- exclude ~ optional + require
Add Dates