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
Suspicious Dish
Sep 24, 2011

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

Zamujasa posted:

Proper escaping

What about prepared statements, so you're separating your logic and data, instead of generating a piece of code that gets eval'd?

Adbot
ADBOT LOVES YOU

Mesothelioma
Jan 6, 2009

Your favorite mineral related cancer!
I just found out that changing the screen orientation on android closes the app. Welp

Deus Rex
Mar 5, 2005

JavaScript code:
var sendData = "a=" + encodeURIComponent(data.aardvark);
sendData += "&b=" + encodeURIComponent(data.butt);
sendData += "&c=" + encodeURIComponent(data.catte);
sendData += "&d=" + encodeURIComponent(data.dogge);
/* ... continues, with some fields inexplicably not encoded */
sendData += "&z=" + encodeURIComponent(data.ziggurat);

$.ajax({
    /* ... */
    data: sendData,
    /* ... */
});
:sigh:

Zamujasa
Oct 27, 2010



Bread Liar

Suspicious Dish posted:

What about prepared statements, so you're separating your logic and data, instead of generating a piece of code that gets eval'd?

Zamujasa posted:

The rest of it is just pure bullshit though. Proper escaping (or just using a real database object and avoid manual queries as much as is feasible) will prevent that poo poo.

Having worked with Invision Power Board (which, mind you, has a function usefully named "boink_it") I had a momentary brain-fart that fully-prepared queries (where you never have to manually escape anything) were a thing, and not just the horrifying query-builder IPB uses. :saddowns: Give me a break, someone had their little 3-year old terrors running around the office today.


Deus Rex posted:

JavaScript code:
var sendData = "a=" + encodeURIComponent(data.aardvark);
sendData += "&b=" + encodeURIComponent(data.butt);
sendData += "&c=" + encodeURIComponent(data.catte);
sendData += "&d=" + encodeURIComponent(data.dogge);
/* ... continues, with some fields inexplicably not encoded */
sendData += "&z=" + encodeURIComponent(data.ziggurat);

$.ajax({
    /* ... */
    data: sendData,
    /* ... */
});
:sigh:
At least they're using jQuery (or similar)'s .ajax method instead of literally copying-and-pasting w3schools's ajax example over and over and just changing the URL inside the function! :smithicide: That thing's copied and pasted for every possible page he wanted to make an ajax request to, and instead of combining his "functions" (which are really just a glorified if-then-else block) into one file he spread them out, so each file really only has one "function" in it.

The end result is that you have at least 5+ instances of the exact same function with a slightly different URL (and sometimes slightly different code that runs when the AJAX request returns), and it only gets better when you realize there are functions that are literally just function dosomething() { doajaxrequest(); } with no arguments or anything.





(The sad part is that it turns out that's w3schools example is exactly what was copied and pasted -- I was hoping to just find a similar example with "javascript ajax example", but it turns out it's the exact same. One of the copy-pasted functions is even still named "loadXMLDoc()". :sigh: )

Zamujasa fucked around with this message at 01:34 on Sep 26, 2012

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Mesothelioma posted:

I just found out that changing the screen orientation on android closes the app. Welp
Yeah, it serializes the app, changes the orientation, then relaunches the app from the serialized data IIRC.

FamDav
Mar 29, 2008

Aleksei Vasiliev posted:

Yeah, it serializes the app, changes the orientation, then relaunches the app from the serialized data IIRC.

I remember the guy who's is coding the Android version of one of our apps mentions that. His response was "Yeah, a thing."

Doctor w-rw-rw-
Jun 24, 2008

Aleksei Vasiliev posted:

Yeah, it serializes the app, changes the orientation, then relaunches the app from the serialized data IIRC.
No, it saves Activity state. That's view data plus anything in onSaveInstanceState into a bundle, then it destroys the Activity, recreates it, and re-sets the content view.

This means that adding header views with state to adapters is such a horrible hack; you can only add them once, before you set the adapter, because it creates a wrapper that can't be changed after the fact, which will then crash.

Technically, you can specify "orientation" as one of the configuration changes you'll handle yourself, but this has bad interactions with some ad integrations in my experience, and probably more.

When the activity is recreated, then onCreate will be called as well as onRestoreInstanceState, if memory serves. However, the lovely part is that this behavior has changed at some point so that different Android versions treat this state persisting slightly differently.

I've taken to using Fragments, lately, and telling them to retain their instance so that, as much as possible, I don't have to reset my state. I don't know how beneficial it is, but it seems to, combined with other things I'm doing, work out better.

The real horror is dealing with Android 2.1 VideoView - there is a pause method, but no resume, and restoring their state is a shitshow of awesome proportions. It is a clusterfuck of epic awfulness. Especially if you have to pause video to, say, show a midroll ad. Holy poo poo. Maybe Fragments will save the day (and to some degree, the VideoView state).

---

E: now that I'm in front of a computer, I'll expand on this. I'm doing this mostly from memory so it may be incorrect.

So VideoViews can be unprepared, preparing, playing, completed, or errored. Activities can be in the process of creation, starting, or resuming, or (correspondingly) pausing, stopping, or destruction. In addition, the VideoView might be paused, and if you set the URL it can reset the state. When you receive a call or see a dialog box. it can go through some but not all of the onPause/onStop/onDestroy method and corresponding unwinding with onCreate/onStart/onResume methods, *in addition to* the onSaveInstanceState and onRestoreInstanceState.

What's more, some devices will always destroy backgrounded Activities, because they don't have very much memory at all. Even decent devices give you a scant couple of MB before it brings the reaper down on you.

Digression: It should be noted that no destruction or recreation is USUALLY needed for activities switching between one landscape and another, or one portrait and another - they're 180 degree turns, so no relayout is necessary. To specify this, you can use "sensorPortrait" or "sensorLandscape" as their orientation in the manifest. However, pre-2.3 device support poses a challenge. It turns out that most devices seem to treat it like a bitfield, and fall back appropriately when you specify this in the AndroidManifest. The numerical values are sensorLandscape = 6, or 0b110, sensorPortrait = 7, or 0b111, with landscape proper being 0 and portrait being 1. However, for whatever reason, Samsung devices don't work this way. I believe, but don't recall, it causes a crash. So, what you have to do instead, is for EVERY Activity in your application which supports sensor orientation, it has to first detect its API level, then it has to set the orientation. However, it must do this before setContentView is called, so if it is a subclass of an activity which could possibly touch setContentView, you must never call it after super.onCreate.

Anyways, back to the VideoView, you basically have five-ish states multiplies by three states as well as playing/paused. However, onSaveInstanceState is only guaranteed to be called before onStop, and will be called before or after onPause. Not to mention, in pre-honeycomb platforms, Activities need only be paused to be killed, meaning that onSaveInstanceState might not even be called. Also, it's easy to make naive mistakes like pausing on onPause or resuming the video in onResume. You might reset the video, or cause it to play immediately on returning to the app if it was paused before you left, and if a dialog comes up, you might have to deal with that before you can get back to the player to pause it.

Also, since there's no resume() method, you call start() instead. But if you call start() twice, it might rebuffer the video. So if you try to keep the necessary calls to the VideoView reconciled with the states the Activity could be in or restoring from, it's a crazy matrix of I HAVE NO IDEA WHAT I'M DOING most of the time.

tl;dr: If you're trying to stream videos on Android, and want to be able to multitask then come back to where you left off, and back up the resume point to the server at some point and be able to resume from that, be prepared to spend several months dealing with nondeterminism, hating yourself, lots of unintentional bugs, dealing with deep, crippling depression, many many angry users, and just...well...a toxic mix of :gonk: and :argh:?

But yeah. This is Android for you. Years of bullshit you'll never escape, fixes that stare you in the face and tantalize you with their presence only on high version numbers, and compatibility libraries that bridge some of the gap.

P.S. BTW, the Android Compatibility Library doesn't include a PreferenceFragment, a glaring omission because it's loving useful - and someone has a proof of concept backport so it's clearly possible - and since PreferenceActivity is not only limiting, but deprecated, your life sucks if you want to support both at the same time)

P.P.S. Did I mention that there are three different H.264 decoders in use on different devices or versions of Android (not sure which or if both)? So what plays fine on one might totally break for another. Additionally, GoogleTV runs API 12 and presumably supports HTTP Live Streaming (aka HLS), but Honeycomb (API 11-13) does not, but ICS (14, 15) and JB (16) do.

P.P.P.S. Man I keep on thinking of things to add. Basically, the problem is that the Android lifecycle works best when you model the data as unchanging, restorable objects. Since, for a given launch, the Intent stays the same, whenever I use immutable objects, things are pretty fine, since I can just reconstruct them from getIntent() in onCreate, and expect them to remain consistent across Activity destruction. On the other end of the spectrum, streaming video is extremely stateful, and reconciling the propensity of the Activity to destroy+recreate with the VideoView's awkward interface (it's actually a just a wrapper around yet more classes) is a monstrous horror.

