It's contest time again, and more particularly, it's contest time for the #devel channel on irc.malvager.net
Draft Rules for the #devel contest of irc.malvager.net:
Create a tool that will either allow or otherwise encourage people in #devel to collaborate in code writing and or sharing. The platform/language can be any (within reason; if you’re not sure, ask). It will be judged subjectively by both bsdpunk and psycho on both functionality and creativity. The first place prize will be a bsdpunk t-shirt and an Arduino (or Arduino clone). The second place prize is an Arduino (or clone). If god willing a third place prize, tbd (this one is not written in stone).
Contest will be over on the 20th of July.
Draft rules are subject to change for the next week, keep updated by looking at this blog(rules will only change by minor stipulations, the spirit of the contest will remain the same).
Sunday, June 12, 2011
#devel contest draft rules
Tuesday, February 24, 2009
Poor man's obstacle avoiding spike via python and lego nxt mindstorms
Ok so this script is a python script for the nxt brick, and in particular for the spike configuration. What it does is, looks for obstacles in kind of a cheap way. It checks the ultrasonic sensor and if it's less than 255 then it starts to only use one side to move...IE it turns. So it's kind of a pathetic script but I threw it together last night, mainly because I don't see any custom python code on the net for nxt python. There's some code for the tail commented out btw.
Ok so a caveat for mac users, you need to do this to get it to nxt_python to work:
http://www.cs.wlu.edu/~levy/software/nxt_lightblue_glue/
PC users should be fine assuming the appropriate modules are installed.
#!/usr/bin/env python
import time
import nxt.locator
from nxt.motor import *
from nxt.sensor import *
sock = nxt.locator.find_one_brick()
def moveit(brick):
#m_camera = Motor(brick, PORT_A)
#m_camera.power = 100 # 100% power
#m_camera.mode = MODE_MOTOR_ON
#m_camera.run_state = RUN_STATE_RUNNING
#m_camera.tacho_limit = 80
#m_camera.set_output_state()
m_camerc = Motor(brick, PORT_C)
m_camerc.power = 100 # 100% power
m_camerc.mode = MODE_MOTOR_ON
m_camerc.run_state = RUN_STATE_RUNNING
m_camerc.tacho_limit = 1000
m_camerc.set_output_state()
m_camerb = Motor(brick, PORT_B)
m_camerb.power = 100 # 100% power
m_camerb.mode = MODE_MOTOR_ON
m_camerb.run_state = RUN_STATE_RUNNING
m_camerb.tacho_limit = 1000
m_camerb.set_output_state()
def moveitback(brick):
m_camera = Motor(brick, PORT_A)
m_camera.power = -100 # 100% power
m_camera.mode = MODE_MOTOR_ON
m_camera.run_state = RUN_STATE_RUNNING
m_camera.tacho_limit = 80
m_camera.set_output_state()
def moveitleft(brick):
#m_camera = Motor(brick, PORT_A)
#m_camera.power = 100 # 100% power
#m_camera.mode = MODE_MOTOR_ON
#m_camera.run_state = RUN_STATE_RUNNING
#m_camera.tacho_limit = 80
#m_camera.set_output_state()
m_camerc = Motor(brick, PORT_C)
m_camerc.power = 100 # 100% power
m_camerc.mode = MODE_MOTOR_ON
m_camerc.run_state = RUN_STATE_RUNNING
m_camerc.tacho_limit = 1000
m_camerc.set_output_state()
def test_sensors(b):
print 'Touch:',
if TouchSensor(b, PORT_1).get_sample():
print 'yes'
else:
print 'no'
print 'Sound:', SoundSensor(b, PORT_2).get_sample()
print 'Ultrasonic:', UltrasonicSensor(b, PORT_3).get_sample()
sock = nxt.locator.find_one_brick(host='00:16:53:09:F4:4A', name='NXT')
if sock:
b = sock.connect()
terd = 1
while terd<= 30:
objectd = UltrasonicSensor(b, PORT_3).get_sample()
print objectd
if objectd == 255:
print '255'
moveit(b)
time.sleep(1)
else:
moveitleft(b)
time.sleep(1)
sock.close()
else:
print 'No NXT bricks found'
Wednesday, November 5, 2008
"the hacker operating system, 'Lunix'"(sic)
Some people are just so crazy or just wrong, it's entertaining. This guy is ranting about how opensource is the reason for, well I guess, malicious computing. And claims that open source doesn't produce anything worth having. Does he know he is hosted on an Apache server? Good stuff though, read it and have a laugh.
Saturday, May 31, 2008
AJAX tutorial for begginers
So ajax is a buzz word around the whole web 2.0 scene. It stands for Asynchronous JavaScript And XML. Basically it's just using some javascript to call a function called xmlHttpRequest(); .Anyway it's usually some pretty standard not changing code which you can get from the W3CSchools. I have made some slight modifications, that I find make the AJAX code work a little better.
What I did was write a simple stupid recursive function(smarm, I had been reading to much QC that week) that has a wait in it and a header thing, which I had to put in there due to some weird IE thing I still don't quite understand.
So this ajax code only does one little thing, it prints a diffrent page in a div every 5 seconds. Now the reason you would do this is if you had ever changing data in that html/php file, you put in the div. You also need onLoad="smarm()" in the body tag.
function ajaxFunction()
{
var xmlHttp;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById('stable').innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("POST","ajax2.php",true);
xmlHttp.send(null);
}
function smarm()
{
ajaxFunction();
var t=setTimeout("smarm()",5000);
http.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
}
So like ajax2.php might look something like this:
$handle = fopen('info.txt', 'a+');
$shiznit = fread($handle,600);
fclose($handle);
Or you could dump a mysql database table into an html table if that database was changing a lot.
Yeah and don't forget to add the div, in my example the div I used was "stable". So to do that you would just add div brackets with a class and id named stable. Also make sure you put the javascript in script brackets and the php in php brackets of course.
One caveat is that unless the page you are inserting into the div is somehow otherwise linked to your site, the content within it most likely well not be viewed by a search engine. So if you are building SEO intensive sites, be aware.
Friday, May 23, 2008
Yo, BSDPunk I want to know what IP's are looking at my site.
So this is broken down simple stupid line by line item by item, if you just want the code scroll to the bottom.
Well here is a little php fu for you guys.
Ok so the first line is:
$newb = "\n";
$newb is a variable we are declaring. By = "\n" we are telling it what the variable is. \n is special and declares a new line. Sp basically \n is a line break.
The quotes are necessary for \n to work because it is a string. The semicolon is used to end the line.
$ip = $_SERVER['REMOTE_ADDR'];
This is a server variable, of the person who is visiting the site.
$handle = fopen('info.txt', 'a+');
So fwrite says to call the variable with the fopen function and then writes the IP to the text file.
fwrite($handle, $newb);
Calls the same variable with to the text file and enters a line break or the $newb variable.
fclose($handle);
So fclose closes the file.
So here is the sum of the code:
$newb = "\n";
$ip = $_SERVER['REMOTE_ADDR'];
$handle = fopen('info.txt', 'a+');
fwrite($handle, $ip);
fwrite($handle, $newb);
fclose($handle);
And remember to go ahead and create info.txt. Also I was using WAMP so I didn't deal with any chmod stuff it's not working check your permissions, I have put this on a *nix server with 777 perms, but don't do that in a production environment, it's insecure.