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
LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

nielsm posted:

Python code:
mod = {x: (max(0, x) + 2.0) / (max(0, -x) + 2.0) for x in range(-6, 7)}

You win this round, nielsm.

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->

1337JiveTurkey posted:

It sounds like it's referring to the form of normalization used. With Unicode there are often equivalent encodings for the same character which are semantically identical but retained to retain round-trip encoding for other character sets. Since a string can contain either, in order to tell if two strings are the same there needs to be some canonical form. NFD is the fully decomposed normal form (everything that can be formed using a base character and combining diacritics is written that way) while NFC is the fully* composed form after full decomposition. I'm not sure how it ties into git.

*For small values of fully.

Some people use NFC names. Mac OSX stores names as NFD. Git treats filenames as opaque filestrings.

*checks out repo on osx, git complains that files are missing*

substitute
Aug 30, 2003

you for my mum
PHP code:
function register()
{
    if (!empty($_POST)) {
        $msg = '';
        if ($_POST['user_name']) {
            if ($_POST['user_password_new']) {
                if ($_POST['user_password_new'] === $_POST['user_password_repeat']) {
                    if (strlen($_POST['user_password_new']) > 5) {
                        if (strlen($_POST['user_name']) < 65 && strlen($_POST['user_name']) > 1) {
                            if (preg_match('/^[a-z\d]{2,64}$/i', $_POST['user_name'])) {
                                $user = read_user($_POST['user_name']);
                                if (!isset($user['user_name'])) {
                                    if ($_POST['user_email']) {
                                        if (strlen($_POST['user_email']) < 65) {
                                            if (filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)) {
                                                create_user();
                                                $_SESSION['msg'] = 'You are now registered so please login';
                                                header('Location: ' . $_SERVER['PHP_SELF']);
                                                exit();
                                            } else $msg = 'You must provide a valid email address';
                                        } else $msg = 'Email must be less than 64 characters';
                                    } else $msg = 'Email cannot be empty';
                                } else $msg = 'Username already exists';
                            } else $msg = 'Username must be only a-z, A-Z, 0-9';
                        } else $msg = 'Username must be between 2 and 64 characters';
                    } else $msg = 'Password must be at least 6 characters';
                } else $msg = 'Passwords do not match';
            } else $msg = 'Empty Password';
        } else $msg = 'Empty Username';
        $_SESSION['msg'] = $msg;
    }
    return register_form();
}

omeg
Sep 3, 2012

That's sort of beautiful. :allears:

substitute
Aug 30, 2003

you for my mum

omeg posted:

That's sort of beautiful. :allears:

It's like a fractal or something. So trippy, dude.

leftist heap
Feb 28, 2013

Fun Shoe
Is that what life is like when the only programming construct you understand is if-else?

substitute
Aug 30, 2003

you for my mum

rrrrrrrrrrrt posted:

Is that what life is like when the only programming construct you understand is if-else?

It's inside a weird new addition (called "0-one-file version") to this: http://www.php-login.net/

.. which has a full MVC version, along with two other simple class versions. So a new single file option seems like a pointless exercise.

qntm
Jun 17, 2009

substitute posted:

PHP code:
function register()
{
    if (!empty($_POST)) {
        $msg = '';
        if ($_POST['user_name']) {
            if ($_POST['user_password_new']) {
                if ($_POST['user_password_new'] === $_POST['user_password_repeat']) {
                    if (strlen($_POST['user_password_new']) > 5) {
                        if (strlen($_POST['user_name']) < 65 && strlen($_POST['user_name']) > 1) {
                            if (preg_match('/^[a-z\d]{2,64}$/i', $_POST['user_name'])) {
                                $user = read_user($_POST['user_name']);
                                if (!isset($user['user_name'])) {
                                    if ($_POST['user_email']) {
                                        if (strlen($_POST['user_email']) < 65) {
                                            if (filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)) {
                                                create_user();
                                                $_SESSION['msg'] = 'You are now registered so please login';
                                                header('Location: ' . $_SERVER['PHP_SELF']);
                                                exit();
                                            } else $msg = 'You must provide a valid email address';
                                        } else $msg = 'Email must be less than 64 characters';
                                    } else $msg = 'Email cannot be empty';
                                } else $msg = 'Username already exists';
                            } else $msg = 'Username must be only a-z, A-Z, 0-9';
                        } else $msg = 'Username must be between 2 and 64 characters';
                    } else $msg = 'Password must be at least 6 characters';
                } else $msg = 'Passwords do not match';
            } else $msg = 'Empty Password';
        } else $msg = 'Empty Username';
        $_SESSION['msg'] = $msg;
    }
    return register_form();
}

