• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Akai__

Member
Any Haskell pros here? I'm stuck with the following:

Code:
mValue :: Float -> Float -> Float
mValue a b = ((b - 0) / (0 - a))

Main> mValue 4.0 -3.0
ERROR - Cannot infer instance
*** Instance   : Fractional (Float -> Float)
*** Expression : mValue 4.0 - 3.0

What am I doing wrong?

Edit: I'm stupid. Negative numbers need to be inside the parentheses.

Code:
Main> mValue 4.0 (-3.0)
-0.75

*facepalm*
 

survivor

Banned
Is there a standard way of generating random strings for names for temporary files? I imagine something like UUID is the correct way right? Some reason my prof thinks there somehow might be a conflict in naming at some point which I'm finding very highly unlikely considering these files don't live for more than 1-2 minutes and there won't ever be huge demand for the service.
 
Is there a standard way of generating random strings for names for temporary files? I imagine something like UUID is the correct way right? Some reason my prof thinks there somehow might be a conflict in naming at some point which I'm finding very highly unlikely considering these files don't live for more than 1-2 minutes and there won't ever be huge demand for the service.

GetTempFileName if you're using Windows?
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Looking for some JSON help. I'm very new with this (2 days).

I'm currently changing the way some dropdowns operate so that they populate based on JSON data to remain in sync with another portion of the app. The problem I'm running into is that the JSON is formatted a little oddly, and I need to work around that. I can't change the format since the main app relies on it being this way.

