Page 1 of 250

Coding: Fleeting Thoughts

Posted: Wed Nov 07, 2007 6:30 pm UTC
by LDJosh
OK. Looks like this board needs a fleeting thoughts thread. - Hammer

While testing some session data handlers, I passed an unset variable to php with the date/time format set. instead of an error, php gives me the 'beginning' of time. so according to php, time began on:

1969 12 31 19:00:00

december 31st, 1969 at 7pm sharp huh?

well let’s see when it will end. Launch outlook, go to tasks. enter a task (like live forever). in the due date, put “forever”.

Seems like time will end on:

Tue 8/31/4500

neat stuff, huh?
This is what I did at work today.

Re: Coding: Fleeting Thoughts

Posted: Wed Nov 07, 2007 10:08 pm UTC
by photosinensis
While adding two randomly generated integer matrices of size 16834 * 16834:

"Damn, this is taking a long time."

I looked, and sure enough, I was doing a crapload of disk swapping. Too bad I've only got 2 GB of memory on that machine. The code didn't finish running before I had to pack up the laptop and run, though.

Re: Coding: Fleeting Thoughts

Posted: Wed Nov 07, 2007 10:12 pm UTC
by Workaphobia
The Unix Epoch is the starting point for many integral time representations, and it is defined to be midnight, January 1st, 1970. Your time was exactly 5 hours earlier, so I take it you're on the East Coast.

Fun fact #1: This time representation doesn't map one-to-one to real seconds, because every now and then it has to adjust with a leapsecond or some similar approximation. It's close enough for almost all purposes.

Fun fact #2: Systems that use a 32-bit signed integer to represent the time can only count forward 2,147,483,647 seconds (68 years), after which they will overflow at the "end of time". This is sometimes known as the Y2.038K problem.

As a Computer Science major, I am logically (not!) required to take Intro to Biology. Some of the people in that class had no concept of magnitude and got the Earth's age confused with numbers like how long ago the dinosaurs became extinct. To illustrate the point that the difference in magnitude between one million and one billion actually mattered, the teacher asked us how long 2 billion seconds is. This is probably the only time my interests helped me in that class.

Sidenote: is a "fleeting thoughts" thread not supposed to have responses to a particular topic, or do multiple discussions just get multiplexed in here?

Re: Coding: Fleeting Thoughts

Posted: Wed Nov 07, 2007 10:30 pm UTC
by Kizyr
Workaphobia wrote:The Unix Epoch is the starting point for many integral time representations, and it is defined to be midnight, January 1st, 1970. Your time was exactly 5 hours earlier, so I take it you're on the East Coast.

When I saw the first post, the only thing that stood out as unusual was the fact that it was at 19:00 and not midnight on January 1st, 1970.

My fleeting thought from coding... I'm starting to think that opposition to COBOL began primarily because THE CODE IS SCREAMING ALL THE TIME. KF

Re: Coding: Fleeting Thoughts

Posted: Thu Nov 08, 2007 12:05 am UTC
by Hammer
Workaphobia wrote:Sidenote: is a "fleeting thoughts" thread not supposed to have responses to a particular topic, or do multiple discussions just get multiplexed in here?

It's for posts that don't really need a dedicated thread of their own. Responses are fine. If something actually coalesces into a topic, I'll split it.

Re: Coding: Fleeting Thoughts

Posted: Fri Nov 09, 2007 10:44 am UTC
by evilbeanfiend
iirc the second before the unix epoch starts is used as an error value

Re: Coding: Fleeting Thoughts

Posted: Sat Nov 10, 2007 3:44 am UTC
by Sc4Freak
evilbeanfiend wrote:iirc the second before the unix epoch starts is used as an error value

Which would be a value of -1, I believe. Makes sense.

Re: Coding: Fleeting Thoughts

Posted: Sat Nov 10, 2007 5:51 am UTC
by fryman
Using CLargeNumber, I wrote a program to calculate the fibonacci sequence up to whatever, giving options for output to file/console, output all values, etc. The 1,000,000th Fibonacci number is 208988 digits in length. I forgot to check how much CPU time it took, but it took quite a while (after 300,000 iterations I was running at about 80/sec). I'm still fiddling with gcc switches to see if I can speed it up a bit.

Re: Coding: Fleeting Thoughts

Posted: Sat Nov 10, 2007 7:05 am UTC
by mrkite
fryman wrote:Using CLargeNumber, I wrote a program to calculate the fibonacci sequence up to whatever


I don't know anything about CLargeNumber, but the "standard" bignum library for C is GMP, which also proclaims to be the fastest.

So you might be able to speed up your code by using it instead...

Re: Coding: Fleeting Thoughts

Posted: Sat Nov 10, 2007 4:11 pm UTC
by M.qrius

Code: Select all

boolean ever = true;
for(;ever;) {
    [Do stuff]
}


Nice way to write down an eternal loop :P

Re: Coding: Fleeting Thoughts

Posted: Sat Nov 10, 2007 5:47 pm UTC
by unmoored
M.qrius wrote:

Code: Select all

boolean ever = true;
for(;ever;) {
    [Do stuff]
}


Nice way to write down an eternal loop :P


Code: Select all

#define ever ;;

for(ever)
{
}

Re: Coding: Fleeting Thoughts

Posted: Sat Nov 10, 2007 6:20 pm UTC
by M.qrius
unmoored wrote:

Code: Select all

#define ever ;;

for(ever)
{
}

Nice :D
There's some "until hell freezes over" around here somewhere as well... but the only language I know with until is TI-Basic.

Re: Coding: Fleeting Thoughts

Posted: Sat Nov 10, 2007 8:17 pm UTC
by Sastira
My favorite way to teach C newbies about why they should free() their malloc()s:

Code: Select all

while(malloc(1024));

Re: Coding: Fleeting Thoughts

Posted: Sat Nov 10, 2007 11:02 pm UTC
by EvanED
Sastira wrote:My favorite way to teach C newbies about why they should free() their malloc()s:

Code: Select all

while(malloc(1024));

Raymond Chen collected a bunch of entries from his blog The Old New Thing, expanded some of them, and put them in a book. The book has a couple bonus chapters that are available online, one of which is this big long thing that is half a rant against programs that were written poorly -- pretty much that assumed that they were not running in protected mode or in a multitasking environment -- and half a description of things programmers should do to make their programs compatible with Windows 95 without making MS hack around their bugs for them. (One of Chen's main roles for Win95 was application compatibility -- figuring out what are essentially hacks MS could put into Windows to allow buggy programs to continue to operate. Apparently there's a fairly famous one with SimCity 2000 where they had to do something to compensate for it accessing memory that had been freed.)

There is an entire section, beginning on page 17, called "allocate available memory". It includes such examples (in approximate order of increasing ridiculousness) from real-world applications and games as

Code: Select all

while ((dwMem = DPMI_QueryFree()) != 0) {
    AddToHeap(DPMI_Allocate(dwMem), dwMem);
}

and

Code: Select all

for (dwMem = 0x1000000; dwMem; dwMem -= 0x1000) {
    while ((hmem = DPMI_Allocate(dwMem)) != 0) {
        AddToHeap(hmem, dwMem);
    }
}

and

Code: Select all

again:
for (dwMem = dwLinFree; dwMem > 0; dwMem -= 0x8000) {
    if ((hmem = DPMI_Allocate(dwMem)) != 0) {
        AddToHeap(hmem, dwMem);
        goto again;
    }
}


The whole chapter is well-worth reading, because it's absolutely hilarious.

Re: Coding: Fleeting Thoughts

Posted: Sun Nov 11, 2007 8:51 pm UTC
by Sastira
That just made my headache worse. Ouch. ;)

I'll have to give that a looksee! Thanks EvanED!

Re: Coding: Fleeting Thoughts

Posted: Mon Nov 12, 2007 6:24 pm UTC
by fryman
mrkite wrote:I don't know anything about CLargeNumber, but the "standard" bignum library for C is GMP, which also proclaims to be the fastest.

So you might be able to speed up your code by using it instead...


I wrote this in C++, but GMP claims compatibility... I suppose I could branch off and re-write it using GMP. And a GUI with a timer would be a nice addition as well. I also noticed the hard division between Intel and AMD, being stronger at maths and graphics respectively.

Could you explain programming please?

Posted: Thu Dec 20, 2007 8:06 pm UTC
by LDJosh
From thedailyWTF forums:

Being a programmer and the only computer literate person in my family, I get tech support calls from my family all the time. I got a phonecall from a brother-in-law today:

Him: Hey, you're good with computers right?

Me: Yes.

Him: And you know how to program computers?

Me: Yes, thats my job actually.

Him: Could you explain programming please?

Me: I'm sorry, what do you mean?

Him: I want to make a game like Halo, but I don't know how to start. Could you explain what I need to do?

Me: You should probably go to the library and get a book.

Him: Can you just tell me what I need to do?

Me: Wait a minute. Are you asking me to explain how to program computers?

Him: Yeah.

Me: Over the phone?

Him: Yeah.



