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
Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
edited out

Hammerite fucked around with this message at 20:22 on Jan 7, 2009

Adbot
ADBOT LOVES YOU

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I know that many languages have first-class functions. What scripting languages have first-class types, in the sense that a function can return a type? So for example a function can return the type integer. (which is not nearly the same thing as returning an integer.)

Example: suppose a scripting language allows you to use decimal types to carry out calculations to arbitrary (but obviously, finite) numbers of decimal places. So you might have a function decimal() taking one argument that returns a type representing decimals accurate to the number of decimal places represented by the argument. Then if I wanted to calculate the square root of 2 correct to 50 decimal places, I might write something like

decimal(50)::sqrt(2);

in which :: is meant to be the static member operator, with sqrt() being a static method of the type returned by decimal().

Are there any scripting languages that exhibit behaviour resembling what I describe? Or am I describing something that cannot work?

(I say scripting language because I have in mind that this should be something that works through dynamic typing, which is something I perceive to be characteristic of scripting languages.)

Hammerite fucked around with this message at 11:11 on Aug 9, 2011

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

tef posted:

Python

OK, further question. A brief search shows that in Python, when you want to declare a function f you do so by writing

code:
def f(x):
    function body
(or something of the sort). This is similar to how in other languages one writes

code:
function f (x) {
    function body
}
This seems to betray a failure to truly treat functions as ordinary values just like any other type of values. If they were really so, you should have to write

code:
f = function (x) {
    function body
}
instead. Perhaps you can indeed do something like this in Python, I do not know. But my question is, why is the def version valid? It ought not to be.

A similar consideration applies to declaring classes. Instead of writing

code:
class c:
    class body
it ought only to be valid to write something like

code:
c = class {
    class body
}

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

tef posted:

MY CONSISTENCY

This, but unironically.

tef posted:

python eschews anonymous definitions -- ask yourself how you would do this in a language without braces.

I can't answer that question other than by noting that it can be interpreted as an argument in favour of braces.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

TasteMyHouse posted:

A foolish consistency is the hobgoblin of little minds

What this quote really says (to me, at least) is that if you have a good reason to be inconsistent then you should go ahead and be inconsistent. It seems to me that it's your job to show that there's good reason for inconsistency here. Or to put it another way, it's up to you to show that the consistency I am arguing for is indeed foolish. :)

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Perhaps I shall learn Lisp. It sounds enlightening.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

rolleyes posted:

I refuse to get involved in cryptic messages when the author can't even manage to spell 'potato'.

it looks like it is a cropped screenshot in which case the word may have been "potatoes"?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I know that in languages with strict typing, you typically have to declare the types of all the parameters to a function, as well as the type of the return value. Like in C you might have

int myfunction (int a, float b);

(I may have made a syntax error somewhere, it's not crucial to the post.) Aside from maybe being necessary for low-level languages to work properly, this has the nice property that you've made a declaration to some extent of what properties you want your function's arguments to satisfy, which makes your job easier. In some dynamic languages (PHP I'm looking at you) you cannot declare that you want an argument to be an integer, so you either have to do some kind of check in the function, or throw your hands up and say gently caress it, I'm just going to assume whenever this function gets called it is by somebody who isn't retarded. Maybe that isn't so bad but it is kind of unsatisfying.

But it seems like the capability of saying what type you want the argument to be is not going far enough. I should be able to say that I want the argument to be not just an integer, but an odd integer greater than 10, or that I want the return value not just to be a string, but that I want it to be a string precisely 8 characters in length.

Seems to me the easiest way to achieve that is by saying: when you define your function, for each argument you should supply not a type, but a predicate that you want to return true or else the function has been called incorrectly and an error should occur. For convenience, names of types should also be usable as predicates that take a single argument and return true or false according as the argument is of the appropriate type. So something like the following should be doable (syntax is made up; assume that nonnegativeInteger is a predicate that already exists and behaves in the obvious way):

code:
global predicateGreaterThan := function (n satisfying number) {
    return function (x satisfying number) capturing n {
        return x > n;
    };
};

global odd := function (x satisfying integer) {
    return x % 2 = 1;
};

local oddIntegerGreaterThan10 := all(predicateGreaterThan(10), odd);

global stringOfLength := function (n satisfying nonnegativeInteger) {
    return function (s satisfying string) capturing n {
        return s.length = n;
    };
};

local stringOfLength8 := stringOfLength(8);

local myfunction := function (x satisfying oddIntegerGreaterThan10, s satisfying string)
                    return value satisfying stringOfLength8 {
    ...
};
Here "all" is a function that takes an arbitrary number of predicates as arguments, and returns a predicate that returns true if and only if all of the original predicates return true on its argument.

Tell me languages that behave in a similar way to what I just described.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

baquerd posted:

code:
<form>
  <input type="button" value="Prompt for IP" onClick="javascript:getInfoForIP()">
  <br>  
  <textarea id="siteInfo" rows="5" cols="50"></textarea>
</form>

<script type="text/javascript"><!--

var siteData = new Array();
siteData["192.168.0.1"] = "This site has 10 employees and funding of $500k a year";
siteData["192.168.0.2"] = "This site has 5 employees and funding of $1500k a year";
siteData["192.168.0.3"] = "This site has 2 employees and funding of $60k a year";

function getInfoForIP() {
  if (confirm("Does the user have an IP?")) {
    var userIP = prompt("Enter the IP:", "");
    document.getElementById("siteInfo").value = siteData[userIP];
  }
}

--></script>

Just a quick note on this: The correct way to do associative arrays in JavaScript is using objects, not arrays. Reference

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

GrumpyDoctor posted:

I have a collection that includes points, lines, and planes (in 3-dimensional space). If I want to do neighbor queries on points (nearest neighbor, nearest k neighbors, whatever) I can use a k-d tree. Is there any technique for if I want to include the lines and the planes in the queries as well? i.e. "find me all the points, lines, and planes within an epsilon of this given point"

If you have a point p and a line l then there is a unique point p2 on l that is closest to p. You could just calculate the distance between p and p2, which is then the same as the distance between p and l. The analogous statement also holds for a point and a plane.

In the case where you have a point p and a plane q you calculate the normal l to q passing through p; the point p2 is the intersection of l with q.

In the case where you have a point p and a line l, you express the line in terms of a parameter (t, say), and then express the square-distance s from p to a point on l in terms of t. Then you find the minimum value of ds/dt and calculate its square root to get the distance from p to l (you can also calculate the point p2 at this point, but you don't actually need to).

If this is too inefficient an approach or otherwise impractical then don't mind me, I'm a programming novice.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Mr.Hotkeys posted:

Create every possible square where each row contains one of each number and then run over the results and cull out the invalid ones? I'm sure someone'll come in with some beautiful way to do it but honestly that just sounds like the easiest way to me, though I don't know if that's C or C++.

Would probably use a huge amount of memory even for not very large n.

Two observations:

1) You can fix the first row of the square, find all magic squares (let's say there are k of them) with that first row, and then generate the remaining squares by applying permutations of the integers 0 through n - 1. (This gives you n! × k squares in total.)

2) To generate those magic squares in the first place, you could take the approach of generating a tree of height n by filling in rows one by one, filtering out partial squares that have already failed to satisfy the requirement of having each number appear at most once in each column. Here is a partial illustration in the case n = 4:

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

shrughes posted:

FYI These are not magic squares.

Oh yeah, I don't know what happened there. I was talking about Latin squares but saying "magic squares".

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Been doing some work in Maple the last few days. Maple has a thing I haven't seen elsewhere, where you can define "sequences" (comma-separated lists of Maple values) and assign a sequence to a variable. So you can write

code:
x := 6, 7, 8, 9;
f(x);
and it has the same effect as writing

code:
f(6, 7, 8, 9);
because in passing x in to f, you actually passed 4 variables, because x is a sequence of 4 values.

Is there a name for this kind of behaviour?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
The way you do certain things in Maple is... idiosyncratic. It is entertaining from time to time.

As well as sequences (comma-separated lists of values) you also have lists, which are sequences encased in a set of square brackets; and sets, which are sequences encased in a set of braces. So you can have

code:
x := 1, 2, 3;
y := [4, 5, 6];
z := {7, 8, 9};
and x is a sequence, y is a list and z is a set. You can go from a list or set to the sequence contained within using the "op" function (short for "operands", I think; it splits expressions of various sorts into their component parts).

There is no built-in function to append an element to a list. You can do that as follows:

code:
x := [1, 2, 3];
y := [op(x), 4];
z := [0, op(x)];
and then y will be the list [1, 2, 3, 4] and z will be the list [0, 1, 2, 3].

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
The only web scripting language I know is PHP. PHP has a great many flaws, and I should like to learn another web scripting language. Probably Python or Ruby. There is one thing that keeps me from getting comfortable with the way other languages do things, though. When I invoke a PHP script I know exactly what is happening. PHP starts at the top of the script and executes the contents, in order, until it reaches the end of the script. I have seen forums poster tef refer to this as "CGI-style" scripting (or maybe I have misunderstood terms, but that is how I perceived it).

This does not seem to be the way that other web scripting languages work, perhaps with the exception of Perl. They seem to typically involve installing things (you need to install such-and-such a "gem"...), declaring things (tell some program to start listening to requests or dealing with them using a specific workflow), configuring toolsets (for example, a templating engine) that are to be pieced together to form the backbone of the application, choosing the way something should communicate with a web server (python.org's introductory page on "how to use Python in the web" is mostly a load of incomprehensible bullshit about different methods for hooking Python code up to a webserver - what if I just want to write a script?), starting and stopping processes (why can't a request to a given script just invoke the necessary interpreter which then does its thing, like in PHP?), who knows what else.

Please offer tips on how I can become more comfortable with these other web scripting languages' ways of approaching scripting.

nb. I have shared web hosting, but I do not have shell access or any of that good stuff. I could spring for a cheap VPS, but it seems like it should not be necessary to do that just in order to do some tinkering.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Look Around You posted:

Most modern web frameworks use a Model-View-Controller (MVC) pattern. The three parts are as follows: a "Model", which contains the representation of the data and the rules for manipulating it, a "View" for displaying it to the user, and a "Controller" that decides what needs to be done and how to do it, basically mediating between the Model and the VIew.

So you'll have a Controller get the request (maybe "yoursite.com/blog/1") and decide what to do with it, usually by calling a function that you "route" that request to. That function (still part of the controller) will then handle getting the data from the model, and pass it to the view (which is usually a special template file, typically html with some code in it to do some display logic).

Here is a good beginners tutorial for the Ruby on Rails (which is obviously written in Ruby)

here is an overview and a tutorial for the Django framework, which is written in Python.

Thanks. In your estimation, how much extra hassle would it be to learn django using only shared hosting with no command line access, as opposed to getting a cheap VPS?

edit: Also if I should get out and ask questions in the dedicated language megathreads instead, tell me.

Hammerite fucked around with this message at 12:32 on Apr 10, 2012

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

gwar3k1 posted:

Thanks, I added a wait function (from a google hit) and changed my do a bit, but the performance is poo poo.

code:
  function runSequence(){
   ...
      do {
        updateClock(circleFgColor[circleColor],current,sequence[i]);		  
        current = current+1;
        wait(1000);
        //alert("a");
      } while (current<=sequence[i]);
    }
  }
	  
  function wait(msecs){
    var start = new Date().getTime();
    var cur = start
    while(cur - start < msecs){
      cur = new Date().getTime();
    } 
  }
I'm giving up because this is supposed to be a fun distraction, but I am curious as to what the correct way to loop times events (animation, or otherwise).

I am not sure you understand how setting timeouts works. If you want to set something up to happen in 5 seconds, say, then you create a timeout using setTimeout (specifying a time of 5000 milliseconds) and then you allow your function (the function in which you used setTimeout) to run to completion. When the timeout has run its course, your function will get called, spontaneously, by the JavaScript engine.

If you want a nice-looking, smooth animation on the other hand, I think it's easiest to use what jQuery offers you.

I made this thing last year for an event I was involved in, it is more complex than is needed for an example but you might find it interesting to look at.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

gwar3k1 posted:

Thanks! So are you effectively queuing up animation functions with doTimeout and incrementing animationStep? The timeoutHandler executes the necessary code after each timeout delay, but the original code from the button press has already completed.

Yes. Depending on what stage in the animation the document is in. It's a while since I wrote it, but basically timeoutHandler() is the function that controls the state of the document and makes sure that things happen "in the right order".

I just realised (and I don't know why I didn't realise it before, I'm honestly not trying to show off) that I actually have a much simpler example of the use of timeouts, that would have been much more appropriate to link you to: (albeit "intervals" rather than "timeouts")

http://orderofthehammer.com/redirect.js

This allows the creation of a page that redirects the user after a countdown. Every second the counter in the page body text and the counter in the page title are decremented, and when they reach zero a thing happens. redirect_begin() is supposed to be called once the page loads. See how the last thing that happens is that it calls setInterval(), and then it gives up control to the JavaScript engine. The JavaScript engine does its job and calls redirect_countdown() every second afterwards, until it is told to stop by code in the conditional block within redirect_countdown().

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
What is a good strategy for creating tests for pieces of software that you have written? I created a script to test out the functionality of a small piece of software I wrote for my own use. In the process of writing and running the tests I actually found and fixed a few bugs that I did not know were in the code, as well as making one or two tweaks to functionality. This of course is quite gratifying, because it means that the code is closer to being free of bugs and that the time spent doing the testing has paid off, but the tests (now all passing) are just what I thought up, just a few experiments that seek to test that various possible eventualities are handled correctly. What if there are still loads of bugs I didn't think of?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

yaoi prophet posted:

If you just want to test a single function, fuzz testing can be good. Like, if you want to test a sort() function, generate random lists, run them through sort(), and verify that they're sorted.

It's a class. Although I made it for my own use, I uploaded it here.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

LittleBob posted:

I'm probably being retarded, but how can I rename a set of files, keeping just the first three characters and deleting everything else?

My attempts using cut and sed and regex all result in failure :downs:

I don't know how to answer your question. But you have considered the possibility that the truncated names will include duplicates, right? For example two files might be named readme.txt and really-big-wieners.jpg. You might need to be more clear what you want to happen if a duplicate filename arises (do you want to destructively overwrite the old file, or...?)

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

MEAT TREAT posted:

:bang:
There should never be more than 1 unique entry in your table if that's the intended logic. Two users can submit the form at the same time with the same username, and the select query will return that there are no users with that username to both of them, then proceed to insert them.

Validations are good but it's not enough as you are open to race conditions like the one I just pointed out. You still need to enforce that the database only inserts unique entries by setting a Unique constraint on the columns.
code:
ALTER TABLE users ADD CONSTRAINT unique_username UNIQUE (username)
ALTER TABLE users ADD CONSTRAINT unique_email UNIQUE (email)

Yes, get the database to help you where it can. Use uniqueness constraints. Use foreign keys. Use transactions. If you are using MySQL, put it in traditional mode.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Shaocaholica posted:

So someone at work asked me if saving a jpeg over and over will introduce compounding compression artifacts and I said 'yes' without really thinking. I then decided to do a test where I open an image, save out at 50% jpeg quality, reopen the new image and save out a new copy with 50% quality so on and so forth for a few hundred iterations. I played the image sequence in motion and after the initial pop in quality from the original image to the first 50% quality image the artifacting didn't change at all for the hundreds of frames that followed. Is this normal for jpeg algorithms?

Wiki says: "JPEG is also not well suited to files that will undergo multiple edits, as some image quality will usually be lost each time the image is decompressed and recompressed, particularly if the image is cropped or shifted, or if encoding parameters are changed – see digital generation loss for details. To avoid this..."

Are you sure your procedure "decompressed and then recompressed" the JPEG after the first pass (in which you reduced the quality)?

I am pretty sure that if you make actual changes to a JPEG, re-saving it as JPEG each time, the quality will get progressively worse.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Where is a comment permitted in an HTML page? Can I have one before <html>? After </html>?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Suppose I want to build a structure that looks like this: The top-level object is a list of objects, each of which can be either an atomic object or itself a list. The structure is meant to be operated upon by "workers" which can move backwards and forwards along lists, climb upwards (if they are not at the top level) and climb downwards (if the object they are positioned at is a sublist). If they climb upwards, they will then be pointing at the same list item that they were pointing at before they descended. Workers can insert elements in the list. Multiple workers may be operating on the same list.

Each list has no reference to its parent element; so a particular list can be inserted by value or by reference in multiple locations (and manipulating the list in one of these locations causes the changes to be made everywhere else that a reference has been placed to the same list). Workers can create workers "constrained" to act within the current list (so the newly produced worker regards the current level as being the top level, whereas it may not be the top level as far as the original worker was concerned).

Inserting a list item in such a way as to form a cycle might or might not be allowed. Or maybe when a sublist is inserted it should be marked as "unsafe" until a check has been made for cycles, or something. If deletion of list items is allowed, then deleting sublists might be problematic, because another worker might be working inside that sublist, and then it is not clear what should happen.

Does a structure like this have a name?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
In the current version of my web app, users can select a set of pronouns they would like to be referred to by. They can elect to be referred to by "he", "she", or "it". I'm considering whether to maintain this in a future iteration of the app. I was considering adding the option of being referred to by "they". But I also allow translation into other languages, and other languages might have totally different sets of pronouns and so it might be impossible to translate the connotations behind one or more sets of pronouns, resulting in inferior translation. I'm not sure whether to just drop the option to select a set of pronouns entirely, and have everybody just referred to as "they" where necessary. I guess this is what most people would do? Obviously this is an aesthetic consideration and difficult to justify spending much time on.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

rjmccall posted:

Localizing gender is a pain. So is not enforcing cisnormativity. Go with gender-neutral or be prepared for a long tail of work.

I was considering in the choice selection, making the connotations of each set explicit. as in

code:
                |  Connotation       |  English                                |  Translated form
----------------+--------------------+-----------------------------------------+-----------------
[radio button]  |  Gender-Neutral    |  they, them, themselves, their, theirs  |  (translation)
[radio button]  |  Masculine         |  he, him, himself, his, his             |  (translation)
[radio button]  |  Feminine          |  she, her, herself, her, hers           |  (translation)
[radio button]  |  Inanimate object  |  it, it, itself, its, its               |  (translation)
default being the first option. The "English" column is not translated (apart from the column header), the other columns are. That way the intended use case is clear to anyone reading in any supported language, even if (say) two possible choices are implemented as identical sets of pronouns in their language.

The way I see it it's a nice thing to do to let people select the way they would like to be referred to, within reason. I don't care about cisnomativity or any stupid poo poo like that, if anyone bothers me with nonsense I'm happy to tell them to go screw themselves.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

yaoi prophet posted:

  • That's third-person, as is "She did $thing." First-person would be "I did $thing" which obviously makes no sense.
  • So what do you do for cases like 'John Smith updated John Smith's profile. Reconnect with John Smith today!'? That looks ridiculous if you keep using their name each time.

I'd recommend sticking with masculine, feminine, and neutral/unspecified if you can swing it in whatever set of languages you support it. If you don't want to deal with making your users think about pronouns, just have them set their gender as male/female/unspecified and pick pronouns based on that.

I figure asking them "what sex/what gender are you?" would be a far worse can of worms than merely asking them how they would like to be referred to. Not to mention people are more likely (I would assume) to see asking them "are you male or female" as a request for irrelevant information and so impertinent.

Don't get me wrong, I do see that some languages might have arbitrarily different pronoun conventions than European languages. For languages where the "them, he, she, it" model is insufficient, it can fall back to use of gender-neutral text everywhere.

That has the problem that users using those languages might not see the need to provide information that doesn't apply to how they view the website anyhow. So it should default to the "they" option.

At the end of the day it is a primarily English-language web app by necessity because I am running it and I am English-speaking. Various issues might arise when attempt to facilitate translation, I'm not convinced that that's a reason to avoid offering features. When a given feature just isn't compatible with a certain language, shouldn't the thing "gracefully degrade"? That's a popular notion iirc.

But all this said, I'm not really convinced it isn't all too much work to be worth it.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

rolleyes posted:

Speaking as someone working for a company which offers our UIs in multiple languages (including non-latin ones) you really don't want to get into this if you don't have the resources to do a good job of it. We send our text to external translation companies and even they don't always get it exactly right, especially when going to logographic languages like Kanji which can be extremely subjective and context sensitive.

If you really are going to do this then the hard and fast rule you must stick to is "thou shalt use complete sentences only." Seriously, attempting to translate sentence fragments raises the error rate exponentially and sometimes is literally impossible to achieve because in another language part of the second fragment might need to be in the first fragment.

What I'm getting at is that some people might think you could get away with something like this to save translation resources:
Fragment 1 with replaceable pronoun: [<She> last updated] (can be reused for multiple types of update)
Fragment 2 with replaceable pronoun: [<her> account on:] <date>

That doesn't work for a variety of reasons: pronoun structure differs in various languages (i.e. you might not just be able to replace the pronoun as it can depend on words around it), sentence order differs in various languages (i.e. there's no guarantee that 'she' and 'her' would remain in the same place relative to the fragmentation), and just about every western language other than English has some situations where parts of the sentence structure and/or actual words change depending on the gender context.

The only really safe way to achieve that translation is simply:
"She last updated her account on:" <date>
"He last updated his account on:" <date>
"They last updated their account on:" <date>
"It last updated its account on:" <date>

And even that might not work as in some contexts the location of the date might have to move.


In short, while it's great and helpful to your users to want to offer localisation it's also a gigantic :can: which leads to you maintaining a huge database of every drat string in your application multiplied the number of pronouns you want to support multiplied by however many languages you want to support. We keep all of our application text gender neutral for exactly this reason.

My current implementation does take a "whole sentence" approach as you suggest. Does it ever work to write something like:

":subject-pronoun: updated :possessive-pronoun: account on:"

I am aware, before you say anything, that in many languages a possessive pronoun (say) has to agree with the noun. So there might be different pronouns for masculine, feminine and neuter nouns and they might also vary according to whether the noun is pluralised. So in some language it might look more like

":subject-pronoun: updated :possessive-pronoun-masculine-singular: account on:"

On the other hand, if a language isn't supported to that extent because it's just so alien OMG then it might end up as a sentence with no :...: placeholders at all, because there are no parameters to change.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Well, it's been useful to explore the idea. I think I've heard enough to convince me to drop the feature and use uniformly gender-neutral phrasing for now. It's not like I couldn't add the feature in at a future date, defaulting to "they" for users already existing at that time.

Incidentally, has there ever been a thread in CoC regarding internationalisation/localisation topics?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
When you have a website that requires login with username and password, what's the correct way to defeat repeated attempts to log in to an account by trying different passwords?

You could lock a user's account for a fixed amount of time when a certain number of failed attempts have been made to log in - say when 3 failed attempts have been made within 15 minutes. But if you do this then one user could grief another by getting them locked out of their account.

Alternatively, you could lock out users from a particular IP address from logging in if a certain number of failed attempts are made from that IP address. But a knowledgeable user can acquire a different IP address and carry on, so this wouldn't stop an attacker, would it? Or am I mistaken in thinking that users can rapidly change IP addresses?

I guess that if several attempts were made to log in to a particular account from IP addresses not previously associated with that account, you could lock it down except for allowing logins from the IP addresses that have been used to successfully log in in the past. But some users might have frequently changing IP addresses through no fault of their own and then they would be out of luck.

How do sites generally deal with this?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Suppose you are creating a web application and you want users to be able to create accounts and choose usernames for them. You don't want to restrict the characters they can use without good reason, so you intend to allow any Unicode character unless there is a good reason not to allow it. What characters do you disallow, and how would you code a function to check whether a username is acceptable or not?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

nielsm posted:

Go read a bit about Unicode normalisation forms, it's very relevant for things that have to not just be displayed but also compared and searched against.
Alternatively, have plain ASCII usernames and then display names in addition to that.

pseudorandom name posted:

Also Unicode Character Classes, to filter out such things as U+1F4A9 PILE OF POO.

Thanks, I find learning about Unicode to be actually very interesting, but it tends to seem very complex. As far as I'm understanding it you would probably want to make sure the user name was in NFC and then check that all the characters code points in it were in an acceptable General_Category? For example, you would prohibit code points with the General_Category Cn (Unassigned), Co (Private Use), Cc (Control), and others besides. Are there other things to consider when validating a name, or any gotchas?

I see that there is also the option to be more "aggressive" about normalizing Unicode text by using NFKC, but I'm not sure when you might do that. I guess maybe you would use it to compare strings, but you would not necessarily store a string in NFKC, since you lose information by doing so?

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Zombywuf posted:

http://www.regular-expressions.info/unicode.html will probably help. You probably want L, M, Zs and P (or maybe a subset). Normalisation I would leave up to whatever library I'm using to compare strings. Which I would then moan about if it didn't work.

Would you say it would be reasonable to restrict to L, M, N, P, Zs and possibly some of S (for special snowflakes who enjoy having, erm, snowflakes in their name) but to apply additional rules, e.g.

- remove Zs characters appearing at the start and end of the name (doesn't make sense for names to start or end with whitespace)
- disallow M characters from appearing at the start of the name
- require a minimum number of non-M, non-Zs characters

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Zombywuf posted:

Well, it all depends on how far you're willing to bend to special snowflakes. There are times I've been tempted to change my name to something that has no valid normal form in unicode as a big gently caress you to the world. Trimming (and normalising) whitespace and disallowing combining chars where they don't belong is reasonable, however if you're allowing symbols you might as well allow as much punctuation as they want. I guess it depends on what the use case is if you want allow Zalgo usernames.

Could you point me to an example or examples of Unicode strings that do not possess a normalisation form? What is the result of applying the normalisation algorithms to strings like that? Is there a collection anywhere of pathological examples of Unicode text?

I hadn't considered the idea of letting users have separate login and display names (potentially with different restrictions applied). I guess that has its advantages and disadvantages.

It also reached my attention that there are some category C characters that there might be reason to allow, such as ZERO WIDTH NON-JOINER

Goat Bastard posted:

The question I always ask myself when defining validation requirements is "what real problem am I trying to solve with this validation?".

If there is a genuine (observed) problem with users entering junk data, or if certain data will break the system in some way then the validation should be designed to prevent this problem and only this problem. Otherwise what the benefit of preventing the user from entering " " or whatever as a name? If they're actively trying to enter junk data then they can enter "x" just as easily, and you may inadvertently blacklist some valid name.

Edit: just noticed this is for user names, not person names, but I'll leave it here as the point remains true. If the person wants to log in as " " is there a valid business reason (eg the name may need to appear on a printed report) for stopping them from doing it? These are the only reasons I would consider preventing certain characters/patterns.

Although this is very reasonable and sensible advice, I am paying such inordinate attention to this in part because it is an opportunity for me to improve my understanding of Unicode and related topics.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

hayden. posted:

Not sure if this is the best place for this, but does anyone have experience doing programming type jobs on Elance? I've been looking and applying to a few jobs for a few days now but it seems unlikely that I'll ever get hired since I don't have any work history on the site. Every listing also has about a dozen applicants from India or whatever and I have no idea if I could ever compete with them on a price basis.

There's a recent thread about ELance and similar sites. It's partly ranting and partly advice iirc, you might find it interesting. :)

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Huragok posted:

Which one of you bought this banner ad:



Unless they're yours, it's pretty drat mysogynistic.

"Come blog about apps and dev poo poo, my lord"

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Jose Cuervo posted:

I am not sure if I can achieve what I want, so hopefully you all will be able to tell me if what I want to do is impossible.

I have 4 different papers that I am writing that are each located in a separate folder. Each paper has it's own local plain text bib file with the citation information of the citations needed for that paper. The citation information is stored in the BibTeX format. A number of the citations overlap - i.e., the citation is used in more than one paper.

The two questions are:
1. Is it possible to write some code/script so that I would have one master plain text bib file with all the citations, and whenever I made a change to a citation, I could run the code/script so that the citation information gets updated in each local paper's plain text bib file?

2. Can someone with limited coding ability (me) write this code given a plan of how to do it?

I have been doing the updating manually, but sometimes I do not update everything, or I misspell something and it is getting to be very aggravating.

Yes, that is something that you could do reasonably straightforwardly with the scripting language of your choice. Do you have any experience using a scripting language like Python, Perl, Lua, etc etc.?

I do not know how others would approach this (and I do not know anything about bibtex), but here is what I might do, assuming you do not want to go to the trouble of involving a relational database:

- Make a master citations file with all of the citations in it, together with identifying names (for your use). You could do a citation on every line of the file, with name first then citation text separated by a tab. Or you could do it innumerable other ways.
- If your papers are spread across a number of directories, then make another file that lists all of the directories to be searched and updated.
- For each paper, make a file called something like "papername.mybib" that just has a list of the citations you want, identified by the name you used in the master citation file.
- Now write your script. The script should read from the two master files. From the first one it builds up a list of identifiers and the citation text for each one. From the second one it reads a list of directories to search through. It goes through each directory in turn looking for .mybib files. For each one, it generates a .bib file.

When reading the first master file, the script should be prepared to encounter blank lines and lines that are "comments" (say, lines starting with % or #), so that you can lay it out in a way that is pleasing and easy for you to read.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

stubblyhead posted:

When you use POST as a html form submission method, what does the submitted document look like? Say your html page is like

code:
<html>
<body>
<form  action="farts.php" method="post" target="hole">
     <input type=text name=beans>
     <input type="Submit" value="Toot"></br>
</form>
</body>
</html>
what actually gets posted to farts.php ?

Someone will doubtless answer in more detail and/or fix inaccuracies in this, but something like the following:

this assumes that the full URL to farts.php is your.subdomain.yoursite.com/path/to/farts.php, and that you entered "Some text about beans" in the text input, and submitted the form by clicking the submit button.

code:
POST /path/to/farts.php HTTP/1.1
Host: your.subdomain.yoursite.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 33

beans=Some%20text%20about%20beans
The first line specifies that the request is an HTTP 1.1 POST request and specifies the resource that is to receive the request. The next three lines are headers that tell the receiving resource some information about the request or the request body. The first one (Host) is used in routing the request in the case where multiple sites have the same IP address (e.g. in case of a shared web host) - it allows the web server to know which site the request is actually for. After the double newline is the actual request body. In this case it is URL-encoded form field data.

I am not sure whether a variable is sent for the submit button, because you didn't give it a name. I'm pretty sure that if you do give it a name, then it sends a variable for the submit button, and its value is the "value" attribute on the button (so in this case, "Toot")

Bear in mind that anyone can craft any HTTP request they like (or even craft a malformed request) and send it to your script, so don't rely on requests looking the way they are supposed to look, and also there might be all sorts of different headers like a user-agent header, "accept" headers, etc. etc.

Hammerite fucked around with this message at 23:31 on Aug 2, 2012

Adbot
ADBOT LOVES YOU

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

kedo posted:

I'm trying to code the front end of a website running on Apache Wicket and it is horrible. According to the developers I'm working with, every time edits are made to the various page templates the only way to see the edits is for the server to grab the files from FTP, stick them into the system somehow, and then restart or reload the theme or something... frankly I have no idea. Here's what the developer said:


Basically my problem is this: there's a minute of lag time between when I upload a change and when the change becomes visible. This makes it drat near impossible to code efficiently.

Anyone familiar with the system able to tell me if this is normal? I honestly cannot believe that there's no way for changes to be applied to the site instantly. Any ideas how I can work around this? What do I need to ask/tell this developer?

I think most people will tell you more or less bluntly that you shouldn't be making live changes to the website you're working on, full stop. Ideally you would have a test or "development" version of the site that is convenient for testing changes out, where you can iron out any problems with changes you make rather than unintentionally causing problems on the live site. This could be local to your development machine or more of a centralised thing. But I am guessing there's little reason to make it easy and convenient to change the production site when in principle that's the final step in making any changes; frequent changes to test edits are what the development version would be for.

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