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
Data Graham
Dec 28, 2009

📈📊🍪😋



Huh, interesting. Promising.

...But apparently not supported in MySQL. :negative:

Adbot
ADBOT LOVES YOU

Sedro
Dec 31, 2008
Let postgres into your life~

revmoo
May 25, 2006

#basta
Postgres kicks rear end but dear god all the GUI apps available for it are garbage. I can tolerate Navicat but Sequel Pro runs circles around it in every way.

DrSunshine
Mar 23, 2009

Did I just say that out loud~~?!!!
Hi, it's me again. I've run into a problem. Basically, the point of this code is to make it load sequential images from a folder until it runs out of images to load. But this is apparently making an infinite loop, but I can't figure out why! That's what the "onerror" is supposed to catch, right?

code:
//Loading images. Run loop until image loading returns false.

function loadImage(n){
	imageLoader = true;
	while (imageLoader){
		var img = new Image();
		img.src = './chapter' + n + '/' + c + '.png';
		img.onload = function(){
			document.getElementById('docDisplay').appendChild(img);
			c++;
		}
		img.onerror = function(){
			imageLoader = false;
			c = 1;
		}
	}
}

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

DrSunshine posted:

Hi, it's me again. I've run into a problem. Basically, the point of this code is to make it load sequential images from a folder until it runs out of images to load. But this is apparently making an infinite loop, but I can't figure out why! That's what the "onerror" is supposed to catch, right?

code:
//Loading images. Run loop until image loading returns false.

function loadImage(n){
	imageLoader = true;
	while (imageLoader){
		var img = new Image();
		img.src = './chapter' + n + '/' + c + '.png';
		img.onload = function(){
			document.getElementById('docDisplay').appendChild(img);
			c++;
		}
		img.onerror = function(){
			imageLoader = false;
			c = 1;
		}
	}
}

Because JS is asynchronous. Observe this fiddle: http://jsfiddle.net/veddermatic/oL1q92fq/


Note that both "The while loop" calls happen before any "the error handler" calls. So imageLoader is never set to false in your code because none of the onerrors ever get a chance to fire.. Also, make sure you aren't using globals for things like your imageLoader and c variables. Also also, in your snippet, you never define c, so it won't run at all.

EDIT: A possible quick "fix" is to not use a while loop, and instead use a recursive call to loadImage in the onload handler.

Lumpy fucked around with this message at 22:08 on Mar 5, 2015

The Merkinman
Apr 22, 2007

I sell only quality merkins. What is a merkin you ask? Why, it's a wig for your genitals!
Any idea why an element with a single line of copy and equal heights and line-heights would be vertically aligned in Firefox but not Chrome? I can't just do a fiddle since it might be some other code conflicting. A simple test of the bare minimum is fine

DrSunshine
Mar 23, 2009

Did I just say that out loud~~?!!!

Lumpy posted:

Because JS is asynchronous. Observe this fiddle: http://jsfiddle.net/veddermatic/oL1q92fq/


Note that both "The while loop" calls happen before any "the error handler" calls. So imageLoader is never set to false in your code because none of the onerrors ever get a chance to fire.. Also, make sure you aren't using globals for things like your imageLoader and c variables. Also also, in your snippet, you never define c, so it won't run at all.

EDIT: A possible quick "fix" is to not use a while loop, and instead use a recursive call to loadImage in the onload handler.

So, basically all I need to do is place the "onerror" before the other stuff, but after the img.src? By the way, the reason why I'm using a while loop is because each chapter folder might have a different number of pages. So I need it to just look for pages to load until it can't do it anymore.

Thanks for the advice, by the way!

Ghostlight
Sep 25, 2009

maybe for one second you can pause; try to step into another person's perspective, and understand that a watermelon is cursing me



The Merkinman posted:

Any idea why an element with a single line of copy and equal heights and line-heights would be vertically aligned in Firefox but not Chrome? I can't just do a fiddle since it might be some other code conflicting. A simple test of the bare minimum is fine
Well if it works fine in isolation then the problem is other code, at which point it could be virtually anything.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

DrSunshine posted:

So, basically all I need to do is place the "onerror" before the other stuff, but after the img.src? By the way, the reason why I'm using a while loop is because each chapter folder might have a different number of pages. So I need it to just look for pages to load until it can't do it anymore.

Thanks for the advice, by the way!

No. If you are doing things in a while loop, none of you onerror calls will ever happen ever until the loop is done iterating. Since the only way your loop stops iterating is if an onerror call happens, you will always have an infinite loop. You will need to use recursion as I suggested. I will do up an example after I am done carting my kid around.

EDIT: had some extra time. Here's a recursive version that does what you want: http://jsfiddle.net/veddermatic/oL1q92fq/1/

Lumpy fucked around with this message at 23:31 on Mar 5, 2015

revmoo
May 25, 2006

#basta

Ghostlight posted:

Well if it works fine in isolation then the problem is other code, at which point it could be virtually anything.


Yeah. Use the divide and conquer method, just start ripping code out until the problem goes away.

The Merkinman
Apr 22, 2007

I sell only quality merkins. What is a merkin you ask? Why, it's a wig for your genitals!

Ghostlight posted:

Well if it works fine in isolation then the problem is other code, at which point it could be virtually anything.
Yeah I just didn't know if there were certain things to look for like padding or border etc

DrSunshine
Mar 23, 2009

Did I just say that out loud~~?!!!

Lumpy posted:

No. If you are doing things in a while loop, none of you onerror calls will ever happen ever until the loop is done iterating. Since the only way your loop stops iterating is if an onerror call happens, you will always have an infinite loop. You will need to use recursion as I suggested. I will do up an example after I am done carting my kid around.

Oh, I get it -- right, because the loop always iterates before the onerror call is triggered.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

DrSunshine posted:

Oh, I get it -- right, because the loop always iterates before the onerror call is triggered.

Correct. I edited in to my other post, but here's a recursive example: http://jsfiddle.net/veddermatic/oL1q92fq/1/

DrSunshine
Mar 23, 2009

Did I just say that out loud~~?!!!

Lumpy posted:

Correct. I edited in to my other post, but here's a recursive example: http://jsfiddle.net/veddermatic/oL1q92fq/1/

Thanks! That's very enlightening. One more question -- you end the function with lol_improved(1); -- what does this do?

The Merkinman
Apr 22, 2007

I sell only quality merkins. What is a merkin you ask? Why, it's a wig for your genitals!

revmoo posted:

Yeah. Use the divide and conquer method, just start ripping code out until the problem goes away.

It's the font? Has anyone had issues like this with Google Web Fonts?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

DrSunshine posted:

Thanks! That's very enlightening. One more question -- you end the function with lol_improved(1); -- what does this do?

Calls it for the first time so it starts looking for images.

DrSunshine
Mar 23, 2009

Did I just say that out loud~~?!!!

Lumpy posted:

Calls it for the first time so it starts looking for images.

Ah, okay, I see! Well, I tried it out and it works just fine! I added a little bit of code to prune the broken image that it creates when it gets to the end of the loop. Thank you so much!! :neckbeard:

Now there's one more thing I'm doing. Every time someone clicks a link to a chapter, it creates a cookie and gives it a value equal to the number of the chapter (so, 1, 2, ...). To advance to the next chapter, I want there to be a button you can click on. So that the button "knows" which chapter to advance to, it takes the value stored in the cookie, adds 1 to it, and sends the new value back into "loadChapter". Then it creates a new cookie with the new value.

At least, that's the intention. For some bizarre reason, the nextButton function gives nextChapter a value of 11 instead of 2, if I start from chapter 1. This is baffling to me, because the "prevButton" function works just fine -- if I start from chapter 2 and go back, it loads chapter 1.

code:
function nextButton(){
	
	//get the cookie
	var chapter = document.cookie;
	console.log("current cookie value: " + chapter);
	var nextChapter;
	
	//Clear docDisplay div
	var docDisplay = document.getElementById('docDisplay');
	document.getElementById('docDisplay').innerHTML = '';
	
	//Advance to next chapter
	nextChapter = chapter + 1;
	
	//Populate with images
	loadImages(nextChapter, i);
	
	//make a cookie with value of nextChapter
	document.cookie = nextChapter;
	console.log("current cookie value: " + document.cookie);
}


//Click on the button to go to previous chapter
function prevButton(){
	
	//get the cookie
	var chapter = document.cookie;
	console.log("current cookie value: " + document.cookie);
	var prevChapter;
	
	//Clear docDisplay div
	var docDisplay = document.getElementById('docDisplay');
	document.getElementById('docDisplay').innerHTML = '';
	
	//Go to previous chapter
	prevChapter = chapter - 1;
	
	//Populate with images
	loadImages(prevChapter, i);
	
	//make a cookie with current chapter
	document.cookie = prevChapter;
	console.log("current cookie value: " + document.cookie);
}

DrSunshine fucked around with this message at 02:02 on Mar 6, 2015

Data Graham
Dec 28, 2009

📈📊🍪😋



Try var chapter = parseInt(document.cookie);

DrSunshine
Mar 23, 2009

Did I just say that out loud~~?!!!

Data Graham posted:

Try var chapter = parseInt(document.cookie);

Ahh, that fixed it perfectly!! Thank you so much!! I knew it had to be something of that nature, but since I'm kind of teaching myself all this as I go along, I sort of lacked the "vocabulary" to do what I needed to.

Data Graham
Dec 28, 2009

📈📊🍪😋



Yup. You'll get a feel naturally over time for the esoteric little idiosyncracies that need to be massaged in JavaScript (as with any language). This one, as you can probably figure, stems from it being a not-strongly-typed language, meaning you don't tell it whether a variable is a string or an integer or whatever, so it has to sort of just guess based on context. It will always treat cookie values as strings, and when you're dealing with strings, 1 + 1 = 11 :v:

As to why it worked when going to the previous page, I can't say, but I would wager something along the lines of https://www.destroyallsoftware.com/talks/wat

For your next trick you might want to try to combine those two functions, since you'll notice you're basically duplicating the exact same thing twice, with only one line of difference between them. DRY = Don't Repeat Yourself. Make it an incrementPage(num) or something, and use num instead of 1. That way you can pass in 1, -1, or any number you want depending on how you set up your controls.

Incidentally I just want to say that your onload/onerror approach is a pretty neat trick. Very elegant/improvisational. I've been in DB land so long I'm pretty sure I wouldn't have come up with that in a million years. :haw:

DrSunshine
Mar 23, 2009

Did I just say that out loud~~?!!!

Data Graham posted:

Yup. You'll get a feel naturally over time for the esoteric little idiosyncracies that need to be massaged in JavaScript (as with any language). This one, as you can probably figure, stems from it being a not-strongly-typed language, meaning you don't tell it whether a variable is a string or an integer or whatever, so it has to sort of just guess based on context. It will always treat cookie values as strings, and when you're dealing with strings, 1 + 1 = 11 :v:

As to why it worked when going to the previous page, I can't say, but I would wager something along the lines of https://www.destroyallsoftware.com/talks/wat

For your next trick you might want to try to combine those two functions, since you'll notice you're basically duplicating the exact same thing twice, with only one line of difference between them. DRY = Don't Repeat Yourself. Make it an incrementPage(num) or something, and use num instead of 1. That way you can pass in 1, -1, or any number you want depending on how you set up your controls.


Oh wow, that's true! I kept thinking that they had to be separate, since I have two separate buttons, so I didn't think at all that I could just use the same function and just pass -1 or 1 into it depending on which <div> was clicked! Oy! That's a clumsy beginner mistake right there, haha!

quote:

Incidentally I just want to say that your onload/onerror approach is a pretty neat trick. Very elegant/improvisational. I've been in DB land so long I'm pretty sure I wouldn't have come up with that in a million years. :haw:

Thanks so much! Coming from someone with, like, decades more experience in coding than I have, that's a huge compliment.

ItBurns
Jul 24, 2007
I'm maintaining a handful of sites on our company intranet, and one thing I've noticed is that people aren't always receiving new versions of pages when I update them. Is there such a thing as best practice for getting new builds out in this situation? Lately I've taken to changing the file names for linked css/js/json resources with new builds, but I've run into problems where the html (e.g. company.com/intranet/index.html) isn't even being refreshed. Our web server is probably a stock-ish IIS (nobody seems to own it) so anything server-side is probably a non-starter anyways.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

ItBurns posted:

I'm maintaining a handful of sites on our company intranet, and one thing I've noticed is that people aren't always receiving new versions of pages when I update them. Is there such a thing as best practice for getting new builds out in this situation? Lately I've taken to changing the file names for linked css/js/json resources with new builds, but I've run into problems where the html (e.g. company.com/intranet/index.html) isn't even being refreshed. Our web server is probably a stock-ish IIS (nobody seems to own it) so anything server-side is probably a non-starter anyways.

I believe that most people get around this by putting a unique query string on the end of the resource, e.g. main.css?v101 . Not sure how viable that is in your environment though.

Loezi
Dec 18, 2012

Never buy the cheap stuff

Scaramouche posted:

I believe that most people get around this by putting a unique query string on the end of the resource, e.g. main.css?v101 . Not sure how viable that is in your environment though.

That was the way it was done previously, it's no longer recommended because it was found out that using query strings causes cache misses for 5 - 25% of the users. Also, to quote the reasoning for Rails moving from query strings to file-name suffixes: "Query strings in particular do not work at all with some CDNs for cache invalidation."

You should probably just append the unique string before the file extension. So instead if main.css?v101 do main-v101.css or something.

v1nce
Sep 19, 2004

Plant your brassicas in may and cover them in mulch.
I agree with Loezi. If you're not sure of your or anyone elses setup, just have the filename contain the version, and update that when you want to increment.
If you can't do it properly, just do it the most basic way. Caching/invalidation is hard.

Data Graham
Dec 28, 2009

📈📊🍪😋



Yeah, it's funny, if you go digging through the code of high-profile publicly-facing sites, you find interesting stuff like

code:
<head><script src="//cdn.optimizely.com/js/785980306.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta property="fb:app_id" content="164636753621449"/>
<link rel="canonical" href="http://www.foobar.com/" />
<link rel="stylesheet" href="http://files.foobar.com/static/site/css/screen.e1e62cb9188da5a2a975c1be01166fa4_gz.css">
<link rel="stylesheet" href="http://files.foobar.com/static/site/css/tipsy.76d323f80f844b59fa7ad4e4e82e8cf5_gz.css">
<link rel="stylesheet" href="http://files.foobar.com/static/site/css/magnific-popup.31001bbf717ff68857a56812c578f4a5_gz.css"><style>
I suspect people doing this are using grunt or something similar to generate unique filenames for each build:

http://robandlauren.com/2013/08/14/busting-cache-with-grunt/

Loezi
Dec 18, 2012

Never buy the cheap stuff

Data Graham posted:

Yeah, it's funny, if you go digging through the code of high-profile publicly-facing sites, you find interesting stuff like

I suspect people doing this are using grunt or something similar to generate unique filenames for each build:

http://robandlauren.com/2013/08/14/busting-cache-with-grunt/

Those are most likely fingersprints (hashes) of the files that are recalculated every time the site is rebuilt/updated. That way if the file has the same contents, the postfix is the same no matter when the file was changed or created. This ensures you invalidate as few of the cached resources as possible.

A previously popular automated alternative is to use file timestamps but that has some drawbacks on multi-server enviroments and you end up invalidating caches if you first make change A and then undo it without checking out the original file before A was changed.

As for how to do it, some frameworks (Ruby on Rails) have a prepackaged asset pipeline that handles asset versioning, others (Django) have addons/packages that can handle it.

Data Graham
Dec 28, 2009

📈📊🍪😋



That's a neato idea.

Seems like in a better world, HTTP might work more like git or something—for each request for a cached file, the browser would send up the hash, and the server would make its 200/304 decision based on that.

But then I suppose if all browsers implemented date checking properly, we wouldn't have caching problems to begin with. :v:

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Data Graham posted:

That's a neato idea.

Seems like in a better world, HTTP might work more like git or something—for each request for a cached file, the browser would send up the hash, and the server would make its 200/304 decision based on that.

But then I suppose if all browsers implemented date checking properly, we wouldn't have caching problems to begin with. :v:
Pretty much. We have If-Modified-Since and the ability to respond to it, but if it never gets to the server what can you do.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe
Hey guys, am I opening myself up to anything if I use a Firebase with read/write rules set to False at the top most level, and then authenticate as an admin in a Python script that's intended to interact with the database? As in, is that a bad habit to get into? I'll eventually open it up for reads from Angular but for now it'll just be a means of storing and retrieving API keys for another service.

Loezi
Dec 18, 2012

Never buy the cheap stuff

Data Graham posted:

That's a neato idea.

Seems like in a better world, HTTP might work more like git or something—for each request for a cached file, the browser would send up the hash, and the server would make its 200/304 decision based on that.

But then I suppose if all browsers implemented date checking properly, we wouldn't have caching problems to begin with. :v:

This is a thing! :eng101:

It's called a HTTP E-Tag and works essentially like this:

code:
Client:   "Yo, gimme X"
Server:   "Here's X. Also take this ETag: 686897696a7c876b7e"
<time passes>
Client:   "Yo, you gave me X yesterday. Is it still valid? It came with this ETag: 686897696a7c876b7e"
Server:   "Just keep using the last one"
There are two variants of ETags: Strong and weak ones. Strong ones are supposed to change whenever the requested resource changes by even a byte and the weak ones are supposed to change when there's a "semantic change" in the resource. So weak ones allow you to essentially say "Yeah there were some small changes but they don't matter, just roll with the last one" to the client.

The actual mechanism is the server sending a header of the form ETag: "686897696a7c876b7e" when replying to a request. In the future, if the client sends a request that contains a header line of form If-None-Match: "686897696a7c876b7e". Now if the resource is unchanged, the server replies with 304 Not Modified and if a change has happened then it returns the new file and the new ETag. Weak ETags work just the same but have a prefix of W/, so a weak version of the above ETag would be W/"123456789".

EDIT: The main difference between ETags and the aforementioned fingerprinted file names is that ETags still require a round trip to the server and waiting for the 302 response. Cache invalidation using file names allows the server to say to the client "Here is the CSS file, keep it forever" and then the client doesn't even bother checking for a new version from the server. When we change the fingerprint in the file name the client no longer recognizes that file and requests it from the server.

So for semi-non-changing assets like images, CSS and JS fingerprinting is probably better, but for situations where you always need the round trip -- like an API or a HTML document -- ETags are better.

Loezi fucked around with this message at 20:14 on Mar 6, 2015

revmoo
May 25, 2006

#basta
Anybody have Firefox poo poo the bed on SSL? I have my FF set to clear all cookies, cache, everything on shutdown, and yet if I load up a fresh instance of FF and browse to a number of sites I get untrusted connection error. I've had other people verify with their copies of FF and it only happens with my copy.

Workaday Wizard
Oct 23, 2009

by Pragmatica

revmoo posted:

Anybody have Firefox poo poo the bed on SSL? I have my FF set to clear all cookies, cache, everything on shutdown, and yet if I load up a fresh instance of FF and browse to a number of sites I get untrusted connection error. I've had other people verify with their copies of FF and it only happens with my copy.

Is your system clock correct?

revmoo
May 25, 2006

#basta
Good idea, but yeah it's set right (time.apple.com)

BlueInkAlchemist
Apr 17, 2012

"He's also known as 'BlueInkAlchemist'."
"Who calls him that?"
"Himself, mostly."
Finally landed myself a lucrative web programming dayjob to support my habits, like trying to write for a living and playing games. My new boss is hot for me to get up to speed on PyroCMS.

Are any goons familiar with Pyro? The streams aspect seems really interesting, and I'm diving into it a bit more this weekend. Anything I should be aware of before I get deep into the code?

hayden.
Sep 11, 2007

here's a goat on a pig or something
Does anyone have a rule of thumb of a range of expected income per 1k page views for AdWords? I mean I know it can vary a ton, but any range at all would be helpful. Asking out of curiosity for my website where people upload save files for a video game if that helps at all.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

revmoo posted:

Anybody have Firefox poo poo the bed on SSL? I have my FF set to clear all cookies, cache, everything on shutdown, and yet if I load up a fresh instance of FF and browse to a number of sites I get untrusted connection error. I've had other people verify with their copies of FF and it only happens with my copy.

Do you have Fiddler running? This happens a lot and I always forget it's because I have Fiddler going.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

BlueInkAlchemist posted:

Finally landed myself a lucrative web programming dayjob to support my habits, like trying to write for a living and playing games. My new boss is hot for me to get up to speed on PyroCMS.

Are any goons familiar with Pyro? The streams aspect seems really interesting, and I'm diving into it a bit more this weekend. Anything I should be aware of before I get deep into the code?

No, but for a framework that touts 'Responsive Design' as one of its features, their site sure is awful looking on mobile.

ItBurns
Jul 24, 2007

Loezi posted:

That was the way it was done previously, it's no longer recommended because it was found out that using query strings causes cache misses for 5 - 25% of the users. Also, to quote the reasoning for Rails moving from query strings to file-name suffixes: "Query strings in particular do not work at all with some CDNs for cache invalidation."

You should probably just append the unique string before the file extension. So instead if main.css?v101 do main-v101.css or something.

Thanks for the info from everyone. I'm just going to stick with appending the date or something onto the file. It's not like I'm doing daily builds on it. All of the new stuff that I've made actually has something more like...

Data Graham posted:

Yeah, it's funny, if you go digging through the code of high-profile publicly-facing sites, you find interesting stuff like

code:
<head><script src="//cdn.optimizely.com/js/785980306.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta property="fb:app_id" content="164636753621449"/>
<link rel="canonical" href="http://www.foobar.com/" />
<link rel="stylesheet" href="http://files.foobar.com/static/site/css/screen.e1e62cb9188da5a2a975c1be01166fa4_gz.css">
<link rel="stylesheet" href="http://files.foobar.com/static/site/css/tipsy.76d323f80f844b59fa7ad4e4e82e8cf5_gz.css">
<link rel="stylesheet" href="http://files.foobar.com/static/site/css/magnific-popup.31001bbf717ff68857a56812c578f4a5_gz.css"><style>
I suspect people doing this are using grunt or something similar to generate unique filenames for each build:

http://robandlauren.com/2013/08/14/busting-cache-with-grunt/

...this because I'm using grunt and those pages don't seem to have the same issues. Good to know I'm not overlooking something obvious.

Adbot
ADBOT LOVES YOU

kedo
Nov 27, 2007

BlueInkAlchemist posted:

Finally landed myself a lucrative web programming dayjob to support my habits, like trying to write for a living and playing games. My new boss is hot for me to get up to speed on PyroCMS.

Are any goons familiar with Pyro? The streams aspect seems really interesting, and I'm diving into it a bit more this weekend. Anything I should be aware of before I get deep into the code?

It's probably going to suck and you should tell him you want to use WordPress or Drupal.

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