Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
MononcQc
May 29, 2007

Munkeymon posted:

Sometiems you just have to try even harder to get your Annonces I guess v:downs:v
It's worse than that.

Turns out $photoList is a global variable that gets declared and transformed inside getAnnonces(). In fact, it is returned by the function, so all you'd think this does is assign the variable to itself for some reason.

Well, it would, if the original programmer would have thought of declaring it as global outside of the function's scope. $photoList exists as a global variable inside the function, but has a local scope outside of it. If this isn't some kind of meta-obfuscation I don't know what it is.

Adbot
ADBOT LOVES YOU

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
Can somebody explain to me why my old code:

code:
enum Foo { FOO_1, FOO_2 };

string GetInfo(Foo foo){
  switch(foo) {
    case FOO_1: return foo1;
    case FOO_2: return foo2;
  }
}
was changed to

code:
string GetInfo(Foo foo){
  stringstream stream;
  switch(foo) {
    case FOO_1:
      stream << this->foo1;
      break;

    case FOO_2:
      stream << this->foo2;
      break;

    default:
      return "";
  }
  return stream.str();
}
because I'm seriously :psypop:ing over here

jandrese
Apr 3, 2007

by Tiny Fistpump
How were foo1 and foo2 declared? Dynamically? Maybe someone's trying to avoid a race condition or memory leak?

Vanadium
Jan 8, 2005

jandrese posted:

How were foo1 and foo2 declared? Dynamically? Maybe someone's trying to avoid a race condition or memory leak?

How the hell do you declare something dynamically

spiritual bypass
Feb 19, 2008

Grimey Drawer

Vanadium posted:

How the hell do you declare something dynamically

Well you just hardcode it :iamafag:

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Vanadium posted:

How the hell do you declare something dynamically

code:
#include </dev/tty>

mr_jim
Oct 30, 2006

OUT OF THE DARK

code:
mr_jim@home:~/tmp/test$ cat tty.c
#include </dev/tty>
mr_jim@home:~/tmp/test$ gcc tty.c
#include <stdio.h>

int main(void)
{
        printf("holy poo poo\n");
        return 0;
}
mr_jim@home:~/tmp/test$ ./a.out
holy poo poo
mr_jim@home:~/tmp/test$
It's the only way to code.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

jandrese posted:

How were foo1 and foo2 declared? Dynamically? Maybe someone's trying to avoid a race condition or memory leak?

No, they're just plain old attributes. There was absolutely nothing wrong with the original code, it was apparently just not complicated enough

tripwire
Nov 19, 2004

        ghost flow

mr_jim posted:

code:
mr_jim@home:~/tmp/test$ cat tty.c
#include </dev/tty>
mr_jim@home:~/tmp/test$ gcc tty.c
#include <stdio.h>

int main(void)
{
        printf("holy poo poo\n");
        return 0;
}
mr_jim@home:~/tmp/test$ ./a.out
holy poo poo
mr_jim@home:~/tmp/test$
It's the only way to code.
whoa

tripwire
Nov 19, 2004

        ghost flow
How did i not know that? Are there any other neat tricks in a similar vein to that?

tripwire fucked around with this message at 05:00 on Jan 14, 2010

awesmoe
Nov 30, 2005

Pillbug

mr_jim posted:

code:
mr_jim@home:~/tmp/test$ cat tty.c
#include </dev/tty>
mr_jim@home:~/tmp/test$ gcc tty.c
#include <stdio.h>

int main(void)
{
        printf("holy poo poo\n");
        return 0;
}
mr_jim@home:~/tmp/test$ ./a.out
holy poo poo
mr_jim@home:~/tmp/test$
It's the only way to code.
This just blew a lot of minds at work. Thanks!

mr_jim
Oct 30, 2006

OUT OF THE DARK

tripwire posted:

How did i not know that? Are there any other neat tricks in a similar vein to that?

Cut out the middle man:
code:
echo "#include </dev/tty>" | gcc -x c - && ./a.out && rm ./a.out
I actually had no idea it would work until I tried it.

tripwire
Nov 19, 2004

        ghost flow

mr_jim posted:

Cut out the middle man:
code:
echo "#include </dev/tty>" | gcc -x c - && ./a.out && rm ./a.out
I actually had no idea it would work until I tried it.

Wow, thats insane! It's almost like having an interactive c REPL console for loving around with. I could see that coming in handy for just testing snippets of code without bothering to build and make a big project.

ColdPie
Jun 9, 2006

tripwire posted:

Wow, thats insane! It's almost like having an interactive c REPL console for loving around with. I could see that coming in handy for just testing snippets of code without bothering to build and make a big project.

Make a big project? Just edit test.c with a text editor (ever tried actually typing code into a terminal? ugh), compile, and run it.

mr_jim
Oct 30, 2006

OUT OF THE DARK

code:
#!/bin/sh