My brother in law apparently made several unsuccessful attempt to "learn programming" by opening up exes in Notepad. He created a text file with the words "Morph the screen into something cool" and couldn't figure out how to run it, even had the balls to ask me "how do I install my program? Do I just put a shortcut on the desttop".

My dad, a programmer, lent him an unfortunately titled book called "Teach Yourself Java in 24 hours". He immediately flipped to the back of the book and reading sections on server and Swing development, and was very excited to see that he could write his own server after just one day.

In the end, I was unable to teach my brother in law how to make his own Halo over the phone, and he decided that I wasn't a very good programmer.

Re: Could you explain programming please?

Posted: Thu Dec 20, 2007 8:40 pm UTC
by segmentation fault
its simply telling the computer what to do in a language the computer can understand. it is also a very deep rabbit hole. if youre interested in programming simply because you want to make a game like halo, youre better off not caring how halo was made and just sitting back and enjoying the game.

Re: Coding: Fleeting Thoughts

Posted: Mon Dec 31, 2007 9:47 am UTC
by wing
I wonder how sad and alone this poor little thread I just wrote must feel, since she's wait()ing and all of her little thread friends died before ever notify()ing her.

Re: Coding: Fleeting Thoughts

Posted: Mon Dec 31, 2007 12:39 pm UTC
by LoopQuantumGravity
EvanED wrote:a rant against programs that were written poorly


Another program from Publisher 31 allocates all the memory it can, and each time you start
a new mission, it zeroes out everything.

Program 24b first allocates all the memory in the system into a “spare pool.” When it needs
to allocate memory from the pool, it first attempts to grow the spare pool; if this succeeds,
the application crashes. (How could I possibly make this up?) Otherwise, it shrinks the spare
pool by the amount it wants to allocate, then allocates the desired value. If this second
allocation fails, the application crashes.

I... I... I just don't know what to say...

But the next time I hear someone complain about Windows, I will make them read (and understand) that entire chapter before they're allowed to talk to me again!

Re: Coding: Fleeting Thoughts

Posted: Tue Jan 01, 2008 12:33 am UTC
by niteice
EvanED wrote:a rant against programs that were written poorly


I'm pretty sure Example 43 is SimCity 2000 for DOS. I had an older machine with 64MB of RAM, so I tried to play...curiously, it only warned me, instead of actually stopping me from continuing. I think hope it was just an overflow.

Re: Coding: Fleeting Thoughts

Posted: Tue Jan 01, 2008 12:41 am UTC
by Berengal
FT: I like threads, but I feel maybe they should be used for other things than making a bunch of threads calculating primes, pi, factorials etc. while still allowing me to use the python interpreter in the meantime, which I only use to poll the other threads to see how far they've come anyway.

Oh, wait, I did use it for something useful once. I had to factorize a bajillion numbers, so I made a thread to do that for me while I wrote the rest of the program. Well, useful... the thread finished in less than a second, but THE IDEA WAS SOUND at least.

Re: Coding: Fleeting Thoughts

Posted: Thu Jan 03, 2008 4:26 pm UTC
by der_bAUer
During the past week or so, I had my seventh or so go at programming some sort of personal information manager modeled after David Allen's book "Getting Things Done". The six designs before died of spaghetti code and other sources of non-maintainability, so this time I decided to make everything really modular. And I would make it a service oriented architecture, even though I don't know anything about how to design or implement one. Oh, and learning XMLRPC (or how to use python's xmlrpc module) is too complicated and requires me to register my functions with the RPC server, so I rolled my own "dead simple minimalistic remote procedure calls" (dsmrpc). Oh, and someday I might write a service in another programming language (always wanted to have an excuse to learn Scheme, Haskell, C, C++), so I can't just send pickled objects over the network, so I programmed my own serialization functions, too.

Surprisingly, this has not become spaghetti code, and the first app build on top of this framework, a simple wiki, actually works. But it is slooow! Maybe doing 37 dsmrpc's for each page is a little too much, considering that a new connection is created for each request ;)

Guess I have to optimize the dsmrpc part so that it does not send data over the network when the function to be called lives in the same python process...

Whatever, so far it's been really fun, a good learning experience, and this promises to be extendable enough so that I won't start over from scratch again.

Re: Coding: Fleeting Thoughts

Posted: Fri Jan 04, 2008 5:32 am UTC
by Berengal
I made pong!
But it needs a) Startup interface allowing you to select number of players and keymapping, b) AI, for those lonely nights and c) hot client on server multiplayer action

Re: Coding: Fleeting Thoughts