Doctor w-rw-rw- fucked around with this message at 06:50 on Sep 26, 2012

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
php:
<?
function addDays($day){
$result = date("Y-m-d",time()+24*3600*$day);
return $result;
}?>
... This does not bode well.

#EDIT:

php:
<?
$EntryDate = addDays(0);
$today = addDays(0);
?>
#EDIT 2:

php:
<?
function MakePretty($day){
//$result = substr($day,5,5) . "-" . substr($day,0,4);
return $day;
}?>
These functions aren't globally defined, at least, so that means that they'll only show up in this file, right? RIGHT? nope

bobthecheese fucked around with this message at 08:14 on Sep 26, 2012

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

bobthecheese posted:

php:
<?
function addDays($day){
$result = date("Y-m-d",time()+24*3600*$day);
return $result;
}?>
... This does not bode well.
People never consider that not every day is 24 hours long. But once it bites them, they never forget it.
php:
<?
function MakePretty($day){
//$result = substr($day,5,5) . "-" . substr($day,0,4);
return $day;
}?>
:stare:
php:
<?
$EntryDate = addDays(0);
$today = addDays(0);
?>
:catstare:

OK, never mind, this guy needs a paddlin'.

Thermopyle
Jul 1, 2003

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

Golbez posted:

People never consider that not every day is 24 hours long. But once it bites them, they never forget it.

This poo poo is why I always use date/time libraries. Let someone else deal with the horrible mess that is the calendar.

Opinion Haver
Apr 9, 2007

Holy poo poo the source code for sh is awful

code:
LOCAL STRING	copyto(endch)
	REG CHAR	endch;
{
	REG CHAR	c;

	WHILE (c=getch(endch))!=endch ANDF c
	DO pushstak(c|quote) OD
	zerostak();
	IF c!=endch THEN error(badsub) FI
}

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal
I guess Bourne really wanted to be writing in some other language. :shrug:

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Yeah I think it was brought up before but

code:
#define IF	if(
#define THEN	){
#define ELSE	} else {
#define ELIF	} else if (
#define FI	;}
ftp://ftp.freebsd.org/pub/FreeBSD/distfiles/v7sh/mac.h

:holy:

xf86enodev
Mar 27, 2010

dis catte!

SavageMessiah posted:

I guess Bourne really wanted to be writing in some other language. :shrug:

Well if the movie trilogy about him is anything to go by his lifestyle choices made things quite a bit more exciting.

AlexG
Jul 15, 2004
If you can't solve a problem with gaffer tape, it's probably insoluble anyway.
The awful do/od, if/fi, case/esac, etc. syntax is from Algol 68.

Edsger Dijkstra, EWD230 posted:

Dear Editor,

Thank you for sending me MR93, which has absorbed a considerable fraction of my available mental energy since it is in my possession. It must have been very hard work to compose it; alas, it also makes rather grim reading. The document turned out like I expected it to be, only much more so.

The more I see of it, the more unhappy I become. I know it is a hard thing to say to an author who has struggled for many years, but the proper fate of this document may indeed range from being subjected to minor corrections to being completely rejected. If the latter is the most sensible thing to do, sending errata sheets and lots of people trying to understand what it is all about seems a sad waste of energy.

On account of the draft report my faith in WG.2.1 (at least in its present constitution) is very low. The draft report is thick and difficult, in fact too thick and too difficult to inspire much confidence. Is there any hope of weeding all errors from a work of such size and complexity? Is there any hope of a convincing demonstration that the proposal does not contain pitfalls any more? And is then this manuscript, that the Computing Community has been waiting for? I am very sorry for you, but I am having a hard time if I try to believe all that.

Size and complexity of the defining apparatus you needed terrify me. Being well-acquainted with your ingenuity I think it a safe assumption that ALGOL 68 as conceived can hardly be defined by significantly more concise and transparent means. Having "Simplex Veri Sigillum" as one of my mottoes -particularly with respect to programming- I feel inclined to put the blame on the language you tried to define. If this is correct, WG.2.1 should return to its proper subject matter, viz. programming languages.

I don't know what is going to happen with MR93 in WG.2.1. I expect a strong political pressure to recommend it and can see many of the fake arguments seemingly supporting the decision. (E.g. "So much has been put in it, that we cannot afford to reject it." or "It becomes absolutely necessary to produce a document and if we reject this, we are back where we were a couple of years ago." or "Who has anything better?". We can be sure that they will all turn up!) If MR93 turns out to be the dead alley I am now afraid it is, it will be more the fate of WG.2.1 than that of MR93 that will be at stake, viz. whether WG.2.1 will make itself ridiculous by recommending it. It makes me very miserable.