Here's an example, with obvious value changes, but the structure is there.
Code:
    "BUILDING NAME": {
      "_config": {
         ... includes geolocate data and other info ...
      },
      "FLOOR #": {
        "_config": {
          ... includes geolocate data and other info ...
        },
        "ROOM #": {
          "_config": {
            ... includes geolocate data and other info ...
          }
        },

So each "CAPS" value is the value that I need to get for my dropdowns. Each tier contains a "_config", then the child values. I need to ignore the "_config" and get the child values.

For example, there are three dropdowns. After selecting the BUILDING, I need the second dropdown to populate with all that building's floors. Then after selecting a FLOOR, the third dropdown will populate with the rooms from ROOM values.

The part I'm failing at is the parsing of the JSON to get only the values I want.

edit2: I think I figured it out
 
Oh yeah sorry I should have specified, I'm working with Node.js so I'd imagine whatever environment the project will run on won't be Windows.

UUIDs should be completely fine. There's almost zero chance for a conflict, as UUIDs are generally 128 bits long. Even with 32 bit identifiers, a conflict would be very rare.

edit: There also appears to be a libc function for creating a temporary file or folder, though I don't know how to use C functions from node.js. (see here: http://www.gnu.org/software/libc/manual/html_node/Temporary-Files.html)
 

Ya no

Member
I need help with writing a sql statement for a homework assignment. I've tried a few different things as well some some examples I found online, but haven't been able to get it to work:

Write a select statement that returns vendor_name, vendor_city, and vendor_state of each vendor that's located in a unique city and state. In other words, don't include vendors that have a city and state in common with another vendor.


Can anyone help me out with this?

EDIT: this seems to work, but it seems like a strange way to get this done:
Code:
Select vendor_name, vendor_city, vendor_state
FROM Vendors
WHERE CONCAT(Vendor_City, Vendor_State)
     NOT IN 
   (SELECT CONCAT(Vendor_City, Vendor_State)
    FROM   Vendors
    GROUP BY Vendor_City, Vendor_State
    HAVING COUNT(*) > 1 )
ORDER BY Vendor_State, Vendor_City;
 

Kalnos

Banned
EDIT: this seems to work, but it seems like a strange way to get this done:
Code:
Select vendor_name, vendor_city, vendor_state
FROM Vendors
WHERE CONCAT(Vendor_City, Vendor_State)
     NOT IN 
   (SELECT CONCAT(Vendor_City, Vendor_State)
    FROM   Vendors
    GROUP BY Vendor_City, Vendor_State
    HAVING COUNT(*) > 1 )
ORDER BY Vendor_State, Vendor_City;

That's actually pretty standard (e.g. using NOT IN) but usually you do it with a primary key ID field instead of that CONCAT method.
 
Is there a standard way of generating random strings for names for temporary files? I imagine something like UUID is the correct way right? Some reason my prof thinks there somehow might be a conflict in naming at some point which I'm finding very highly unlikely considering these files don't live for more than 1-2 minutes and there won't ever be huge demand for the service.

UUID should be fine, just generate and test for the file already existing. Repeat until it doesn't, collisions almost certainly won't happen but this way they definitely won't.
 

poweld

Member
UUID should be fine, just generate and test for the file already existing. Repeat until it doesn't, collisions almost certainly won't happen but this way they definitely won't.

Yup, this. You have to write about 10 extra lines of code to ensure that you'll never have a problem, even though the Sun is more likely to prematurely explode than for you to have a random UUID collision.

(exaggeration, but perhaps not by that much)
 

nOoblet16

Member
Guys can anyone help me find a good tutorial for basic password based encryption/decryption in java plus cracking it using brute force ?

There are none on youtube, and I couldn't really find a well explained tutorial on it by googling. Basic encryption like multiplying/dividing a string buffer with a number to generate an encrypted text is something I already know. But I want something more proper and standardised rather that uses keys.
 
Guys can anyone help me find a good tutorial for basic password based encryption/decryption in java plus cracking it using brute force ?

There are none on youtube, and I couldn't really find a well explained tutorial on it by googling. Basic encryption like multiplying/dividing a string buffer with a number to generate an encrypted text is something I already know. But I want something more proper and standardised rather that uses keys.

This is a huge topic, what exactly is your goal? Are you implementing something? Do you want to learn more about crypto for the sake of it? It's hard to recommend something without a better idea of where you want to end up.
 

nOoblet16

Member
This is a huge topic, what exactly is your goal? Are you implementing something? Do you want to learn more about crypto for the sake of it? It's hard to recommend something without a better idea of where you want to end up.

Just a simple password based encryption using DES and MD5 that takes a plain text and encrypts it with a password then decrypts it again by using the password. They I want to brute force the code so as to find the password while assuming that I know the plaintext, the salt, the iteration count but not the password.
 

Onemic

Member
Anyone here that knows CSS that could maybe help me a bit?

I'm trying to build a two level drop down menu for my nav bar. I have my design for the nav bar, but whenever I add the CSS code for enable the drop down efffect I can never actually select the buttons uncovered from the drop down. When I move my mouse to click the button drop down button, it dissepears before I get a chance to access it. As soon as the cursor moves away from the first level menu, the drop down dissapears and I don't know why.

Here's my code:
Code:
#navigation li {
  display:          inline;
}
/*naviagation menu*/
.nav  {
	background: #333; 
	background: -moz-linear-gradient(#383838, #272727);
	background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#383838), to(#272727)); 
	background: -webkit-linear-gradient(#383838, #272727);
	border-bottom: 1px solid #222;
}

/*navigation text*/
.nav a
{
    display: inline-block;
    padding: 0 20px;
    background:#383838;
    border-radius: 2em;
    border: 1px solid #272727;
    color:#C4B09C;
    text-decoration:none;
    font: bold 12px Arial;
    line-height: 27px;
    margin-right:1 px;
    position: relative;
    left: 200px;
    top: 7px;    
}


/*Make menu buttons highlight when hovered*/
.nav a:hover, .nav a.current 
{ 
    background:#b2aeaa;
    color:#000;
}



/*dropdown*/
.nav li >ul {display : none;}

.nav li:hover > ul {
    display: block;
    position: absolute;
    padding-top: 20px;
    margin-left: 20%;
}

HTML

Code:
        <div class="nav">
            <ul id="navigation">
                <li><a href="../index.html">Home</a></li>
                <li><a href="blog.html">Blog</a></li>
                <li><a href="#">Media</a>
                    <ul>
                    <li><a href="audio.html">Audio</a></li>
                    <li><a href="video.html">Video</a></li>
                    </ul>
                </li>
                <li><a href="#">About Me</a>
                    <ul>
                    <li><a href="faq.html">FAQ</a></li>
                    <li><a href="contact.html">Contact</a></li>
                    </ul>
                </li>
                <li><a href="honesty.html">Honesty</a></li>
            </ul>
        </div>

EDIT: missed a piece of code
 
Anyone here that knows CSS that could maybe help me a bit?

I'm trying to build a two level drop down menu for my nav bar. I have my design for the nav bar, but whenever I add the CSS code for enable the drop down efffect I can never actually select the buttons uncovered from the drop down. When I move my mouse to click the button drop down button, it dissepears before I get a chance to access it. As soon as the cursor moves away from the first level menu, the drop down dissapears and I don't know why.

The dropdown disappears because the element you were on first loses focus. You'll most likely want static width for your top menu and sub enus and then move the sub menus to the right the amount of the top level div width. If you want the submenus to overlap the top one, you'll need to raise the sublevel z-index value

Some other things:

- Use list-style: none; on the ul-elements to remove the "list" styles (The dots)
- The left on the nav a pushes the a-elements, but not the list elements themselves. Were you using it to push / center the navbar? The a-elements have display: inline-block; too, did you mean to make the navbar horizontal? If so, add the inline-block display attribute to the nav > ul > li elements.
- Instead of using <div class="nav"> you could just use <nav> element
 

Onemic

Member
The dropdown disappears because the element you were on first loses focus. You'll most likely want static width for your top menu and sub enus and then move the sub menus to the right the amount of the top level div width. If you want the submenus to overlap the top one, you'll need to raise the sublevel z-index value

Some other things:

- Use list-style: none; on the ul-elements to remove the "list" styles (The dots)
- The left on the nav a pushes the a-elements, but not the list elements themselves. Were you using it to push / center the navbar? The a-elements have display: inline-block; too, did you mean to make the navbar horizontal? If so, add the inline-block display attribute to the nav > ul > li elements.
- Instead of using <div class="nav"> you could just use <nav> element

Whoops, missed a piece of code that made it all into one line. Edited it in my OP. It shouldnt look as horrendously bad now lol.

I'll try those suggestions, thanks. Hopefully that will fix it
 
Just a simple password based encryption using DES and MD5 that takes a plain text and encrypts it with a password then decrypts it again by using the password. They I want to brute force the code so as to find the password while assuming that I know the plaintext, the salt, the iteration count but not the password.

Well I'd start then by reading the wiki article on DES, it has a very indepth explanation of exactly how it work if implementation is something you're interested in. MD5 or other hashing functions don't have anything to do with symmetric encryption though and there is no salt involved in DES, you just have the key. Brute forcing DES is certainly doable although you need to have a very fast implementation and depending on how many CPUs you have access to it could take a very very long time. With a key size of 56 bits you're looking at 2^56 possible keys. This number could be greatly reduced if you knew certain properties of the key or message. For example if you know that the key is an ascii string that reduces the possible key space enormously. If you know that the encrypted message is an ascii string that means that you can simply decrpyt as many bytes as needed before moving on.

I would recommend though that you don't try to brute force anything as a learning exercise, although doing an implementation of DES and checking it works with whatever crypto lib in your language of choice might be valuable. Maybe instead you could look into doing the matasano challenge. It's a series of exercises taking you from implementing basic functions that are useful for crypto (decoding/encoding strings, byte manipulation etc.) up to real attacks on legitmate crypto. They give you enough information that you can do what research you need yourself. I've actually been working through it myself in my spare time and it's been very good so far (up to set 3 and a bit).
 

Antiwhippy

the holder of the trombone
How do you find it? I'm not sure if I entirely understand it, but it basically runs JS event loops without... needing to be called?
 
So I'm currently in a data structures class and we're using this book. I'm liking the subject, but I feel like I'm also missing a lot of information and want a book to keep for reading on my own time. Anybody got any suggestions for something better or should I buy this?
 

r1chard

Member
How do you find it? I'm not sure if I entirely understand it, but it basically runs JS event loops without... needing to be called?

It's callbacks, all the way down. Seriously, there's even a name for it:
wsuxJaH.png


And a website, for helping those unfortunate enough to have to deal with it: http://callbackhell.com/ ;)
 

survivor

Banned
How do you find it? I'm not sure if I entirely understand it, but it basically runs JS event loops without... needing to be called?

Well I wouldn't say I know very well the inner workings of Node.js so I just know general overview of the event system. But like the way I understood it there are certain events that once they are activated they have a callback function associated with them that gets added to the queue and then when it's their turn it does the callback function. So you see this in cases of http server that has a request event that fires up anytime someone connects to the server. Will probably make more sense once you starts messing around with it.

Anyway as for the whole thing I think it's a cool technology to learn, has different ways of doing things that I used to before so it was interesting learning experience. However to be honest, since I guess you are interested in using to build some web apps or something of that sort. If so you will be much better off with PHP or Ruby. Their communities are much more mature, most of their popular frameworks have been around for a long time and have a lot of resources online so I feel like you can get something usable done quicker.

In general for web applications, Express.js is generally the most popular framework for Node.js and the one that I'm using. It's good, has some good support, nothing comparable to Rails/Laravel. There is also hapi.js which I believe Walmart is using for some of their backend.
 

hateradio

The Most Dangerous Yes Man
So reading this article made me decide that my learning roadmap should be learning various PHP frameworks like laravel and cakePHP, to ruby on rails, then node.js.

Anyone here with experience on node.js?
I would skip CakePHP. I remember it not being that worthwhile a few years ago.

I personally would go Rails to Laravel because Rails documentation is amazing, while Laravel is severely lacking. Once you're familiar with Rails, Laravel and its shortcomings shouldn't be too much of an issue.

If you really want to learn a different PHP framework, look at Symphony because it has a really great book (tutorial) on its site. However, it uses Doctrine ORM which is way too verbose compared to the Active Record pattern used by Rails and Laravel. Still, it's very good at teaching you everything you need to know about routing, controllers, models, forms, pages, and even testing.
 

Anustart

Member
Question. I need to create a bunch of objects that have every possible arrangement of incrementing or decrementing number.

Say my integer is 5. I might have 3 different expressions, so ascending and descending need to be here. How can I make it so I build every possible sequence? Like with the 5, and 3 expressions, I'd need say (0, 2, 5), (1, 3, 4), (2,3,4)... Every possible set up of an integer that's ascending up to and including the maximum, 5 in this case. Same thing for descending, i.e. (5, 2, 1), (4,3,0)... etc.

I'm having trouble visualizing the solution to this problem.
 
Question. I need to create a bunch of objects that have every possible arrangement of incrementing or decrementing number.

Say my integer is 5. I might have 3 different expressions, so ascending and descending need to be here. How can I make it so I build every possible sequence? Like with the 5, and 3 expressions, I'd need say (0, 2, 5), (1, 3, 4), (2,3,4)... Every possible set up of an integer that's ascending up to and including the maximum, 5 in this case. Same thing for descending, i.e. (5, 2, 1), (4,3,0)... etc.

I'm having trouble visualizing the solution to this problem.

This problem is fairly straightforward if you think of it slightly differently. Take the ascending case, in your example what you want is to select every combination (6, 3), i.e. every combination of 3 elements from the set of numbers up to 5 inclusive. There are a couple of algorithms to do this efficiently. One of the simplest to implement is to generate the index of combinations in lexicographical order. Here's a simple example implementation. In this case the indices themselves are actually the numbers you need for ascending, it should be pretty easy to see how you can generate the descending numbers at the same time. The nice thing about this method is that you can generate all combinations of size k of a set m for any data type.

Some languages have built in functions for this by the way. Python has itertools.combinations for example.
 

Anustart

Member
New question, why would this second push_back() crash my program?

Code:
ExpressionTree tree;    // My tree of expressions
    
    ExpressionTreeNode baseNode;
    Expression baseExp;
    Expression nextBase;
    
    baseExp.threePower = 0;
    baseExp.twoPower = 1;
    
    baseNode.thisExpression.push_back(baseExp);
    
    baseNode.thisExpression.push_back(baseExp);

If I take out the second push_back(), program compiles fine.

Edit: I've determined that two lines there cause a crash. THe second push_back() and declaring Expression nextBase; also crashes it.

Edit 2: May have figured it out. In my struct ExpressionTreeNode I had two pointers, for left and right but I hadn't initialized these to NULL. I know that by itself was incorrect, but don't know why that would affect me pushing back a second value.

Edit 3: I believe I'm on the verge of completing this program :3 It's been tough for me but I'm glad I'm close! Last task I need to overcome is figuring out how to search this tree I've created >.<

Edit 4: Nevermind, I'm never gonna finish this and going to fail this class.

Edit: Gave up. I might as well just give up on the idea of being a programmer. I put values into an object, check that object's values, place object into tree, values get all fucked when looking at them inside the tree. Program crashes constantly, code doesn't work correctly to place shit in the tree anyway and even if I check for null, it'll crash when reading. God I fucking suck.
 

methane47

Member
Any html/javascript people can assist me with this?

Code:
<div id="divDocument">
         <table id="tblDocument">
            <tr>
		<td colspan="2" rowspan="2" class="reallybigcaption">
		<a><span id="AMT_DUE_DDLabel">AMT_DUE</span></a>
            </td>
            </tr>
            <tr>
               <td colspan="2" rowspan="3" class="reallybigtotal">
                  <a id="AMT_DUE">0.00</a>
               </td>
            </tr>

         </table>
      </div>

I would like to take the value from AMT_DUE and do some sort of calculation on it.
lets say AMT_DUE * 1.8 and place it into another td

How would i go about doing that?

/beginner HTML
 
New question, why would this second push_back() crash my program?

Code:
ExpressionTree tree;    // My tree of expressions
    
    ExpressionTreeNode baseNode;
    Expression baseExp;
    Expression nextBase;
    
    baseExp.threePower = 0;
    baseExp.twoPower = 1;
    
    baseNode.thisExpression.push_back(baseExp);
    
    baseNode.thisExpression.push_back(baseExp);

If I take out the second push_back(), program compiles fine.

Edit: I've determined that two lines there cause a crash. THe second push_back() and declaring Expression nextBase; also crashes it.

Edit 2: May have figured it out. In my struct ExpressionTreeNode I had two pointers, for left and right but I hadn't initialized these to NULL. I know that by itself was incorrect, but don't know why that would affect me pushing back a second value.

Edit 3: I believe I'm on the verge of completing this program :3 It's been tough for me but I'm glad I'm close! Last task I need to overcome is figuring out how to search this tree I've created >.<

Edit 4: Nevermind, I'm never gonna finish this and going to fail this class.

Edit: Gave up. I might as well just give up on the idea of being a programmer. I put values into an object, check that object's values, place object into tree, values get all fucked when looking at them inside the tree. Program crashes constantly, code doesn't work correctly to place shit in the tree anyway and even if I check for null, it'll crash when reading. God I fucking suck.

Don't worry this kind of incredible frustration is part of it. Post your code on pastebin or something. It's impossible to tell What's wrong without seeing all of it.
 
Any html/javascript people can assist me with this?

I would like to take the value from AMT_DUE and do some sort of calculation on it.
lets say AMT_DUE * 1.8 and place it into another td

How would i go about doing that?

/beginner HTML

You take the value out of the the element and parse it as floating point number, then you can do whatever you want with it and insert it to another element, for example:

Code:
var val = parseFloat(document.getElementById("AMT_DUE").innerHTML);
document.getElementById("result").innerHTML = val * 1.8;
 

Antiwhippy

the holder of the trombone
I would skip CakePHP. I remember it not being that worthwhile a few years ago.

I personally would go Rails to Laravel because Rails documentation is amazing, while Laravel is severely lacking. Once you're familiar with Rails, Laravel and its shortcomings shouldn't be too much of an issue.

If you really want to learn a different PHP framework, look at Symphony because it has a really great book (tutorial) on its site. However, it uses Doctrine ORM which is way too verbose compared to the Active Record pattern used by Rails and Laravel. Still, it's very good at teaching you everything you need to know about routing, controllers, models, forms, pages, and even testing.

Cool. Thanks for the tip.
 

rrvv

Member
just having issue with Class stuff

Code:
#include <iostream>
using namespace std;
 
class Human{
    char *name;
    int age;
    float height;
    float weight;
    
public:
Human (char *N, int A, float H, float W);
void Prints () const;
void Set (char *N, int A, float H, float W);
  
};

int main(){
Human myObj;
myObj.Prints();
myObj.Set("Ronaldo", 28, 185.0, 85.0);
myObj.Prints();
}

Never got it working in Dev C++ but my friend got it work in Xcode

Any idea why?
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
just having issue with Class stuff

Code:
#include <iostream>
using namespace std;
 
class Human{
    char *name;
    int age;
    float height;
    float weight;
    
public:
Human (char *N, int A, float H, float W);
void Prints () const;
void Set (char *N, int A, float H, float W);
  
};

int main(){
Human myObj;
myObj.Prints();
myObj.Set("Ronaldo", 28, 185.0, 85.0);
myObj.Prints();
}

Never got it working in Dev C++ but my friend got it work in Xcode

Any idea why?

Different compilers.
so annoying

What errors are you seeing in Dev C++?
 
Top Bottom