|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On May 02 2016 12:24 amazingxkcd wrote:Show nested quote +On May 02 2016 09:45 Shield wrote:On May 01 2016 21:00 Manit0u wrote:On May 01 2016 19:39 bangsholt wrote:On May 01 2016 03:36 Manit0u wrote:Since I'm trying to brush up on my C a bit (been years since I last did anything in it) I'm here to ask you guys if this code is acceptable and please point out any errors or give suggestions if you have them. I've decided to start with something relatively simple - generating an array of numbers in range (eg. irange(1, 3) results in {1, 2, 3}, irange(3, 1) results in {3, 2, 1} etc.). Generating forward and reverse arrays of letters comes next: + Show Spoiler + #include <stdio.h> #include <stdlib.h> // Include stdbool.h to get booleans
// Merge the typedef with the declaration of the struct typedef struct integer_range integer_range;
integer_range *irange(int start, int end);
struct integer_range { int length; int nums[]; };
integer_range *irange(int start, int end) { // Use booleans for the next two declarations int reverse = (end < start); int size = (reverse ? start - end : end - start) + 1; size_t mem = sizeof(integer_range) + size * sizeof(int); integer_range *range = malloc(mem);
// Check return value of malloc.
range->length = size;
for (int i = 0; i < size; i += 1) { range->nums[i] = reverse ? start - i : start + i; }
return range; }
int main(void) { integer_range *range = irange(7, -1);
for (int i = 0; i < range->length; i += 1) { printf("%d\n", range->nums[i] ; }
free(range);
return 0; }
Please don't mind the main function for now. It's just there for testing purposes... Threw in a few comments in the spoiler for your code. Thanks. By checking return value of malloc do you mean something like that? if (range == NULL) { return -1; // something went wrong }
I still find it hilarious how you force yourself to do manual memory management and reinvent a basic version of std::vector. Here is your code with more safety (leak-free) that tries to resemble your C variant. That's not how I'd have written it anyway. + Show Spoiler + #include <vector> #include <iostream>
typedef struct integer_range integer_range;
integer_range irange(int start, int end);
struct integer_range { std::vector<int> nums; };
integer_range irange(int start, int end) { bool reverse = end < start; int size = (reverse ? start - end : end - start) + 1; integer_range range;
for (int i = 0; i < size; ++i) { range.nums.push_back(reverse ? start - i : start + i); }
return range; }
int main(void) { integer_range range = irange(7, -1);
for (const int& num : range.nums) { std::cout << num << std::endl; }
return 0; }
Are you trying to develop operating systems or embedded systems? Why C? "I don't like C++" is not a good reason. maybe he just wants to use C?
But why limit yourself to an outdated, unsafe language unless it's for embedded systems/operating systems?
|
On May 02 2016 20:04 Shield wrote:Show nested quote +On May 02 2016 12:24 amazingxkcd wrote:On May 02 2016 09:45 Shield wrote:On May 01 2016 21:00 Manit0u wrote:On May 01 2016 19:39 bangsholt wrote:On May 01 2016 03:36 Manit0u wrote:Since I'm trying to brush up on my C a bit (been years since I last did anything in it) I'm here to ask you guys if this code is acceptable and please point out any errors or give suggestions if you have them. I've decided to start with something relatively simple - generating an array of numbers in range (eg. irange(1, 3) results in {1, 2, 3}, irange(3, 1) results in {3, 2, 1} etc.). Generating forward and reverse arrays of letters comes next: + Show Spoiler + #include <stdio.h> #include <stdlib.h> // Include stdbool.h to get booleans
// Merge the typedef with the declaration of the struct typedef struct integer_range integer_range;
integer_range *irange(int start, int end);
struct integer_range { int length; int nums[]; };
integer_range *irange(int start, int end) { // Use booleans for the next two declarations int reverse = (end < start); int size = (reverse ? start - end : end - start) + 1; size_t mem = sizeof(integer_range) + size * sizeof(int); integer_range *range = malloc(mem);
// Check return value of malloc.
range->length = size;
for (int i = 0; i < size; i += 1) { range->nums[i] = reverse ? start - i : start + i; }
return range; }
int main(void) { integer_range *range = irange(7, -1);
for (int i = 0; i < range->length; i += 1) { printf("%d\n", range->nums[i] ; }
free(range);
return 0; }
Please don't mind the main function for now. It's just there for testing purposes... Threw in a few comments in the spoiler for your code. Thanks. By checking return value of malloc do you mean something like that? if (range == NULL) { return -1; // something went wrong }
I still find it hilarious how you force yourself to do manual memory management and reinvent a basic version of std::vector. Here is your code with more safety (leak-free) that tries to resemble your C variant. That's not how I'd have written it anyway. + Show Spoiler + #include <vector> #include <iostream>
typedef struct integer_range integer_range;
integer_range irange(int start, int end);
struct integer_range { std::vector<int> nums; };
integer_range irange(int start, int end) { bool reverse = end < start; int size = (reverse ? start - end : end - start) + 1; integer_range range;
for (int i = 0; i < size; ++i) { range.nums.push_back(reverse ? start - i : start + i); }
return range; }
int main(void) { integer_range range = irange(7, -1);
for (const int& num : range.nums) { std::cout << num << std::endl; }
return 0; }
Are you trying to develop operating systems or embedded systems? Why C? "I don't like C++" is not a good reason. maybe he just wants to use C? But why limit yourself to an outdated, unsafe language unless it's for embedded systems/operating systems?
While I do agree with your statement for the most part, sometimes people just prefer a language over another language, even if that language is just a subset of a more modern language. People have preferences that don't always have to make sense or fit into our world view.
C, while it's indeed a bit outdated, is not a bad language as such and you can always learn a bit more about memory management from working with it, so it's not the worst language to program in.
|
On May 02 2016 02:59 WarSame wrote:Show nested quote +On April 29 2016 17:08 Djagulingu wrote:On April 27 2016 23:42 WarSame wrote:On April 27 2016 18:41 Wrath wrote:On April 27 2016 10:43 WarSame wrote:Folks, looking for a bit of help with mean.io. I dled and installed node, mongodb and git. I then init a directory and run npm install inside of it. I then run gulp to start the server. This throws errors that I'm missing various modules such as 'mongoose', 'async', etc. but these should be installed from the npm install, correct? The exact error is + Show Spoiler +E:\mean_workspace\monoprobability\node_modules\q\q.js:155 throw e; ^
Error: Cannot find module 'mongoose' at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (E:\mean_workspace\monoprobability\node_modules\meanio-users\server\models\user.js:6:17) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at requireModel (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\index.js:116:19) at E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:21:7 at Array.forEach (native) at walk (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:16:25) at E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:23:7 at Array.forEach (native) at Object.walk (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:16:25) at MeanUserKlass.Module (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\index.js:134:14) at new MeanUserKlass (E:\mean_workspace\monoprobability\node_modules\meanio-users\app.js:10:10) at Object.<anonymous> (E:\mean_workspace\monoprobability\node_modules\meanio-users\app.js:21:16) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Module.activate (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\dependablelist.js:52:15)
When I tried to start using mean.io on another computer it worked fine so it is almost certainly a problem with my current environment. When I look inside of my root's node_modules folder it is missing both 'async' and 'mongoose'. Are they supposed to be in that folder? Can't you copy them from the other computer and see if that solves the issue for you? The other computer is a work computer which disables copying files :/ On April 27 2016 19:43 Acrofales wrote:On April 27 2016 10:43 WarSame wrote:Folks, looking for a bit of help with mean.io. I dled and installed node, mongodb and git. I then init a directory and run npm install inside of it. I then run gulp to start the server. This throws errors that I'm missing various modules such as 'mongoose', 'async', etc. but these should be installed from the npm install, correct? The exact error is + Show Spoiler +E:\mean_workspace\monoprobability\node_modules\q\q.js:155 throw e; ^
Error: Cannot find module 'mongoose' at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (E:\mean_workspace\monoprobability\node_modules\meanio-users\server\models\user.js:6:17) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at requireModel (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\index.js:116:19) at E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:21:7 at Array.forEach (native) at walk (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:16:25) at E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:23:7 at Array.forEach (native) at Object.walk (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:16:25) at MeanUserKlass.Module (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\index.js:134:14) at new MeanUserKlass (E:\mean_workspace\monoprobability\node_modules\meanio-users\app.js:10:10) at Object.<anonymous> (E:\mean_workspace\monoprobability\node_modules\meanio-users\app.js:21:16) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Module.activate (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\dependablelist.js:52:15)
When I tried to start using mean.io on another computer it worked fine so it is almost certainly a problem with my current environment. When I look inside of my root's node_modules folder it is missing both 'async' and 'mongoose'. Are they supposed to be in that folder? Is your internet stable, and no timeout problems? I've had issues with npm skipping stuff if it cannot get it sufficiently quickly, and then claiming success all the same. rerunning npm install usually works, but sometimes it's really confused and you need to throw away your node_modules and start again. either that, or your package.json is wrong. Yup, my internet is pretty stable here. I've run the command like 5 times in a row and I've deleted and reinited the app ~5 times too, so that shouldn't be it. My package.json is simply the default mean.io package, so it should be fine. I know it's a dumb question but... Does your package.json have async and mongoose in dependencies section? The only other thing I can think about is async and mongoose getting deleted from central npm repo. I don't think internet connection creates major issues because I might be having one of the shittiest internet connections in the entire thread and still didn't have any issues with npm claiming success but not downloading dependencies. Regardless, you can run: npm install --save async mongoose and solve your problem that way. It now starts the server, looks like it's going fine and then refuses to serve the pages. :/ Not sure why it's doing that... This is the same thing that happened last time I tried to manually install the packages. Dafaq?
Can you link me your github/bitbucket so that I can check out your code?
|
Hyrule18968 Posts
Saving things is usually done by a database, so there will be a PHP (or python or asp or ruby) layer you'll need to interact with.
|
On May 02 2016 21:45 tofucake wrote: Saving things is usually done by a database, so there will be a PHP (or python or asp or ruby) layer you'll need to interact with. Or you use nodejs, which does db access itself. But yeah. You have some kind if backend that your front end JS has to interact with.
|
On May 02 2016 20:04 Shield wrote:Show nested quote +On May 02 2016 12:24 amazingxkcd wrote:On May 02 2016 09:45 Shield wrote:On May 01 2016 21:00 Manit0u wrote:On May 01 2016 19:39 bangsholt wrote:On May 01 2016 03:36 Manit0u wrote:Since I'm trying to brush up on my C a bit (been years since I last did anything in it) I'm here to ask you guys if this code is acceptable and please point out any errors or give suggestions if you have them. I've decided to start with something relatively simple - generating an array of numbers in range (eg. irange(1, 3) results in {1, 2, 3}, irange(3, 1) results in {3, 2, 1} etc.). Generating forward and reverse arrays of letters comes next: + Show Spoiler + #include <stdio.h> #include <stdlib.h> // Include stdbool.h to get booleans
// Merge the typedef with the declaration of the struct typedef struct integer_range integer_range;
integer_range *irange(int start, int end);
struct integer_range { int length; int nums[]; };
integer_range *irange(int start, int end) { // Use booleans for the next two declarations int reverse = (end < start); int size = (reverse ? start - end : end - start) + 1; size_t mem = sizeof(integer_range) + size * sizeof(int); integer_range *range = malloc(mem);
// Check return value of malloc.
range->length = size;
for (int i = 0; i < size; i += 1) { range->nums[i] = reverse ? start - i : start + i; }
return range; }
int main(void) { integer_range *range = irange(7, -1);
for (int i = 0; i < range->length; i += 1) { printf("%d\n", range->nums[i] ; }
free(range);
return 0; }
Please don't mind the main function for now. It's just there for testing purposes... Threw in a few comments in the spoiler for your code. Thanks. By checking return value of malloc do you mean something like that? if (range == NULL) { return -1; // something went wrong }
I still find it hilarious how you force yourself to do manual memory management and reinvent a basic version of std::vector. Here is your code with more safety (leak-free) that tries to resemble your C variant. That's not how I'd have written it anyway. + Show Spoiler + #include <vector> #include <iostream>
typedef struct integer_range integer_range;
integer_range irange(int start, int end);
struct integer_range { std::vector<int> nums; };
integer_range irange(int start, int end) { bool reverse = end < start; int size = (reverse ? start - end : end - start) + 1; integer_range range;
for (int i = 0; i < size; ++i) { range.nums.push_back(reverse ? start - i : start + i); }
return range; }
int main(void) { integer_range range = irange(7, -1);
for (const int& num : range.nums) { std::cout << num << std::endl; }
return 0; }
Are you trying to develop operating systems or embedded systems? Why C? "I don't like C++" is not a good reason. maybe he just wants to use C? But why limit yourself to an outdated, unsafe language unless it's for embedded systems/operating systems?
Because all I want to do is just refresh my memory of it and brush up on it a bit. It provides a nice counter-balance to all of the objective, functional and otherwise highly abstract stuff I get to work with on a daily basis. I really like its simplicity and purity. It can teach you some solid practices and how to tackle your programs from a different angle.
On a side note, if anyone is working with PHP and has to make use of DOMDocument class here's a helper function I've devised that makes it much less of a hassle to build xml/html documents without resorting to string concatenation:
function buildNodesFromArray(\DOMDocument $document, $nodeName, array $nodeElements) { $node = $document->createElement($nodeName);
foreach ($nodeElements as $key => $value) { if (is_array($value)) { if (is_int($key)) { // array of arrays $key = key($value); $value = array_shift($value); }
if (is_array($value)) { $subNode = buildNodesFromArray($document, $key, $value);
$node->appendChild($subNode); } else { $node->appendChild(createNode($document, $key, $value)); } } else { $node->appendChild(createNode($document, $key, $value)); } }
return $node; }
function createNode(\DOMDocument $document, $key, $value) { if (null === $value || '' === $value) { // empty node $emptyValue = $document->createTextNode(''); $element = $document->createElement($key); $element->appendChild($emptyValue); } else { $element = $document->createElement($key, $value); }
return $element; }
Example usage:
$data = [ 'items' => [ ['item' => null], ['item' => 0], ['item' => 1], ['item' => 2], ], ]; $document = new \DOMDocument('1.0', 'UTF-8'); $nodes = buildNodesFromArray($document, 'list', $data);
$document->appendChild($nodes);
$xml = $document->saveXML();
// output: <?xml version="1.0" encoding="UTF-8"?> <list> <items> <item></item> <item>0</item> <item>1</item> <item>2</item> </items> </list>
It takes care of typical problems like having multiples of the same key or empty nodes that you'd still want in your DOM. Not dealing with attributes just yet.
I must say I'm quite surprised how often I'm using this helper now since I've created the initial version of it 5 months ago just to solve the empty node problem I've run into (and found related question on SO).
|
On May 02 2016 21:19 Djagulingu wrote:Show nested quote +On May 02 2016 02:59 WarSame wrote:On April 29 2016 17:08 Djagulingu wrote:On April 27 2016 23:42 WarSame wrote:On April 27 2016 18:41 Wrath wrote:On April 27 2016 10:43 WarSame wrote:Folks, looking for a bit of help with mean.io. I dled and installed node, mongodb and git. I then init a directory and run npm install inside of it. I then run gulp to start the server. This throws errors that I'm missing various modules such as 'mongoose', 'async', etc. but these should be installed from the npm install, correct? The exact error is + Show Spoiler +E:\mean_workspace\monoprobability\node_modules\q\q.js:155 throw e; ^
Error: Cannot find module 'mongoose' at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (E:\mean_workspace\monoprobability\node_modules\meanio-users\server\models\user.js:6:17) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at requireModel (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\index.js:116:19) at E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:21:7 at Array.forEach (native) at walk (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:16:25) at E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:23:7 at Array.forEach (native) at Object.walk (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:16:25) at MeanUserKlass.Module (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\index.js:134:14) at new MeanUserKlass (E:\mean_workspace\monoprobability\node_modules\meanio-users\app.js:10:10) at Object.<anonymous> (E:\mean_workspace\monoprobability\node_modules\meanio-users\app.js:21:16) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Module.activate (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\dependablelist.js:52:15)
When I tried to start using mean.io on another computer it worked fine so it is almost certainly a problem with my current environment. When I look inside of my root's node_modules folder it is missing both 'async' and 'mongoose'. Are they supposed to be in that folder? Can't you copy them from the other computer and see if that solves the issue for you? The other computer is a work computer which disables copying files :/ On April 27 2016 19:43 Acrofales wrote:On April 27 2016 10:43 WarSame wrote:Folks, looking for a bit of help with mean.io. I dled and installed node, mongodb and git. I then init a directory and run npm install inside of it. I then run gulp to start the server. This throws errors that I'm missing various modules such as 'mongoose', 'async', etc. but these should be installed from the npm install, correct? The exact error is + Show Spoiler +E:\mean_workspace\monoprobability\node_modules\q\q.js:155 throw e; ^
Error: Cannot find module 'mongoose' at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (E:\mean_workspace\monoprobability\node_modules\meanio-users\server\models\user.js:6:17) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at requireModel (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\index.js:116:19) at E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:21:7 at Array.forEach (native) at walk (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:16:25) at E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:23:7 at Array.forEach (native) at Object.walk (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\util.js:16:25) at MeanUserKlass.Module (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\index.js:134:14) at new MeanUserKlass (E:\mean_workspace\monoprobability\node_modules\meanio-users\app.js:10:10) at Object.<anonymous> (E:\mean_workspace\monoprobability\node_modules\meanio-users\app.js:21:16) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Module.activate (E:\mean_workspace\monoprobability\node_modules\meanio\lib\core_modules\module\dependablelist.js:52:15)
When I tried to start using mean.io on another computer it worked fine so it is almost certainly a problem with my current environment. When I look inside of my root's node_modules folder it is missing both 'async' and 'mongoose'. Are they supposed to be in that folder? Is your internet stable, and no timeout problems? I've had issues with npm skipping stuff if it cannot get it sufficiently quickly, and then claiming success all the same. rerunning npm install usually works, but sometimes it's really confused and you need to throw away your node_modules and start again. either that, or your package.json is wrong. Yup, my internet is pretty stable here. I've run the command like 5 times in a row and I've deleted and reinited the app ~5 times too, so that shouldn't be it. My package.json is simply the default mean.io package, so it should be fine. I know it's a dumb question but... Does your package.json have async and mongoose in dependencies section? The only other thing I can think about is async and mongoose getting deleted from central npm repo. I don't think internet connection creates major issues because I might be having one of the shittiest internet connections in the entire thread and still didn't have any issues with npm claiming success but not downloading dependencies. Regardless, you can run: npm install --save async mongoose and solve your problem that way. It now starts the server, looks like it's going fine and then refuses to serve the pages. :/ Not sure why it's doing that... This is the same thing that happened last time I tried to manually install the packages. Dafaq? Can you link me your github/bitbucket so that I can check out your code? Well, I've got the whole mean.io setup there, which is huge. The package for my website itself is here but that's just the basic website they offer as an example.
|
Some asshole tried to enter into my Facebook today but it's good I have 2-step verification, so nothing happened. It wasn't the easiest password but it wasn't a too simple one either. It's been written as if it's:
st4rw4rsbr0 - starwarsbro (not actual password)
Either way, I've set a new password using LastPass now. I should be fine.
|
I want to switch to LastPass but I feel like I'm going to get really mad one day if I need to access a file on a friend's computer or something :/
|
|
On May 04 2016 16:17 Nesserev wrote:Show nested quote +On May 04 2016 07:45 Shield wrote:Some asshole tried to enter into my Facebook today but it's good I have 2-step verification, so nothing happened. It wasn't the easiest password but it wasn't a too simple one either. It's been written as if it's: st4rw4rsbr0 - starwarsbro (not actual password) Either way, I've set a new password using LastPass now. I should be fine.  Wait, so your original facebook password was compromised? Do you have an idea how it could've happened? Show nested quote +On May 04 2016 14:12 Blisse wrote: I want to switch to LastPass but I feel like I'm going to get really mad one day if I need to access a file on a friend's computer or something :/ There's an alternative service that is accessible online and let's you type in a password and website, and it auto-generates a strong password. Don't remember what it was... maybe someone in this thread knows.
No, other than password being too easy for that person, I'm not really sure. Facebook thought it was someone from Indonesia but it could have been proxy. It's a shame Facebook doesn't have a customer service team to talk to. Just generic forms.
|
I know this isn't the "computer science" thread but is anybody interested in an algorithms! problem? I encountered this problem in the context of matching people based on survey answers and couldn't really find anything similar / analogous on the internet (I'm sure someone has implemented a solution to this in some shape or form before though, since from what I can tell e.g. dating websites often seek to answer this exact problem. Perhaps I just didn't look hard enough lol), so I'd consider it a pretty interesting problem with very clear practical applications.
Basically the problem is this: When someone takes a survey, their responses are recorded in a sequence. We want to take an input sequence, look into a set of sequences, and return from that set the sequence that most closely matches the input. We determine if two sequences match by comparing their elements pairwise. Assume that all sequences have constant length A, and that for question i we know the maximum number of answers to that question Bi (i.e. there exists a mapping M[i] = Bi). Let n be the number of sequences we want to draw a best match from.
A naive solution is to just store the sequences in a list, iterate over the sequences, and for each sequence find how many of its elements match the input. If this number is greater than the old best match number, make the new best match this sequence, and continue iterating. Then you just return what's stored as the best match once the list is iterated.
Now this seems like a good solution because it's O(n) (times A). However in the contexts this would be used we'd likely have millions of sequences to find a match from, and each sequence could have a hundred entries. I want to find a sublinear solution to this problem (perhaps involving tries) or at least one that reduces the coefficient on O(n) severely.
Let me know if you want me to post more information about this problem and PLEASE PLEASE PLEASE let me know if this is already a problem someone has solved. I've been thinking about it a lot and I love playing around with it.
|
What you need is a similarity measure. The cosine similarity seems like it might work well for you.
Given that you want to do pairwise comparisons, you won't get less than O(n) (cosine similarity is also O(n), but it's fast... Then again, so is edit distance, which you seem to describe). You could try speeding it up by shortening the vectors through some form of feature selection (it'll still be O(n), but you'll have less n.
|
On May 05 2016 21:36 Chocolate wrote: Matching stuff I think it's obvious that the only way to go below O(n) (or to achieve a constant factor c < 1 for O(n)) is to maintain some sort of lookup table/matrix/cache that you can query quickly.
Just some random idea, this might not actually lead anywhere: Imagine your data as an A-dimensional matrix of sets of identical survey results. For any given result you can locate all identical results by looking up the corresponding entry in the matrix. That's the easy part (even though you probably need some sort of high performance sparse matrix implementation to make this work).
Now how do we find the closest match if there are no identical ones? For a 2 dimensional matrix (only 2 questions), that would be the entries in the same row or column as the one you are matching with. But if we scan through all of these entries in a large matrix and repeat that for increasingly less similar results, it probably becomes very slow. I don't know, it might be fast, but I doubt it.
But since we are always looking for the closest match, then if we don't find an identical entry in the matrix we know that this entry in the matrix is free to store other stuff. So we can store pointers to the next closest matches there. Obviously this would make lookup blazing fast. But how do we update those pointers? Assume we have an empty matrix at first, obviouslty no pointers at all yet. The first entry is easy, everything now points to that (can we do that with a sparse matrix?). For the next ones, we have to find all the entries that should now point to the new entry and update those. We know the previously closest match for the new entry, so maybe that helps? We don't have to update the entries that are already occupied. That also helps a little.
Well, I guess that's it for now. I'd have to actually spend a bunch of time to continue this from here.
|
Might not be a lot of a speedup but you can stop comparing two sequences early when the number of remaining elements is not enough to produce a new best fit.
And I'm not sure if that works cause I didn't really think it trough completely, but maybe you can pre-process your sequences so that you know how often answer A, B, C... was selected and store these. That might let you completely skip sequences if these values not "equal" enough compared to the best fit you already have.
|
I feel like this problem can be solved as an eigenvalue problem, but I'm not sure on the specifics.
|
On May 04 2016 16:17 Nesserev wrote:Show nested quote +On May 04 2016 07:45 Shield wrote:Some asshole tried to enter into my Facebook today but it's good I have 2-step verification, so nothing happened. It wasn't the easiest password but it wasn't a too simple one either. It's been written as if it's: st4rw4rsbr0 - starwarsbro (not actual password) Either way, I've set a new password using LastPass now. I should be fine.  Wait, so your original facebook password was compromised? Do you have an idea how it could've happened? Show nested quote +On May 04 2016 14:12 Blisse wrote: I want to switch to LastPass but I feel like I'm going to get really mad one day if I need to access a file on a friend's computer or something :/ There's an alternative service that is accessible online and let's you type in a password and website, and it auto-generates a strong password. Don't remember what it was... maybe someone in this thread knows. I use keepass.info. They have an iOS app so I always have access to all my passwords if necessary.
|
On May 05 2016 21:36 Chocolate wrote: stuff
Look at the 2D case (so only 2 questions). Now your input/target t and all your other sequences in the set S of sequences are 2D points. Your goal is now to find the sequence s from S that is "closest" to t.
You are looking for the nearest-neighbour in high dimensions.
|
On May 06 2016 02:18 Zocat wrote:Look at the 2D case (so only 2 questions). Now your input/target t and all your other sequences in the set S of sequences are 2D points. Your goal is now to find the sequence s from S that is "closest" to t. You are looking for the nearest-neighbour in high dimensions. I don't think it's quite that. Imagine 100 different possible answers per question. The result (0,0) is closer to (1,1) than it is to (0,99). But (0,99) is still a better match. Assuming that the best match is the one which has the most identical answers.
|
On May 06 2016 02:35 spinesheath wrote:Show nested quote +On May 06 2016 02:18 Zocat wrote:On May 05 2016 21:36 Chocolate wrote: stuff Look at the 2D case (so only 2 questions). Now your input/target t and all your other sequences in the set S of sequences are 2D points. Your goal is now to find the sequence s from S that is "closest" to t. You are looking for the nearest-neighbour in high dimensions. I don't think it's quite that. Imagine 100 different possible answers per question. The result (0,0) is closer to (1,1) than it is to (0,99). But (0,99) is still a better match. Assuming that the best match is the one which has the most identical answers. Depends on your distance metric. Edit distance is a perfectly acceptable distance metric, and for edit distance for d((0,0),(1,1)) = 2, whereas d((0,0), (0,99)) = 1. There's no specific reason to limit yourself to Euclidean or Manhattan distance. I suggested cosine distance, but you're right that that may be the wrong approach if he really needs it to be edit distance.
As above, the only way to reduce the problem down form O(n) to some smaller version of O(n) is to find some way of reducing the number of n you have to look at. Obviously, heuristically stopping any time a solution goes over your minimum distance so far (or you can expand this heuristic to one that may be sub-optimal, but will always return at least a decent response, by doing this in parts). However, some kind of feature selection might work even better: for instance, if you have 20 questions about what general outward traits someone likes, stereotype that, and reduce it to searching for people whose outward traits were matched to that stereotype. It is suboptimal, but optimality is not everything it was made out to be anyway (especially not if dealing with human data, which is usually not a fully accurate representation of what you`re trying to figure out anyway).
|
|
|
|