Posted: Fri Jan 04, 2008 10:53 am UTC
by Notch
Berengal wrote:c) hot client on server multiplayer action


Good luck! High latency pong is a very interesting problem.

Re: Coding: Fleeting Thoughts

Posted: Fri Jan 04, 2008 11:29 am UTC
by crazyjimbo
Notch wrote:Good luck! High latency pong is a very interesting problem.


Are you talking about pong ping?

Re: Coding: Fleeting Thoughts

Posted: Fri Jan 04, 2008 1:50 pm UTC
by Notch
crazyjimbo wrote:pong ping?


.. !

Well played! =D

Re: Coding: Fleeting Thoughts

Posted: Sun Jan 06, 2008 4:59 pm UTC
by arcoain
nah man I'm talking about
pong pong pong pong Server Time Out Warning ping ping ping 0x45035 Exception

Declarative Programming

Posted: Sat Mar 08, 2008 11:58 am UTC
by rodarmor
"What's declarative programming?" she asked sweetly.

"Well," he began, moving closer to her, "declarative programming is when you tell the computer what you want, and then the computer figures out how to get it. Pretty sweet, huh?"

"What kinds of things can you tell the computer you want?" she asked, her cheeks beginning to flush.

He thought for a moment, and began stroking her hair gently. "All kinds of things. There's a language called prolog you can use to ask about logical expressions. In SQL you can ask about relationships between data. With a program like bison you can use declarative programming to describe a language, letting bison generate something that recognizes it."

"Oh," she said breathlessly, leaning her head on his shoulder, "so I don't have to worry about choosing an algorithm--the computer will pick one for me?"

He silently began caressing her breasts.

She took this as an affirmation. "That's so cool that it just does it--it must be really smart to pick the right algorithm!" she enthused.

"Well..." he trailed off, still gently fondling her breasts.

"What?" She asked, suddenly nervous.

"Um..." he said, "it's not quite like that." His hand stopped moving.

She sensed he was backpedaling. "Well?" She demanded.

He laughed awkwardly. "Heh... You see, most declarative programming systems only know about one algori--"

"It must be a great algorithm!" She interrupted, with renewed intellectual arousal. "What is it?"

He hesitated for as long as he could... "Brute force search," he said, guiltily.

"What the fuck!?!?" She yelled, straightening and yanking his hand from her breast.

"Wait, baby, it's not so bad!" He begged.

"I'm listening." She said, looking him in the eye.

"Well, if you're careful and you program in an idiomatic way, you ca--"

A venomous glare silenced him mid-sentence. She stood suddenly, grabbing his hat from the night stand and moving towards an open window.

"My Stetson!" He shrieked, standing quickly. The spurs on his cowboy boots jangled feebly. "But baby, didn't that bison parser generator thing sound cool?" He pleaded.

She stopped. "Well... yeah, that was pretty neat..." she begrudgingly acknowledged, softening for a moment.

"And that doesn't use a brute force algorithm. It builds an automata for you, an LR parser," he said.

She smiled to herself, seeming to relent momentarily. He could see that she was touched by the idea of a program that could understand other programs.

"See, declarative programming isn't all bad..." he cajoled, slowly walking towards her, palms outstretched.

She started, as if waking from a dream. She looked at him. "But what about in the case of an ambiguous grammar, for which an LR parser won't suffice?"

"Don't worry," he said, smiling, "bison can use a technique called generalized LR parsing, which allows it to follow all possible parses simultaneously, eventually finding a successful parse."

She thought for a moment. "But if we're following all possible paths simultaneously and discarding the ones which don't lead to successful parses, isn't that just brute force search?!?" She asked, her voice suddenly ringing with betrayal.

Her words were damming. Nothing he could say would placate her. He stood in embarrassed silence, eyeing his cowboy hat nervously.

She turned away from him, her emotions halfway between pity and rage. He moved towards her, reaching for her hands, but it was too late. She had already hurled his hat from the window, as hard as she could. They watched silently as it flew through the night, lofted on the cool air as if by the breath of angels.

Re: Declarative Programming

Posted: Sat Mar 08, 2008 1:52 pm UTC
by Spoffin
Funneh!!!

:lol:

Re: Coding: Fleeting Thoughts

Posted: Sat Mar 08, 2008 6:59 pm UTC
by thoughtfully
Definitely need a Hall of Shame just for this shining example of not reading the fora rules. Wow.

I'm not sure which rule you feel this violates. It was originally a separate thread. I dropped it into this Fleeting Thoughts thread as it seemed pretty fleeting. There was the possibility that some people would find it funny. - Hammer

Sorry. I thought it was a "shining example" and a "post which didn't follow the rules". (not posting in the intro thread) I enjoyed it very much, and thought it more insightful/touching than humorous. If there was a place of posts that were outside the usual rules, this would be an interesting one to find there.

Just FYI: We are no longer requiring a post in the Intro thread. This version of phpBB has much improved spammer protections.

Sandwich

Posted: Thu Mar 20, 2008 1:07 am UTC
by ObsidianX

Re: Sandwich

Posted: Thu Mar 20, 2008 1:13 am UTC
by phildini
Heh. Multi-lingual webcomic hacks. yummy.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 20, 2008 2:29 am UTC
by Magilla
I was at work til 8:30* last night fighting with asp. My fleeting thought was "holy crap, vbscript sucks!"

Even when it's well written, it's difficult to read. I wonder if I can convince the boss that jscript is better...





* I'm supposed to finish at 5...

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 20, 2008 3:19 am UTC
by ObsidianX
Ack! I'm sorry I didn't read the rules! >.<

Re: Sandwich

Posted: Thu Mar 20, 2008 3:25 am UTC
by coppro
ObsidianX wrote:I got bored... decided to code http://xkcd.org/149/ in a few languages:
One nitpick - what if user account 0 isn't named root? (Note: I wonder if naming your root account something else would help guard against exploits?)

Re: Sandwich

Posted: Thu Mar 20, 2008 3:45 am UTC
by Karrion
coppro wrote:
ObsidianX wrote:I got bored... decided to code http://xkcd.org/149/ in a few languages:
One nitpick - what if user account 0 isn't named root? (Note: I wonder if naming your root account something else would help guard against exploits?)


Linux Administration Handbook wrote:Linux does not prevent you from changing the username on [the root] account, or from creating additional accounts whose UIDs are 0, but both are bad ideas. Such changes have a tendency to create inadvertant breaches of system security.

--Linux Administration Handbook By Evi Nemeth, Garth Snyder, Trent R. Hein, section 3.2

Re: Coding: Fleeting Thoughts

Posted: Mon Mar 24, 2008 8:00 am UTC
by wing
Sometimes I wish someone would write quick reference cards for different languages syntaxes. It's quite annoying to have a language that you know, but don't write often enough to do the syntax by reflex 100% of the time. For example, I am primarily a Java and C# programmer, and I could write those with my goddamn eyes closed. But it inevitably comes to pass that PHP or VB is the only way a given employer is going to let me do anything. I made PHP very, very angry a few dozen times today with simple syntax errors (why is it "if($variable)" but "include '$variable'"?!?!??!)

Re: Coding: Fleeting Thoughts

Posted: Mon Mar 24, 2008 12:53 pm UTC
by Xanthir
wing wrote:Sometimes I wish someone would write quick reference cards for different languages syntaxes. It's quite annoying to have a language that you know, but don't write often enough to do the syntax by reflex 100% of the time. For example, I am primarily a Java and C# programmer, and I could write those with my goddamn eyes closed. But it inevitably comes to pass that PHP or VB is the only way a given employer is going to let me do anything. I made PHP very, very angry a few dozen times today with simple syntax errors (why is it "if($variable)" but "include '$variable'"?!?!??!)

Um, it's not. You can uses parenthesis with an include() or require() as you wish - it's entirely optional. If you have the pathname in a variable, you don't need quotes either.

Re: Coding: Fleeting Thoughts

Posted: Mon Mar 24, 2008 2:53 pm UTC
by wing
Xanthir wrote:
wing wrote:Sometimes I wish someone would write quick reference cards for different languages syntaxes. It's quite annoying to have a language that you know, but don't write often enough to do the syntax by reflex 100% of the time. For example, I am primarily a Java and C# programmer, and I could write those with my goddamn eyes closed. But it inevitably comes to pass that PHP or VB is the only way a given employer is going to let me do anything. I made PHP very, very angry a few dozen times today with simple syntax errors (why is it "if($variable)" but "include '$variable'"?!?!??!)

Um, it's not. You can uses parenthesis with an include() or require() as you wish - it's entirely optional. If you have the pathname in a variable, you don't need quotes either.

Okay, leave it to me to get it backwards at 4AM.

Why is "include '$variable'" valid and "if '$variable'" invalid? Now if you go ahead and tell me I'm wrong there, than I have an axe to grind with a certain pain in the ass webhosting company. (Their database creation control panel forces you to set what it considers a strong password... Which phpmyadmin - the ONLY available database frontend - will not accept because it's useless developers don't understand escaping)