echo "This is not a REPL. Press ctrl-d to compile and run, ctrl-c to exit."
echo -n "> "
while true ; do
    echo "#include </dev/tty>" | gcc -x c - && ./a.out && rm ./a.out
    echo -n "> "
done
I'm done.

edit:

No, I'm not. If you add "-ldl" to the gcc command, you never need worry about using a dynamic library function:

code:
This is not a REPL. Press ctrl-d to compile and run, ctrl-c to exit.
> #include <stdio.h>
#include <math.h>
#include <dlfcn.h>

typedef double (*math_funcp)(double);

int main(void)
{
    void *libm = dlopen("/usr/lib/libm.so", RTLD_LAZY);
    void *initializer = dlsym(libm, "sin");
    math_funcp sin_func = *((math_funcp*)(&initializer));
    printf("sin(0.6) = %f\n", (*sin_func)(0.6));
    dlclose(libm);

    return 0;
}
sin(0.6) = 0.564642
>

mr_jim fucked around with this message at 06:33 on Jan 14, 2010

UberJumper
May 20, 2007
woop
code:
rows = gp.SearchCursor(A_Layer, The_SQL_Query_For_This_Layer)
row = rows.next()

# CHeck if Row is NULL, seems turning a row into a string, that is Null will print "None"
if str(row) != "None":
  <do something>
else:
  # Free the License!
  del gp
  sys.exit("Error Bad Feature layer")
:psyboom:

Now whats the biggest WTF here?

Zombywuf
Mar 29, 2008

Perhaps a small change is called for

code:
#!/bin/sh

echo "This is not a REPL. Press ctrl-d to compile and run, ctrl-c to exit."
echo -n "> "
while true ; do
    echo '#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main () {
#include </dev/tty>
}' | gcc -lm -x c - && ./a.out && rm ./a.out
    echo -n "> "
done

tef
May 30, 2004

-> some l-system crap ->

tripwire posted:

Wow, thats insane! It's almost like having an interactive c REPL console for loving around with. I could see that coming in handy for just testing snippets of code without bothering to build and make a big project.

http://neugierig.org/software/c-repl/


* 20 minutes of haranguing haskell, and I now get this*
code:
$ c-repl 
c-repl: a C read-eval-print loop.
enter '.h' at the prompt for help.
int x error: In file included from /usr/include/stdio.h:906,
                 from <stdin>:1:
/usr/include/bits/stdio2.h: In function 'int sprintf(char*, const char*, ...)':
/usr/include/bits/stdio2.h:35: error: '__builtin_va_arg_pack' was not declared in this scope
....
Also, there is an older version of c-repl using ruby hiding in debian.

tef fucked around with this message at 13:16 on Jan 14, 2010

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
http://root.cern.ch/drupal/content/cint

I have no idea how good or bad it is.

mr_jim
Oct 30, 2006

OUT OF THE DARK

Zombywuf posted:

Perhaps a small change is called for

code:
#!/bin/sh

echo "This is not a REPL. Press ctrl-d to compile and run, ctrl-c to exit."
echo -n "> "
while true ; do
    echo '#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main () {
#include </dev/tty>
}' | gcc -lm -x c - && ./a.out && rm ./a.out
    echo -n "> "
done


Well, if you need that much hand-holding:
code:
#!/bin/bash                                                                
# snarepl - Still Not A Read-Eval-Print Loop.                              
 
if [ -z "$1" ]
then          
    srcfile=`mktemp -u`
    trap "rm -f $srcfile; rm -f $outfile; echo; stty echo; exit" INT
    echo "Editing a temporary file, which will be deleted upon exiting."
    read -s -p "Press enter to continue, or ctrl-c to exit. "
    echo
else
    srcfile=$1
    trap "rm -f $outfile; echo; stty echo; exit" INT
fi
 
if [ ! -e $srcfile ] ; then
echo '#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
 
    return 0;
}
' > $srcfile
fi
 
outfile=`mktemp -u`
 
while (true) ; do
    echo editing $srcfile
    oldtime=`stat -c %Y $srcfile`
 
    vim -c "set filetype=c" $srcfile +6
 
    newtime=`stat -c %Y $srcfile`
    if [ $newtime -gt $oldtime ]
    then
        echo compiling $srcfile
        gcc -x c -o $outfile $srcfile
    else
        echo no changes
    fi
    if [ -x $outfile ]
    then
        echo running:
        echo ========
        $outfile
        echo ========
    fi
 
    read -s -p "Press enter to continue, or ctrl-c to exit. "
done
No "#include </dev/tty>" fuckery though.

mr_jim fucked around with this message at 18:15 on Jan 14, 2010

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!

quote:

CINT is written in C++ itself, with slightly less than 400,000 lines of code.
Holy poo poo that's a lot of code for an interpreter.

Vanadium
Jan 8, 2005

If you really want something that approaches a REPL for C++, why not go the whole distance and turn it into an IRC bot.

:colbert:

mr_jim
Oct 30, 2006

OUT OF THE DARK

Vanadium posted:

If you really want something that approaches a REPL for C++, why not go the whole distance and turn it into an IRC bot.

:colbert:

Well that would just be silly.

VV no, I got it.

mr_jim fucked around with this message at 19:42 on Jan 14, 2010

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

mr_jim posted:

Well that would just be silly.

*whoosh*

chocojosh
Jun 9, 2007

D00D.
Dear former intern: Just because .NET allows you to pass any object in the sender field of the event, does not mean you should use it to pass any arbitrary data. The first google result of "C# Custom Event" shows you exactly how to pass in custom event args.

Also, if your dialog only contains an ok and cancel button, you don't need to fire an event on when ok is pressed. Use the Dialog Result instead.

ohgodwhat
Aug 6, 2005

Mustach posted:

http://root.cern.ch/drupal/content/cint

I have no idea how good or bad it is.

I had to use it for a brief period of time. It was interesting...

captain_g
Aug 24, 2007
http://netbeans.org/bugzilla/show_bug.cgi?id=167395

Synopsis:

User: Your singleton has a public constructor and multiple instances of it are made.
Dev: Oh, it is not so bad, the extra instances of the singleton are thrown away.
User: Uh...

MrMoo
Sep 14, 2000

Ryouga Inverse posted:

How are you going to deal with the corpus of already-existing code?

Re-write it when it fails or needs modification. Probably end up with something neat like MUMPS-Linq.

Vanadium
Jan 8, 2005

code:
int EntrySortFunc(const void *pEl1, const void *pEl2) {
  Entry *pEntry1 = *(Entry * const *) pEl1, *pEntry2 = *(Entry * const *) pEl2;
  [...]
// sort folders before files
  bool fS1, fS2;
  if (!(fS1=!pEntry1->GetIsFolder()) != !true != !(fS2=!pEntry2->GetIsFolder())) return fS1-fS2;
:psyduck:

yippee cahier
Mar 28, 2005

Vanadium posted:

:psyduck:

!coherent

Nippashish
Nov 2, 2005

Let me see you dance!

sund posted:

!coherent

I think you mean !(!coherent != !true).

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through

Vanadium posted:

code:
int EntrySortFunc(const void *pEl1, const void *pEl2) {
  Entry *pEntry1 = *(Entry * const *) pEl1, *pEntry2 = *(Entry * const *) pEl2;
  [...]
// sort folders before files
  bool fS1, fS2;
  if (!(fS1=!pEntry1->GetIsFolder()) != !true != !(fS2=!pEntry2->GetIsFolder())) return fS1-fS2;
:psyduck:

maybe he doesn't know that == tests for equality?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

MasterSlowPoke posted:

maybe he doesn't know that == tests for equality?

Yeah, but != tests for !equality. So..... !?

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal
Long ago in college he spent hours debugging a program where he'd mistakenly typed = instead of == in a condition.

Never again.

Yakattak
Dec 17, 2009

I am Grumpypuss
>:3

YeOldeButchere posted:

Long ago in college he spent hours debugging a program where he'd mistakenly typed = instead of == in a condition.

Never again.

Gotta love new age compilers eh? poo poo, even codesense/intellisense will pick that up nowadays.

Zombywuf
Mar 29, 2008

Yakattak posted:

Gotta love new age compilers eh? poo poo, even codesense/intellisense will pick that up nowadays.

Clearly the problem here was a bad compiler...

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Nippashish posted:

I think you mean !(!coherent != !true).

That has to be programming by permutation. I refuse to believe anyone deliberately writes code like that.

BigRedDot
Mar 6, 2008

TRex EaterofCars posted:

That has to be programming by permutation. I refuse to believe anyone deliberately writes code like that.
Demorgan's Law is a law goddamnit, and you better follow it!

MononcQc
May 29, 2007

I got no code to show, but I've just found out about this bug:

A coworker of mine was saving hours in a database and chose to use the complete timestamp format (YYYY:MM:DD HH:mm:SS). However, he built the date using mktime() before sending it to the database. When there are parameters missing, mktime() completes them with the local date and time. For some reason, this made it so the main site would show an event's hour as right or wrong depending on the time of the day it was saved on in the admin panel.

I still don't really get how or why this all happens, but it made my day hell.

Adbot
ADBOT LOVES YOU

UberJumper
May 20, 2007
woop
:psyduck:

code:
_CREATE_GP_DEFS = {
  '9.0' : (lambda x = (lambda : __import__('win32com.client')) :
    win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")),
  '9.1' : (lambda x = (lambda : __import__('win32com.client')) :
    win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")),
  '9.2' : (lambda x = (lambda : __import__('arcgisscripting')) :
    arcgisscripting.create()),
  '9.3' : (lambda x = (lambda : __import__('arcgisscripting')) :
    arcgisscripting.create(9.3))
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply