Forums
April 28, 2024, 07:37 PM

Author Topic: web development / code challenge  (Read 1884 times)

0 Members and 1 Guest are viewing this topic.

Offline THeDoGG

web development / code challenge
« on: July 24, 2012, 09:05 PM »
Hello!
Is there any good developer around ?

I have a little challenge, there is something I'm trying to achieve and I'd like some advice for it.
Not looking for a final solution, but just some clues that could help me to go in the good way :)

It's about writing a function, and I've never written any :)

Here is my problem :
I've got a DB with several items, and for each of them I'd like to generate a "random" description, but that would actually always be the same !
So it wouldnt really be a random one actually :)

For each of the items, ive got several values: id, title, duration, etc ...
I was thinking that I could play with the ID, getting the number and depending on it generating a description. Good idea or not ?
I need this function to be light, because it's gonna calculate this generated description each time the page is rendering !

I've currently already got my description generator, but its writting the result directly in MySQL, and totally randomly. But it was the only way I've found to be sure the description would always stay the same.
And it's a bit painfull to have to re-write in the DB each time I want to add new items into my DB..

Does anyone has a good advice to give me ? :)

Re: web development / code challenge
« Reply #1 on: July 24, 2012, 09:21 PM »
Quote
"random" description, but that would actually always be the same

it's not a random anymore ? :o

What language ? php ?
If I understood what you said this might help you.
A way i can think of is. Everytime there is a new entry in your db. Trigger it and run your "generateArandomNotSoRandomFunction" that will take in an array of premade random description and add it to a Map that has your id as a key and the index (or whatever you want) as the value. There are plenty of way of doing it (you can mix up everything in one array if you want to save data or use two array has i said if you don't mind data but use maybe more cpu depend if you aim something or not). Up to you. :)
« Last Edit: July 24, 2012, 09:24 PM by zippeurfou »

Offline Rok

Re: web development / code challenge
« Reply #2 on: July 24, 2012, 09:23 PM »
Sounds like hashing would do the job?
chakkman> if rok was a girl i d marry the bitch lolz

Re: web development / code challenge
« Reply #3 on: July 24, 2012, 09:31 PM »
Sounds like hashing would do the job?
Indeed, my bad I am always thinking "Java" (don't kill me :D) but indeed I was thinking @Hashing also :)

Offline THeDoGG

Re: web development / code challenge
« Reply #4 on: July 24, 2012, 09:31 PM »
Quote
"random" description, but that would actually always be the same

it's not a random anymore ? :o

What language ? php ?
If I understood what you said this might help you.
A way i can think of is. Everytime there is a new entry in your db. Trigger it and run your "generateArandomNotSoRandomFunction" that will take in an array of premade random description and add it to a Map that has your id as a key and the index (or whatever you want) as the value. There are plenty of way of doing it (you can mix up everything in one array if you want to save data or use two array has i said if you don't mind data but use maybe more cpu depend if you aim something or not). Up to you. :)

Yes its not really random :) By random I mean that for each items I use a serie of keyword nun, verb, adjective, etc .. that i have put in arrays, and i mix them all together, I'd like that for each item it takes different word from those array.
I would like to run the function not when there is a new entry in the db, but when the page is rendering, in the client side ! So that I can manage my DB and get sure each of the new items will get fresh "randomly" generated static description. But actually maybe it's not such a good idea to it this way ?

About the language its ruby for a rails app.

@Rok, I've already heard about hashing, but I have no clue of what it is xD

Offline Rok

Re: web development / code challenge
« Reply #5 on: July 24, 2012, 09:38 PM »
What is this "description"? How does it need to look like? Write an example of input/output.
chakkman> if rok was a girl i d marry the bitch lolz

Re: web development / code challenge
« Reply #6 on: July 24, 2012, 09:43 PM »
this can help you for Hashing.
I am not sure to really understand.
Do you mean that if the client reload the page all these word  will change ?
Let me understand it.
let's use this code (it's C).

char randomWords[][10] = {"TheDogg", "Love", "Agnos", "Dick"};

you want the description to be a mix of these words "TheDogg", "Love", "Agnos", "Dick" with space at between everyword.

The output could be TheDogg Agnos Love Dick or Agnos Loves Dick TheDogg and so on.
right ?



Offline THeDoGG

Re: web development / code challenge
« Reply #7 on: July 24, 2012, 09:55 PM »
Do you mean that if the client reload the page all these word  will change ?

I want exactly the opposite :) Each time the client reload it should keep the same description. But it still should be a different one for each item
It's for SEO purpose, google will not like that the description change each time it visits the page :)