This is kind of what my very first ever Java program looked like when I didn't understand try/catch blocks very well.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
A bunch of my first few months of code looked like that, until I learned about the arrow anti-pattern and early exit from functions.

nielsm
Jun 1, 2009



I wrote something like this the other day. I can't determine whether it's good or bad.

Python code:
  raise {
    'FARTED_TOO_EARLY': FartedTooEarlyError,
    'NOT_A_BUTT': InvalidButtError,
    'BUTT_WAS_DIRTY': InvalidButtError,
    'MISSING_BUTT': MissingButtError,
  }.get(response['status'], ButtError)(response['message'])

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Bognar posted:

A bunch of my first few months of code looked like that, until I learned about the arrow anti-pattern and early exit from functions.

The best part is that it even has an early exit, so it's not just SESE insanity.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Plorkyeran posted:

The best part is that it even has an early exit, so it's not just SESE insanity.

Well, not SESE anyway.

xtal
Jan 9, 2011

by Fluffdaddy

nielsm posted:

I wrote something like this the other day. I can't determine whether it's good or bad.

Python code:
  raise {
    'FARTED_TOO_EARLY': FartedTooEarlyError,
    'NOT_A_BUTT': InvalidButtError,
    'BUTT_WAS_DIRTY': InvalidButtError,
    'MISSING_BUTT': MissingButtError,
  }.get(response['status'], ButtError)(response['message'])

The dict/get concept is a popular Python idiom that replaces a standard switch statement. Nothing wrong with it.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

substitute posted:

PHP code:
function register()
{
    if (!empty($_POST)) {
        $msg = '';
        if ($_POST['user_name']) {
            if ($_POST['user_password_new']) {
                if ($_POST['user_password_new'] === $_POST['user_password_repeat']) {
                    if (strlen($_POST['user_password_new']) > 5) {
                        if (strlen($_POST['user_name']) < 65 && strlen($_POST['user_name']) > 1) {       -------*********>>>>>
                            if (preg_match('/^[a-z\d]{2,64}$/i', $_POST['user_name'])) {
                                $user = read_user($_POST['user_name']);
                                if (!isset($user['user_name'])) {
                                    if ($_POST['user_email']) {
                                        if (strlen($_POST['user_email']) < 65) {
                                            if (filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)) {
                                  ============  create_user();
                          ====================  $_SESSION['msg'] = 'You are now registered so please login';
                          ====================  header('Location: ' . $_SERVER['PHP_SELF']);
                                  ============  exit();
                                            } else $msg = 'You must provide a valid email address';
                                        } else $msg = 'Email must be less than 64 characters';
                                    } else $msg = 'Email cannot be empty';
                                } else $msg = 'Username already exists';
                            } else $msg = 'Username must be only a-z, A-Z, 0-9';
                        } else $msg = 'Username must be between 2 and 64 characters';      -------******>>>>>>
                    } else $msg = 'Password must be at least 6 characters';
                } else $msg = 'Passwords do not match';
            } else $msg = 'Empty Password';
        } else $msg = 'Empty Username';
        $_SESSION['msg'] = $msg;
    }
    return register_form();
}

I made it into a side scroller fighter ship.

dc3k
Feb 18, 2003

what.

substitute posted:

PHP code:
function register()
{
    if (!empty($_POST)) {
        $msg = '';
        if ($_POST['user_name']) {
            if ($_POST['user_password_new']) {
                if ($_POST['user_password_new'] === $_POST['user_password_repeat']) {
                    if (strlen($_POST['user_password_new']) > 5) {
                        if (strlen($_POST['user_name']) < 65 && strlen($_POST['user_name']) > 1) {
                            if (preg_match('/^[a-z\d]{2,64}$/i', $_POST['user_name'])) {
                                $user = read_user($_POST['user_name']);
                                if (!isset($user['user_name'])) {
                                    if ($_POST['user_email']) {
                                        if (strlen($_POST['user_email']) < 65) {
                                            if (filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)) {
                                                create_user();
                                                $_SESSION['msg'] = 'You are now registered so please login';
                                                header('Location: ' . $_SERVER['PHP_SELF']);
                                                exit();
                                            } else $msg = 'You must provide a valid email address';
                                        } else $msg = 'Email must be less than 64 characters';
                                    } else $msg = 'Email cannot be empty';
                                } else $msg = 'Username already exists';
                            } else $msg = 'Username must be only a-z, A-Z, 0-9';
                        } else $msg = 'Username must be between 2 and 64 characters';
                    } else $msg = 'Password must be at least 6 characters';
                } else $msg = 'Passwords do not match';
            } else $msg = 'Empty Password';
        } else $msg = 'Empty Username';
        $_SESSION['msg'] = $msg;
    }
    return register_form();
}

I call it the crocodile clause.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
It looks like a fire raging out to the right.

Zombywuf
Mar 29, 2008

My life is now made of debug prints fixing data races. Spot the bug fix*:
Python code:
if True: # a % 128 == 0:
    DEBUG('page elements left:%d' % a)
* Well, the bug goes away.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Is the bug fix synchronizing on IO at that point?

Zombywuf
Mar 29, 2008

Jabor posted:

Is the bug fix synchronizing on IO at that point?

It's more likely that it introduces a slight delay making the race less likely to manifest than any synchronising effect.

NtotheTC
Dec 31, 2007


Zombywuf posted:

It's more likely that it introduces a slight delay making the race less likely to manifest than any synchronising effect.

Python code:
if True: # a % 128 == 0:
    time.sleep(1) # Making application more RESTful

tef
May 30, 2004

-> some l-system crap ->

Zombywuf posted:

It's more likely that it introduces a slight delay making the race less likely to manifest than any synchronising effect.

iirc (and i probably don't), the bug is pretty much from making QtWebkit do things that it doesn't like doing. An event is fired, and something may or may not happen. A timeout can also happen. However, the events can queue up, so sometimes both the timeout *and* the event fire, and sometimes in an arbitrary order. (Note: Qt is ostensibly single threaded, but QtWebKit isn't)

anyway, bad things can happen.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I've had plenty of times where adding debug prints was enough to eliminate some bizarre asynchronous behavior. But rebooting the machine is also likely to eliminate the particular problem. Heck, restarting the IDE has been sufficient sometimes. This has lead me to make a rule for myself that whenever possible, I attack those kinds of bugs as soon as they happen, where the happen, because it might go hide again soon enough. By the time I've found the bug, I've exposed some nasty rear end thing that was causing all kinds of problems everywhere.

quiggy
Aug 7, 2010

[in Russian] Oof.


Scaramouche posted:

I made it into a side scroller fighter ship.

Not as good as flying a plane into code :colbert:

That Turkey Story
Mar 30, 2003

911.php was an inside job.

ephphatha
Dec 18, 2009




code:
[a line of code]
//<ticket number>
//[the exact same loving line of code]
It's always like this. Every loving file has commented out poo poo duplicated exactly immediately before/after the commented out poo poo.

Edit: same file

code:
where table1_id = :id
and table1_id = table2_id
and table1_id = table3_id
and table1_id = table4_id
and table1_id = table5_id
and table2_id = :id
and table2_id = table3_id
and table2_id = table4_id
and table2_id = table5_id
and table3_id = :id
and table3_id = table4_id
and table3_id = table5_id
and table4_id = :id
and table4_id = table5_id
and table5_id = :id

ephphatha fucked around with this message at 06:00 on Aug 22, 2013

Posting Principle
Dec 10, 2011

by Ralp
C++ code:
typedef QColor QColour;
:canada:

One Eye Open
Sep 19, 2006
Am I awake?

Posting Principle posted:

C++ code:
typedef QColor QColour;
:canada:

I once did it the opposite way, after I was told Americans kept spelling it their way and getting errors using a library I wrote, even though they included the header file, "colour.h" right.

:britain:

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost
Not so much coding horror, but management horror. I was fixing an old ASP gantt chart page when I saw this.

code:
// this was stupid, embarassing in fact 
// if i wasn't so level-headed i would fire someone for this - *** 04-01-02 
//if (wt_part <= 25) { 
// line_img = 'blue'; 
//} else if (wt_part > 25 && wt_part <= 50) { 
// line_img = 'green'; 
//} else if (wt_part > 50 && wt_part <= 75) { 
// line_img = 'yellow'; 
//} else if (wt_part > 75) { 
// line_img = 'red'; 
//} 
// this sanity replaces the ridiculous crap from directly above - ***  04-02-02 
// call me a hothead, but i'm still considering firing someone for this 
taskPercentComplete = (twh [ca [pid][i]] / ett [ca [pid][i]]) * 100; 
if (isNaN(taskPercentComplete)) 
	taskPercentComplete = 0; 
if (taskPercentComplete > 100) 
	taskPercentComplete = 100; 
if (taskPercentComplete <= 25) { 
	line_img = 'blue'; 
} else if (taskPercentComplete > 25 && taskPercentComplete <= 50) { 
	line_img = 'green'; 
} else if (taskPercentComplete > 50 && taskPercentComplete <= 75) { 
	line_img = 'yellow'; 
} else if (taskPercentComplete > 75) { 
	line_img = 'red'; 
}
No one knows who exactly wrote that (Both the code itself and the comment). My manager and the rest of my team came on well after this person left, and this was from before they used Subversion or any check in service. This was also a time when they would do live edits of code in production and had only one computer with backups, so it was pretty hosed up all around. Thankfully that does not happen anymore.

seiken
Feb 7, 2005

hah ha ha
This was posted on Stack Overflow under the title How to create an array? It's now deleted. I present it here without comment.

quote:

You are about to be provided with information to start your own Google.

Some people posted comments and said this can not be done because google has 1 million servers and we do not.

The truth is, google has those many servers for trolling purposes (e.g. google +, google finance, youtube the bandwidth consuming no-profit making web site, etc ).

all for trolling purposes.

if you wanted to start your own search engine... you need to know few things.

1 : you need to know how beautiful mysql is.
2: you need to not listen to people that tell you to use a framework with python, and simply use mod-wsgi.
3: you need to cache popular searches when your search engine is running.
3: you need to connect numbers to words. maybe even something like.. numbers to numbers to words.

in other words let's say in the past 24 hours people searched for some phrases over and over again.. you cache those and assign numbers to them, this way you are matching numbers with numbers in mysql. not words with words.

in other words let's say google uses 1/2 their servers for trolling and 1/2 for search engine.

we need technology and ideas so that you can run a search engine on 1 or 2 dedicated servers that cost no more than $100/month each.

once you make money, you can begin buying more and more servers. after you make lots of money.. you probably gonna turn into a troll too like google inc.

because god is brutal. god is void-state it keeps singing you songs when you are sleeping and says "nothing matters, there is simply no meaning"

but of course to start this search engine, you need a jump start. if you notice google constantly links to other web sites with a trackable way when people click on search results.

this means google knows which web sites are becoming popular are popular, etc. they can see what is rising before it rises. it's like being able to see the future.

the computer tells them " you better get in touch with this guy before he becomes rich and becomes un-stopable "

sometimes they send cops onto people. etc.

AMAZON INC however..

will provide you with the top 1 million web sites in the world. updated daily in a cvs file. downloadable at alexa.com

simply click on 'top sites' and then you will see the downloadable file on the right side.

everyday they update it. and it is being given away for free. google would never do this. amazon does this.

this list you can use to ensure you show the top sites first in your search engine .

this makes your search engine look 'credible'

in other words as you start making money, you first display things in a "Generic" way but at the same time not in a "questionable" way by displaying them based on "rank"

of course amazon only gives you URLS of the web sites. you need to grab the title and etc from the web sites.

the truth is, to get started you do not need everything from web sites. a title and some tags is all you need.

simple. basic. functional will get peoples attention.

i always ask questions on SO but most questions get deleted. here's something that did not get deleted..

How do I ensure that re.findall() stops at the right place?

use python, skrew php, php is no good. do not use python frameworks, it's all lies and b.s. use mod-wsgi use memcache to cache the templates and thus no need for a template engine.

always look at russian dedicated servers, and so on. do not put your trust in america. it has all turned into a mafia.

google can file a report, fbi can send cops onto you, and next thing you know they frame you as a criminal, thug, mentally ill, bipolar, peadophile, and so on.

all you can do is bleed to death behind bars.

do not give into the lies of AMERICA. find russian dedicated servers.

i tried signing up with pw-service.com but i couldn't do it due to restrictions with their russian payment systems and so on..

again, amazon's web site alexa.com provides you with downloadable top 1 mil web sites in the form of a cvs file.

use it.

again, do not give into python programmers suggesting frameworks for python. it's all b.s. use mod_wsgi with memcache.

again, american corporations can ruin you with lies and all you can do is bleed to death behind bars

again, a basic search engine needs : url, title, tags, and popular searches can be "cached" and words can be connected to "numbers" within the mysql.

mysql has capabilities to cache things as well.

cache once, cache twice, and you will not need 1 million servers in order to troll.

if you need some xdotool commands to deal with people calling you a troll here it is;

code:
      xdotool key ctrl+c
      xdotool key Tab Tab Tab Return
      xdotool type '@'
      xdotool key ctrl+v
      xdotool type --clearmodifiers ', there can not be such thing as a `troll`
          unless compared to a stationary point, if you are complaining, you are
          not stationary. which means you are the one that is trolling.'
      xdotool key Tab Return
create an application launcher on your gnome-panel, and then select the username in the comments section that called you a 'troll' and click the shortcut on the gnome-panel.

it will copy the selected username to the clipboard and then hit TAB TAB TAB RETURN

which opens the comment typing box. and then it will type @ + username + comma, and then the rest.

seiken fucked around with this message at 20:40 on Aug 22, 2013

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I can't imagine why anyone would call that person mentally ill.

I wonder what they think "troll" means, they don't seem to be using it correctly in any sense I recognise.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Pretty reasonable if you ask me.

Lorem ipsum
Sep 25, 2007
IF I REPORT SOMETHING, BAN ME.
Someone should tell him he can run his search engine off AWS

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
Sweet, my first contribution (oh god I hope I don't have to post here often):


I couldn't get the RDP clipboard to work so I had to make an image

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

seiken posted:

This was posted on Stack Overflow under the title How to create an array? It's now deleted. I present it here without comment.

I'm... honestly not sure if the guy was trolling or mentally ill :psyduck:

substitute
Aug 30, 2003

you for my mum

Volmarias posted:

I'm... honestly not sure if the guy was trolling or mentally ill :psyduck:

Well I'm going with he's criminal, thug, mentally ill, bipolar, peadophile, and so on.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Sincerely,

Paul Edward McLaughlin

RoadCrewWorker
Nov 19, 2007

camels aren't so great
I've been waiting for a cuil post-mortem, sad to see their engineer has hit tough times.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

RoadCrewWorker posted:

I've been waiting for a cuil post-mortem, sad to see their engineer has hit tough times.

They should have used the Alexa top million list then they would be awesome and trolling.

Sticky Profits
Aug 12, 2011
I refuse to read any more posts until you guys get with the times and start assigning numbers to the numbers to the words of your posts.

Adbot
ADBOT LOVES YOU

Sereri
Sep 30, 2008

awwwrigami

I[1] am[2] not[3] really[4] sure[5] what[6] in[7] the[8] goddamn[9] world[10] I[1] just[11] read[12].

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