For you I most sincerely hope that your tremendous efforts will prove to have been well-directed, but I am terribly afraid.....

Yours ever

Edsger W. Dijkstra

Workaday Wizard
Oct 23, 2009

by Pragmatica

AlexG posted:

...Edsger Dijkstra quote...

I read the quote but I don't get it. What is his complaint?

dis astranagant
Dec 14, 2006

Shinku ABOOKEN posted:

I read the quote but I don't get it. What is his complaint?

I think someone handed him a thousand page draft spec and he didn't like the complexity of the beast. ALGOL 60 was a pretty simple and easy to implement language, ALGOL 68 was considered Djikstra and others to be be overly broad and a pain to write a compiler for. The report came out in 68 but there wasn't a full compiler written until the mid 70s.

dis astranagant fucked around with this message at 20:37 on Sep 27, 2012

Okita
Aug 31, 2004
King of toilets.
code:
if not @id is null
begin
	select @sql = @sql + '
insert into nccdhldauxdata (nccardholderid, ncfieldid, ncdata)
	values ('+convert(varchar(10), @chid)+', 14, '''+replace(@id, '''', '''''')+''')'
end
I just spent the last 3 hours listening to music and staring at this at work. It's not that I don't get what it does. I'm sure it does something.

It made me ponder about life, humanity, and which direction we're headed in as a species. It also made me think about what an "ncchihuahua" looks like and what the little single quotes could represent artistically(a choo-choo train).

The man that wrote this code must be a genius. His subtly ironic code paints an allegory of the plight of modern man, the loss of the frontier, and the problems of modern society. These are all perfectly captured in this concise piece of art.

ijustam
Jun 20, 2005

if not [x] is null? What flavor of SQL is that? I thought they were all "if [x] is not null"

KaneTW
Dec 2, 2011

not (x is null) is a synonym (at least without going into specifics) for x is not null.

bucketmouse
Aug 16, 2004

we con-trol the ho-ri-zon-tal
we con-trol the verrr-ti-cal
http://jsil.org/

quote:

JSIL is a compiler that transforms .NET applications and libraries from their native executable format - CIL bytecode - into standards-compliant, cross-browser JavaScript.

:psyboom:

OnceIWasAnOstrich
Jul 22, 2006


Isn't that guy a goon? I remember trying to use some of his EVE-related scripts and seeing a CIL to JS compiler in his Github and wondering wtf that was. The code I used wasn't especially horror inducing.

OnceIWasAnOstrich fucked around with this message at 23:59 on Sep 27, 2012

akadajet
Sep 14, 2003


The horror is that it seems to handle XNA games fairly well?

KaneTW
Dec 2, 2011

Yeah, he's a goon (i've been using shootblues a lot back in the day). It isn't really a coding horror imo; it certainly has it's uses.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Maybe the thought-to-be horror is the world accidentally specifying the only cross-browser virtual machine in the form of interpreted source code?

PrBacterio
Jul 19, 2000

pokeyman posted:

Maybe the thought-to-be horror is the world accidentally specifying the only cross-browser virtual machine in the form of interpreted source code?
You know, that go me thinking ... maybe someone could make a microprocessor that directly executes Javascript as its native machine language. Then we'd finally arrived at the one true architecture to be used everywhere. Someone should get on this! :suicide:

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

That's not a horror, that's loving awesome.

that awful man
Feb 18, 2007

YOSPOS, bitch

Shinku ABOOKEN posted:

I read the quote but I don't get it. What is his complaint?

http://repository.cwi.nl/search/fullrecord.php?publnr=9187

PrBacterio posted:

You know, that go me thinking ... maybe someone could make a microprocessor that directly executes Javascript as its native machine language. Then we'd finally arrived at the one true architecture to be used everywhere. Someone should get on this! :suicide:

http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AIM-514.pdf
http://dspace.mit.edu/handle/1721.1/6334
http://groups.csail.mit.edu/mac/users/mhwu/scheme86/scheme86-home.html
http://research.microsoft.com/en-us/um/people/gbell/Computer_Structures__Readings_and_Examples/00000383.htm
http://research.microsoft.com/en-us/um/people/gbell/Computer_Structures_Principles_and_Examples/csp0524.htm

dis astranagant
Dec 14, 2006


Wow, if you cut off the index you can fit the entire ALGOL 60 revised spec (EWD was on the team for the first several ALGOL 60 compilers and cranked the first one out in like 2 months) inside the table of contents of that mess. THAT is what his complaint was.

N.Z.'s Champion
Jun 8, 2003

Yam Slacker
The contents of global.css
code:
/* CSS Document */

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Accurate. And it's tiny when gzipped!

PrBacterio
Jul 19, 2000
Ehh, Lisp machines weren't really horrors in the same way a Javascript machine would be; they were basically just computer architectures designed with efficient compilation of Lisp source code in mind, much in the same way pretty much every machine architecture these days is designed for C/C++.

Beef
Jul 26, 2004

PrBacterio posted:

much in the same way pretty much every machine architecture these days is designed for C/C++.

You got it the other way around, young grasshopper.

Also, Lisp-machines were very much made just for Lisp, which is very obvious from its ISA, It's a bit like baking in the java VM. The main difference was that they could just modify the Lisp dialect they used to make the implementors happy. Java and Javascript have so much :psyduck: for implementors that it's just not useful to bake it on a chip, even under the massive commercial pressure to do so. For some presentations on 'wtf JVM', check out Cliff Click's presentations/posts.

Beef fucked around with this message at 15:58 on Sep 28, 2012

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!
Can't give many details but this is a typical New Relic page on the CMS we use:


Features:
- 500+ SQL queries to show most pages, all stored procedures (in this example some queries were cached)
- all content served from the same aspx page
- coded in Visual Basic and it seems so convoluted that even the smallest changes require at least a week
- No useful version control
- Any small change requires DB changes and they are done in a non-backwards compatibleway (haha you want to revert to what version?)

Needless to say it's getting replaced.

deimos fucked around with this message at 16:18 on Oct 1, 2012

Quote-Unquote
Oct 22, 2002



bobthecheese posted:

php:
<?
function addDays($day){
$result = date("Y-m-d",time()+24*3600*$day);
return $result;
}?>
... This does not bode well.

If I'm reading this right, this function is just supposed to add on a number of days from today's date and return it in a YYYY-MM-DD format?
I'm guessing this guy never heard of strtotime?
PHP has a lot of silly poo poo but strtotime is the most awesome solution I've seen for dealing with dates.

Still, life would be much better if we would just shut up and convert to metric time already

Primpod
Dec 25, 2007

jamming on crusty white
(classic asp)
VB Script code:
strAjaxMethods = ""
strAjaxCalls = ""
with recordset 
	do while not .eof
		strAjaxMethods = strAjaxMethods & " var http" & .Fields("Code") & " = createRequestObject(); " & chr(013)
		strAjaxMethods = strAjaxMethods & " function get" & .Fields("Code") & "() " & chr(013)
		strAjaxMethods = strAjaxMethods & "{ " & chr(013)
		strAjaxMethods = strAjaxMethods & " /* Some unrelated code */" & chr(013)
		strAjaxMethods = strAjaxMethods & "} " & chr(013)
		strAjaxCalls = strAjaxCalls &  "get" & .Fields("Code") & "();" & chr(013)
	loop 
End with

'after all other page content.
<%=strAjaxMethods%>
<%=strAjaxCalls%>
Our codebase is the worst codebase.

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
I... I give up. Seriously, gently caress. I'm out.

php:
<?
$resultProfit = ConnectToDatabase($sqlProfit);
if (mysql_num_rows($resultProfit)>500) {
    $resultProfit = ConnectToDatabase($sqlProfit." LIMIT 500");
}
?>

Chopper
Feb 13, 2006

bobthecheese posted:

I... I give up. Seriously, gently caress. I'm out.

php:
<?
$resultProfit = ConnectToDatabase($sqlProfit);
if (mysql_num_rows($resultProfit)>500) {
    $resultProfit = ConnectToDatabase($sqlProfit." LIMIT 500");
}
?>

I don't understand how someone has the logical ability to write code, but then writes something so utterly illogical as that.

:suicide:

big trivia FAIL
May 9, 2003

"Jorge wants to be hardcore,
but his mom won't let him"

Chopper posted:

I don't understand how someone has the logical ability to write code, but then writes something so utterly illogical as that.

:suicide:

A new(er) developer that read the analyst's (me) requirements and carried them out in code to a T? I've seen junior devs do things like that quite a bit. Maybe we just recruit terrible junior devs.

Adbot
ADBOT LOVES YOU

raminasi
Jan 25, 2005

a last drink with no ice

Chopper posted:

I don't understand how someone has the logical ability to write code, but then writes something so utterly illogical as that.

:suicide:

Never TA'd a CS 101 class, huh?

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