for example, to generate my descriptions, ive got 3 arrays :

["thedogg", "zippeurfou", "rok"]
["loves", "enjoy", "hates"]
["cherries", "apples", "bananas"]

for item #1: thedogg enjoy apples
for item #2: zippeurfou hates cherries
for item #3: rok loves bananas

but actually item #3 could also be "thedogg hates cherries" or anything else since i get sure it would ALWAYS be the same generated description

Re: web development / code challenge
« Reply #8 on: July 24, 2012, 09:59 PM »
If you want to do it client sided.
You'll have to use cookies to do it. If they disable it, you'll be kinda f@#!ed. I might be wrong but I don't see any otherway :(.

Offline THeDoGG

Re: web development / code challenge
« Reply #9 on: July 24, 2012, 10:02 PM »
wait, talking about client side was a mistake, after thinking !
Could be in server side :)

Offline MonkeyIsland

Re: web development / code challenge
« Reply #10 on: July 25, 2012, 06:46 AM »
May I ask why you need to do such thing? Filling page for SEO?
Due to massive misunderstandings: MonkeyIsland refers to an island not a monkey. I would be a monkey, if my name was IslandMonkey meaning a monkey who is or lives on an island. MonkeyIsland is an island which is related to monkeys. Also there's been a legend around saying MonkeyIsland is a game. So please, think of me as an island or a game.

Offline THeDoGG

Re: web development / code challenge
« Reply #11 on: July 25, 2012, 09:46 AM »
May I ask why you need to do such thing? Filling page for SEO?

Its not about filling a whole page, its about giving to each item a <meta> description that is unique. Getting sure it wont display any "duplicate" content that would also be present in another site.
Like this is should get better ranking in Google and sure to not be in "omitted" search results.

Any idea to help me MI ?

Re: web development / code challenge
« Reply #12 on: July 25, 2012, 12:33 PM »
In many languages there is function Choose, here's info from one of them

Code: [Select]
Real-valued function
Choose(val1,val2,val3,...) Returns one of the arguments choosen randomly. The function can have up to 16 arguments.
Maybe something such as that exist on language you use? So you could write IDs, and they would choose randomly..

Offline Abnaxus

Re: web development / code challenge
« Reply #13 on: July 25, 2012, 12:33 PM »
I didn't really got it: if you can explain me in French, I might be able to help you.
Watashi wa, jinmei ni iku sa reru ka o kakunin surunoni nagai jikan o matteita.
Shikashi, tada nariyuki o mimamoru.
Jikan dake to iudarou gen'in to naru.

May the force be with you.

Offline MonkeyIsland

Re: web development / code challenge
« Reply #14 on: July 26, 2012, 07:07 AM »
THeDoGG, my advise is that do not try to make a function to generate unique description. Such things are not flexible and will cause even more trouble. For example:

1. What if you need to specifically change a description for whatever reason in the future?
2. What if you need to search within your nonsense description for whatever reason?
3. What if a description is really really crappy and you want to refresh it?

If it was me, I would create a totally random generating function and insert the output in the database. That way everything would be in my control.
Due to massive misunderstandings: MonkeyIsland refers to an island not a monkey. I would be a monkey, if my name was IslandMonkey meaning a monkey who is or lives on an island. MonkeyIsland is an island which is related to monkeys. Also there's been a legend around saying MonkeyIsland is a game. So please, think of me as an island or a game.