


I also had great fun at the Native Place, home to Nirvana Adventures. Hoping to go back in May and make progress towards Club Pilot.
bool MemberFilter::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
if( sourceParent.isValid() && sourceModel()->data(sourceParent).toString().contains(filterRegExp()) ) return true;
QString data = sourceModel()->data(sourceModel()->index(sourceRow, 0, sourceParent)).toString();
bool ret = data.contains(filterRegExp());
QModelIndex subIndex = sourceModel()->index(sourceRow, 0, sourceParent);
if( subIndex.isValid() )
{
for(int i = 0; i < sourceModel()->rowCount(subIndex); ++i)
{
ret = ret || filterAcceptsRow(i, subIndex);
}
}
return ret;
}
#!/bin/bash
MOUNTS="/windows/C /shared"
function 66ntfsmount() {
for i in $MOUNTS
do
mount $i
done
}
function 66ntfsumount() {
for i in $MOUNTS
do
umount $i
done
}
case $1 in
hibernate)
66ntfsumount
;;
suspend)
66ntfsumount
;;
thaw)
66ntfsmount
;;
resume)
66ntfsmount
;;
*)
echo "BAD!"
;;
esac
UUID=... /windows/D fuse.ntfs defaults 0 0
UUID=... /windows/C fuse.ntfs defaults 0 0
UUID=... /shared fuse.ntfs defaults 0 0
. /etc/rc.conf
. /etc/rc.d/functions
# Unmount NTFS partitions
stat_busy "Unmounting NTFS partitions"
umount /shared
umount /windows/C
umount /windows/D
stat_done
import pygame
from pygame.locals import *
import graffiti as g # 1
pygame.init()
g.init() # 2
pygame.display.set_caption('Graffiti Render Test')
screen = pygame.display.set_mode((800, 600))
screen.fill((0, 0, 0))
page = g.page.Page('<body><p>Testing Graffiti</p></body>') # 3
page.render.on(screen) # 4
while True:
for event in pygame.event.get():
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
pygame.quit()
sys.exit(0)
pygame.display.update()
import UserDict # allow NodeAttrs to behave like a dictionary, not significant for this example
class NodeName(object):
def __init__(self, name, parent=None):
self.name = name
self.parent = parent
def __str__(self):
return (parent and str(parent) or '') + self.name
def __hash__(self):
# the hash of our string is our unique hash
return hash(str(self))
def __cmp__(self, other):
# similarly the strings are good for comparisons
return cmp(str(self), str(other))
class NodeAttrs(UserDict.UserDict):
def __init__(self, attrs={}):
self.update(attrs)
>>> d = {}
>>> d[node_name] = attrs # node_name is an instance of NodeName and attrs
... # do anything which can be done to a dictionary and its keys
import sys
import pygame
from pygame.locals import *
class Point(object):
def __init__(self, x, y):
self.x, self.y = x, y
def distance_sq(self, other):
return (self.x-other.x)**2 + (self.y-other.y)**2
def distance(self, other):
return sqrt(self.distance_sq(other))
def tupl(self):
return (self.x, self.y)
def midpt(p1, p2):
return Point( (p1.x+p2.x)/2, (p1.y+p2.y)/2 )
def too_small(p1, p2, p3):
return max([ p1.distance_sq(p2), p2.distance_sq(p3), p3.distance_sq(p1) ]) < 5
def draw_line(p1, p2, surf, col):
pygame.draw.line(surf, col, p1.tupl(), p2.tupl())
def draw_triangle(a, b, c, screen, col):
if too_small(a, b, c):
return
else:
a_b = midpt(a, b)
a_c = midpt(a, c)
b_c = midpt(b, c)
draw_line(a, b, screen, col)
draw_line(b, c, screen, col)
draw_line(a, c, screen, col)
draw_triangle(a, a_b, a_c, screen, col)
draw_triangle(b, a_b, b_c, screen, col)
draw_triangle(c, b_c, a_c, screen, col)
pygame.init()
pygame.display.set_caption('Sierpinski')
screen = pygame.display.set_mode((640,480))
screen.fill((0, 0, 0))
draw_triangle(Point(10, 10), Point(630, 10), Point(310, 450), screen, (255, 0, 0))
draw_triangle(Point(50, 10), Point(630, 240), Point(310, 0), screen, (0, 255, 0))
while True:
for event in pygame.event.get():
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
pygame.quit()
sys.exit()
pygame.display.update()
pygame.quit()
Well, I'm here, or I've been here for 5 days now. Since we haven't got ID cards yet, there is no computer access, so I'm writing this from a cyber cafe. The last few days have been a bit boring. With no studies, playing and reading seem to be the only things you can do in 24 HOURS!.
I haven't written any code in days, but I have managed to read Hutton's Haskell book, which is really good. This place's library is awesome for all the computer science/programming related books they have, now I just hope I'll have linux access in the labs. For atleast four more months personal computers are not allowed in the rooms. So it might be next year (read Jan 2009) before I actually have my own computer again. Till then I'll just hang on to the external harddisk.
git rm graffiti -rf
N, S, W, E = 1, 2, 4, 8
def code(dirs):
return '%x'%dirs
I doubled 2's in my head because it made me feel calmer. I got to 33554432, which is 225, which was not very much because I've got to 243 before, but my brain wasn't working very well.
-- Christopher Boone
import sys
import pygame
from pygame.locals import *
import graffiti as g # Line 1
pygame.init()
g.init() # Line 2s = g.spraybuilder.parse_string(
"""
<body>
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean id diam. Curabitur lectus. Nullam ultricies ultrices tellus. Praesent id turpis vitae lorem varius posuere. Donec id diam. Nam risus sem, aliquet ac, dignissim eget, aliquam ac, dolor. Aenean lacus metus, eleifend eu, elementum ut, lacinia non, nisi. Morbi odio. Aenean id massa. Ut arcu urna, elementum et, iaculis ac, lacinia eget, dolor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Maecenas eleifend facilisis dolor. Quisque eget nulla. Sed ut eros. Maecenas ut diam. Nullam tellus urna, sodales ac, cursus nec, tempus ac, purus.
Aenean malesuada est quis velit. Nulla vitae nunc. Integer gravida. Curabitur purus velit, egestas quis, aliquet quis, mattis ac, orci. Aliquam ac lectus. Mauris congue orci faucibus est. In orci odio, sodales at, pretium nec, dignissim et, neque. Suspendisse potenti. Fusce eget ante. Etiam purus ligula, placerat tempor, pellentesque quis, tincidunt accumsan, turpis.
</p>) # Line 3
</body>
"""
surf = g.spray.SprayRenderer(s.sprays[0]).render() # Line 4
pygame.display.set_mode((800, 600))
pygame.display.set_caption('Spray Rendering')
screen = pygame.display.get_surface()
pygame.mouse.set_visible(1)
while True:
for event in pygame.event.get():
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
pygame.quit()
sys.exit()
screen.blit(surf, (50, 50, 800, 600)) # Line 5
pygame.display.flip()
Two new things at a time == frustration
Frustration kills learning
URL Memory(n) - the arcane talent of unconsciously remembering all human readable URLS.
Usually predominant among power users only.
startshape sun
rule sun {
sq { }
36* { r 10 } sq { }
}
rule sq {
SQUARE { hue 46 saturation 250 }
sq { x 1 y 1 s 0.8 brightness 0.4 }
}
startshape foo
rule foo {
hornleft { y 1 b 0.2 }
hornright { y 1 r -90 b 0.2 }
TRIANGLE { size 0.8 y 1.5 b -10 }
}
rule hornleft {
CIRCLE { size 0.7 }
hornleft { x -0.3 y 0.3 r 30 size 0.8 b 0.1 }
}
rule hornright {
CIRCLE { size 0.7 }
hornright { x -0.3 y 0.3 r -30 size 0.8 b 0.1 }
}
print
, Java has System.out.println
. I don't care about preserving your heirarchy! I want to print quickly. Where other languages have open("file")
Java has
try {
f = new FileReader("./words.txt");
} catch (FileNotFoundException e) {}
BufferedReader in = new BufferedReader(f);
Technology is clever people getting cleverer, so that dumb people can get dumberer.
Technology is clever people doing clever stuff, so that dumb people can do even dumber stuff.
When a boy calls a girl, he pays double, listening to the girl talk and talk, and the phone company charge and charge
But it won't be enough. Because this is not, fundamentally, a technological problem. Nor is it, fundamentally, a political problem. This is a problem of appetites, and of narcissism, and of self-deceit. The planet is breaking, and it is breaking under the weight of our hunger for more. To reform the world, we must first reform ourselves." -- Affluenza.orgThis really resonated with me. It's so true and yet so few people know it. BTW I searched for this after reading Oliver James's articles in The Economic Times.
! A guessing game
USING: calendar random strings namespaces prettyprint math.parser io io.files math kernel combinators ;
IN: guess
! lets choose our number
SYMBOL: answer
! initialize the generator
now timestamp>unix-time init-random
! get a number [1..100] and put it in answer
100 random answer set
answer get .
! keep asking the user
: start-guessing ( -- )
"Enter number: " print
! get the number as a string
stdio get stream-readln
! convert to integer
string>number
! push on answer
answer get
! now stack top is : input, answer
{
{ [ 2dup < ] [ "try higher" print start-guessing ] }
{ [ 2dup > ] [ "try lower" print start-guessing ] }
{ [ 2dup = ] [ "Thats right!" print ] }
} cond
;
"<path>/<filename>" run-file
Much has already been written about how much High School computer science teaching sucks ( High school computer science education ). As a student who has just left high school I just wanted to present my 2 cents on how bad the seperation between RealWorld programming and ClassRoom programming is. A common rebuttal is that there isn't enough time. I agree there isn't, but half-baked knowledge is dangerous. If you teach something, teach it qualitatively, not quantitatively.
A programmer is only as good as his tools, and how well he can use them. But schools generally lock down students to a specific ( often crappy ) tool. For example, we've Turbo C++ 3.0 ( 1992 ) on all computers. That is a 16 year old environment, supporting 16 year old standards. That's bad! In the days of Linux and Wikipedia do you really want kids raised on old proprietary standards. The ICSE board is very good atleast in their terms. They say that any Operating System ( why are we still on Windows ) with a latest C++ compiler should be used. It seems our school isn't listening.
If you are on Java, you probably have BlueJ. Now I've nothing against the BlueJ folks, but hiding all the compilation details from the student is denying knowledge. Students ( especially the ones who got into CS just for fun ) are of course happy that they don't muck around with "hard" stuff. But thats not how things work in the RealWorld. You should know how to use the command line, invoke javac and java. And, fricking, you should know that Java files have a .java extension and .class is the compiled byte code.
Another issue is shortcuts, quick search and replace, commenting. Kids don't know any of these things. It's type, click, type. Click Save. Click Compile. And to change something there is always manual replace.
Typical high school level programs, if well written, are never longer than 2 pages. They are often crappy, in the fact that the logic is repetitive, their is no purpose to the program and that students still don't get it!
So when it's project time, what the instructor gets is a dump of humongous shit, often with all the code in main, bad indentation and no comments. That's because the instructor hasn't taught the kids anything about decoupling programs, and seperating classes in files, and using header files. Often the instructor himself has no idea about build systems.
One really bad thing I see among my fellow students, is the complete inability to realise that each statement is an individual component. It evaluates to something, and other statements can use that value to do their job. This causes repetitive coding. To illustrate see this code sample.
function isSpam(email) {
if(email.contains('$$$'))
return true;
else
return false;
}
Students aren't taught that email.contains is returning true or false, and all we care about is true and false. They are never taught to see function documentation, just use it the way the instructor tells them too. This code can be simplified to the following, because email.contains is already doing what we want it to do, why decorate it?
function isSpam(email) {
return email.contains('$$$');
}
Bad indenting. Student code is full of bad indenting. Instructor code is full of bad indenting.
Learn to appreciate code people. It's just as much art as painting or poetry. Encourage right indentation, make liberal use of whitespace, clean up your logic, don't nest too much. You should be able to go back to it after a few months and not have to spend time just cleaning it up.
Follow standard conventions for variable names, make sure your method names and parameter names make sense. Use camelCase or _underscores_. Make booleans start with 'is' or simply the condition you're representing. If any variable has more purpose than a loop counter or a position marker, it should have a meaningful name.
Name your files meaningfully, keep it lowercase, and keep all your fake 31337 ness to yourself.
It's a matter of thinking for 3 hours, writing 3 minutes worth of elegant code, versus thinking for 3 minutes, spending 3 hours typing up code.
-- Compsci.ca
The post above also mentions some of the crap I've mentioned here, like the 4600 line Sudoku.
Student code is littered with conditionals highly specific. The very reason you're using a high level language is to avoid this. I've seen quiz programs where each question and its answer is in an if clause, embedded in the program! Cardinal sin. Use a file and parse the file, if you can't do that, atleast put all the questions and answers in two arrays ( don't tell me about maps ). Then you can just use a loop to pick out the question and its right answer.
Make your code extensible. Just because this is some dumb program which you're writing in school, doesn't mean it should be a waste of muscle energy, disk space and time.
If you have to choose day's of the week, put them in an array. You want to find out the number of days in a month, use a 12 element array. Or better yet, use your brain a bit more and write this:
int daysInMonth(int month) {
if(month==2)
return 28;
else if((month%2 == 1 && month <= 7) || (month%2 == 0 && month >= 8))
return 31;
else return 30;
}
It might seem like more code, but you can write this code once and use it anywhere. And you are using your brain.
Far too many schools have jumped on the Java bandwagon. If you are teaching kids who don't have much programming experience start with a higher level, small language. Use Python. You should be able to finish explaining most of the language within a week. Besides the interactive interpreter is great for messing around to know exactly how something works, how to make it go wrong and where it can fail. You will also spare them from the compile cycle ( I know, it kind of contradicts my first problem :p ), allowing them instant gratification. Spare them the brackets and let them develop the logic. Logic is far more important than syntax. Syntax changes, but logic is immortal.
Once in a while just stop the programming, and discuss technology related issues, latest news, ethical considerations. Anything which expands their minds and gets them more interested in computers. There are more than enough anecdotes and quotes about programming, use them. Instructors should stay on top of news stories. You don't have to know what monads are, but at least know what Linux is. One of my instructors had never heard of Opera and Mozilla ?!? Whatever language you are teaching, make sure you know it well. The same instructor above didn't know that the Java GUI framework is called Swing. Make sure you are aware of atleast major upgrades and integrate them.
The Open Source ecosystem is set to flourish. Make sure your students are aware of what it is. Encourage them to try out FLOSS. If you can't convert to Linux, atleast use open source compilers, tools and languages on your Windows machines. Set aside a computer where you can mess with distros.
Encourage frequent group projects. Let the kids make plans. Tell them how to go about design. Make sure its extensible and adaptable. If the project will need something more than what is taught, tell them to read about it, while you do too.
I don't know about the rest of the world, but in India, Computer Science textbooks for high school are crap. They are full of errors, bad practices, incorrect language, and often old software. There are hundreds of better quality books available online, often royalty free. There is Wikipedia and Wikibooks. While using them, remember to tell your students how cool the Internet is, and teach them about sharing.
There is this huge emphasis on theory at the high school level, mostly due to lack of time for practical assessment. Which means students have to often write programs and submit them without testing. In such situations, don't cut marks for syntax errors, unless they mess up the logic ( missing braces ). The compiler/interpreter is going to catch them anyway. As long as the program works correctly logically, missing semicolons are OK.
Rank readability above extensibility, extensibility above just-getting-it-done. If a student has used some cool logic, or exploited the specifications, give him some appreciation. After all programming is all about getting the best out of constraints, and pushing the limits. If he/she has looked to optimize, that's good too.
Far too many instructors help students fix their errors. Don't help them fix the errors, help them understand what the error is. Any decent language is quite verbose at error reporting, and in case of languages which support exceptions, the class name is often a very good indicator. Any decent compiler also reports line numbers. Let them fix the problem for themselves. Time well used now, is time saved later. Tell them it's called debugging.
Kate Masukomi sums it up nicely. Most programmers today are doing it to pay the bills. Don't let your students be one of them. If someone just doesn't seem to have any aptitude, maybe he should look into some other field. Encourage the good ones to expand out of the syllabus, mess with different languages and read sites like Proggit. Tell them to blog and learn HTML/CSS and create their own site. Don't create hundreds of typists, the world would prefer fifty real programmers ( thanks to lankythoughts for the link! ).
If something isn't done quickly, the IT world will be in a mess. Already the lack of real talent is leading to a shortage of employees. According to me, the only real coders are the people who are up breast with new developments and technologies. They don't have to know how everything works, but they should know that it exists. That's passion. They are the ones who read blogs, write them, comment on articles, are always hacking on side projects and have commits on some open source project. Make your students a part of that group.
P.S. Forgive my immodesty in certain areas :)