|
edit: I'm XYing here
JawnV6 fucked around with this message at 21:43 on Feb 24, 2016 |
# ? Feb 24, 2016 21:40 |
|
|
# ? May 18, 2024 04:18 |
|
Stupid question: can someone explain enviornment variables to me? Are these just super mega global variables that anyone/anything can edit? I ask because I know in node there are sometimes process enviornment variables I have to set. And then reading up on some man pages for a particular linux command, a command can take input from an enviornment variable. So can I just have node change this enviornment variable and then run the command or are these scopes totally outside of each other?
|
# ? Feb 25, 2016 18:47 |
|
There is a group of environment variables for each process. When a process A spawns a new process B, B's environment starts with a copy of A's environment. A process can modify its own environment using the "setenv" and "getenv" library functions. They're often used to pass configuration into programs, since they can be set by whatever spawns a process.
|
# ? Feb 25, 2016 18:51 |
|
Suspicious Dish posted:There is a group of environment variables for each process. When a process A spawns a new process B, B's environment starts with a copy of A's environment. A process can modify its own environment using the "setenv" and "getenv" library functions. OK so if I am using node to spawn a child process, because i am spawning that process using bash ultimately, whatever node env's are set won't really be passed to the spawned process, but bashes will instead correct?
|
# ? Feb 25, 2016 19:18 |
|
How long would it take to set up a small test case with a brand new env variable that node sets and gets checked in the child?
|
# ? Feb 25, 2016 19:25 |
|
Knifegrab posted:OK so if I am using node to spawn a child process, because i am spawning that process using bash ultimately, whatever node env's are set won't really be passed to the spawned process, but bashes will instead correct? So bash (process A) spawns node (process B), which spawns custom-thing (process C)? When bash spawns node, bash's current environment gets copied and shoved in node. When node spawns custom-thing, node's current environment gets copied and shoved in custom-thing. bash's environment has no influence on custom-thing, except for variables that have been passed through node.
|
# ? Feb 25, 2016 19:32 |
|
Knifegrab posted:Stupid question: can someone explain enviornment variables to me? You've got two parts: Part I: When processes are spawned, they get a list of environment variables -- the same as they do with command line arguments. Part II: When spawning other processes, you pass a list of environment variables down to the callee. If "you" aren't explicitly passing environment variables in Part II, it's because your standard library is automatically pulling them out of a global variable and passing them for you. (That global variable originally got set from the environment that was passed into your process, and then perhaps got modified by you with some setenv function, if you did that sort of thing.) Knifegrab posted:OK so if I am using node to spawn a child process, because i am spawning that process using bash ultimately, whatever node env's are set won't really be passed to the spawned process, but bashes will instead correct? Assuming you are using bash somehow instead of just spawning the sub-process directly, what happens here is that your program spawns a new instance of bash, passes it whatever environment variables it wants (typically, the ones it was passed). Then bash passes those along to its subprocess -- it doesn't know what the other bash process's environment variables were -- and maybe it might pass some extra environment variable to its sub-process, because it's bash, I don't know, you could look and see.
|
# ? Feb 25, 2016 21:39 |
|
sarehu posted:You've got two parts: Part I: When processes are spawned, they get a list of environment variables -- the same as they do with command line arguments. Part II: When spawning other processes, you pass a list of environment variables down to the callee. OK this makes more sense thank you for the clarification. OK so what if I have something like this: I have a node server that is running express to handle multi-user webpage delivery. I have a process that can be kicked off by any number of users at any time. This process involves setting a node env variable, and then passing that env variable to bash which then spawns another child process to run. In the script that can be run by the user, I set the env variable (which will be different for each user) and then spawn the process. Now because there is only one instance of node running (the express server) is it possible that a collision could occur due to the non-blocking behavior of the script I am running where: -User A kicks off the script -Node sets env variable for User A and kicks off a promise for the spawning of the child process (this is non-blocking) -Before the child process is spawned User B then kicks off the script -Still before the promise resolves, the env variable is now changed for User B -The promise resolves, having used the env variable after it was set by user B. In this instance will a collision have occured? Or will User A's script and User B's script have env variables only scoped to themselves so no collision can occur. I am largely self-taught in most of my coding/learned on the job so I apologize if I am using some really dumb and bad terminology here. If I am being confusing let me know as well.
|
# ? Feb 28, 2016 21:13 |
|
Anyone know where I can get a good list of RSS feeds to test a feed parser? I found a list of 1000 feeds, but a lot of them were all generated by the same generators like wordpress and the like. I'd like a larger variety.
|
# ? Feb 28, 2016 22:46 |
|
Knifegrab posted:-User A kicks off the script It would be pretty bad (a) for an async API that depends on global variables to not make a copy or snapshot of them at the time it's called before doing anything, and (b) API design matters aside, for a process spawning API to not have made a syscall that has already passed the env itself, before returning. So I think you're fine. I mean, the way you're doing it is generally icky, setting the global environment and then having that value sit there in the env for something later to pick it up -- it could leak the information from User A to other users, and such, and increases the general chance of bugs. You could always look at the standard library (or whatever library) source code to examine its behavior in finer detail. Seriously. I found it to be a mess, but it was still just Javascript down to some level, you could probably see when and how it pulls the information from process.env.
|
# ? Feb 29, 2016 06:54 |
|
If I'm converting from a float to double in C or C++, there shouldn't be any reason why I would lose precision, right?
|
# ? Mar 1, 2016 04:51 |
|
Subyng posted:If I'm converting from a float to double in C or C++, there shouldn't be any reason why I would lose precision, right? No? Not unless you have a denormal and it rounds it to the smallest normal, or zero, before converting. I don't know that this happens, but it's the only exception I could come up with. (Might it also map negative zero to zero?)
|
# ? Mar 1, 2016 05:32 |
|
I know it's part of the "solid" principles, but is there any kind of consensus in the dev community about if/when to use dependency injection in an application? Is there any real benefit besides how it makes unit testing possible/easier?
|
# ? Mar 1, 2016 18:07 |
|
There's theoretically other use-cases (being able to switch between two implementations of a dependency based on a config setting or for A/B testing or the like), but reducing the boilerplate involved in making it so that you can override dependencies for the sake of unit tests is definitely the primary benefit.
|
# ? Mar 1, 2016 18:22 |
|
Since some of you may find this useful as well: Got tired of checking manually for new posts on threads, so i automated that bit with a little script and cron: https://github.com/wchristian/SomethingAwful-FreshBookmarks/blob/master/bookmarks.pl
|
# ? Mar 2, 2016 02:53 |
|
2 questions (C++ using mingw): 1) Is there a way to change the implementation of fmod()? Right now when I use it, fmod(x,y) with x<0 and y>0 gives me a negative number, i.e. the remainder from multiplying y with a negative number n such that ny is less negative than x. I want it to work so that it gives me the remainder of multiplying x with n-1. As a way to avoid this I'm currently using it as fmod(x+y,y) as |x|<|y| always, but speed is a must for me so if I can change the way fmod works it would be nice. 2) I have code occasionally crashing and I have no idea why it's happening. It happens when I allocate memory to an array of arrays. I declare it outside all functions as unsigned long** arr, later on making it arr = new unsigned long[L] and then in a for loop doing arr[i] = new unsigned long[Q] (Q is not constant for different i). The weird thing is, although I do have an RNG being seeded by time(0), nothing in that part of the code uses it, so all parameters are the same. Sometimes it crashes, sometimes it doesn't, and other times it crashes allocating another part of the array. I once got a message about bad_alloc() via the command prompt, but that only happened once. I've restarted my computer just in case but the problem persists. Any ideas? Is my RAM hosed?
|
# ? Mar 2, 2016 23:10 |
|
Leandros posted:1) Is there a way to change the implementation of fmod()? Right now when I use it, fmod(x,y) with x<0 and y>0 gives me a negative number, i.e. the remainder from multiplying y with a negative number n such that ny is less negative than x. I want it to work so that it gives me the remainder of multiplying x with n-1. As a way to avoid this I'm currently using it as fmod(x+y,y) as |x|<|y| always, but speed is a must for me so if I can change the way fmod works it would be nice. What kind of optimization are you doing that a single addition is an unacceptable speed penalty? Have you actually determined that this addition is slowing you down unacceptably? People are lousy at optimizing code unless they have a lot of experience at it. quote:2) I have code occasionally crashing and I have no idea why it's happening. It happens when I allocate memory to an array of arrays. I declare it outside all functions as unsigned long** arr, later on making it arr = new unsigned long[L] and then in a for loop doing arr[i] = new unsigned long[Q] (Q is not constant for different i). The weird thing is, although I do have an RNG being seeded by time(0), nothing in that part of the code uses it, so all parameters are the same. Sometimes it crashes, sometimes it doesn't, and other times it crashes allocating another part of the array. I once got a message about bad_alloc() via the command prompt, but that only happened once. I've restarted my computer just in case but the problem persists. Any ideas? Is my RAM hosed? Your problem is elsewhere in your code. You are almost certainly doing a bad access into your array of arrays somewhere. The RNG is probably not related to the cause; the reason it's nondeterministic is because the initial state of memory is different each time you run the program. You need to run your program inside of a memory access analyzer which keeps track of what parts of the program are valid accesses and which are not. MSVC has a built-in debugger that can help with this; since you aren't using it, though, you might look into valgrind. Or just check all the places where you're doing memory accesses; you done hosed up in one of them at least.
|
# ? Mar 2, 2016 23:30 |
|
Leandros posted:unsigned long** arr, later on making it C++ has an amazing ability to make people utterly certain their code is correct and the entire computing world, from the compiler to the OS and even hardware, around them is crumbling instead.
|
# ? Mar 2, 2016 23:37 |
|
JawnV6 posted:Middle one should have one * That's merely a typo here. The compiler would've thrown an error if it was that. TooMuchAbstraction posted:What kind of optimization are you doing that a single addition is an unacceptable speed penalty? Have you actually determined that this addition is slowing you down unacceptably? People are lousy at optimizing code unless they have a lot of experience at it. TooMuchAbstraction posted:Your problem is elsewhere in your code. You are almost certainly doing a bad access into your array of arrays somewhere. The RNG is probably not related to the cause; the reason it's nondeterministic is because the initial state of memory is different each time you run the program. You need to run your program inside of a memory access analyzer which keeps track of what parts of the program are valid accesses and which are not. MSVC has a built-in debugger that can help with this; since you aren't using it, though, you might look into valgrind. Or just check all the places where you're doing memory accesses; you done hosed up in one of them at least.
|
# ? Mar 3, 2016 01:01 |
|
I'm going to go out on a limb and suggest that you probably don't actually want a standard, commonly-used function to suddenly work completely differently in your codebase than it does everywhere else. That's just going to result in hair-pulling later on when someone tries to figure out why their numeric algorithm is giving them totally wrong results. Have you benchmarked whether removing the addition results in a measurable performance improvement, or are you just guessing? The addition is likely to be an order of magnitude faster than the fmod operation itself...
|
# ? Mar 3, 2016 01:20 |
|
Leandros posted:That's merely a typo here. The compiler would've thrown an error if it was that. Leandros posted:I get that, there's probably far more places I could improve my code, and obviously addition isn't exactly a burden, but it's called about 10^9 times in a small run so I'd prefer to not have it there. Besides, if there's a simple way to change the implementation of fmod() I'd prefer it just because it looks nicer.
|
# ? Mar 3, 2016 01:36 |
|
Leandros posted:2 questions (C++ using mingw): Point one: the things external (ram, compiler, system, etcetc) is never bad unless you are absolutely rock solid certain you have eliminated all other possibilities in your code. You are not there yet. Point two: If you're compiling with mingw, you're doing something unixy. Get a real unix machine or a vm, and use valgrind. Point two+: Get visual studio and use their debuggers instead. Point three: how close are you to the edge that you need to do this kind of memory trickery. Leandros posted:1) Is there a way to change the implementation of fmod()? Right now when I use it, fmod(x,y) with x<0 and y>0 gives me a negative number, i.e. the remainder from multiplying y with a negative number n such that ny is less negative than x. I want it to work so that it gives me the remainder of multiplying x with n-1. As a way to avoid this I'm currently using it as fmod(x+y,y) as |x|<|y| always, but speed is a must for me so if I can change the way fmod works it would be nice. You will regret doing this, and additionally it will not give you the speed improvements you want.
|
# ? Mar 3, 2016 02:20 |
|
In general: IEEE requires that implementations provide the floating point remainder x–(round(x/y)·y). If you get anything else (like fmod) it's a bonus. For X86: fmod and remainder map or or less directly to the two partial remainder functions FPREM and FPREM1. The advanced instruction sets can do the two corresponding remainder operations in one instruction (FPREM and FPREM1 are partial remainders, hence the P, and require loops) and vectorize them but do not, to my knowledge, offer any other remainders. You can't change the behavior and keep the performance. If you want more performance, 1: parallelize and 2: vectorize.
|
# ? Mar 3, 2016 02:43 |
|
How the gently caress do I create a sidebar? I cannot get my code to work right. It's supposed to work like this: <header> <nav> <sidebar><content> How do I get my sidebar and my content next to each other? I floated the nav menu left, the sidebar left, and the content right. It's not working and I want to hurt something.
|
# ? Mar 3, 2016 07:35 |
|
Need to see code, the relevant CSS and HTML to see where you've mis-stepped.
|
# ? Mar 3, 2016 08:03 |
|
Mycroft Holmes posted:How the gently caress do I create a sidebar? I cannot get my code to work right. It's supposed to work like this: set the size of the sidebar to a percent width="20%" then with the float left it should work, otherwise its going to fill the full window. a hint - use the debug tools in chrome to edit css to try things out (f12 in firefox as well)
|
# ? Mar 3, 2016 08:06 |
|
Maluco Marinero posted:Need to see code, the relevant CSS and HTML to see where you've mis-stepped. edit. Mycroft Holmes fucked around with this message at 08:37 on Mar 3, 2016 |
# ? Mar 3, 2016 08:06 |
|
Yeah, so you have no widths set. You want to set the width of your sidebar, and then also the width of the content area. I means there's a lot more to it than that, and you could also use new hotness like flexbox, but just setting widths will do for now.
|
# ? Mar 3, 2016 08:11 |
|
Mycroft Holmes posted:Should have put it in code blocks but it works fine like this I removed div4 as i couldnt work out where you wanted it - if its supposed to be on the right then you contain everything on the right in another div which is the column wrapper so using divs you create the left column/right column and then you can put whatever you want in there code:
code:
TheresaJayne fucked around with this message at 08:17 on Mar 3, 2016 |
# ? Mar 3, 2016 08:14 |
|
Thank you for your help.
|
# ? Mar 3, 2016 08:16 |
|
HappyHippo posted:This is a typical experience, but keep at it and eventually things will start clicking. The functional paradigm is different enough that it's almost like learning programming all over again. Yeah, it's encouraging to hear others have gone through the same and it's not just me being a loving idiot Thanks, guys!
|
# ? Mar 3, 2016 20:35 |
|
Der Shovel posted:Yeah, it's encouraging to hear others have gone through the same and it's not just me being a loving idiot Thanks, guys! Yeah, it took me quite a while too. The best advice I can give is try to work backwards from how you normally would. Start at the end, draw up the most complex data structure assuming you have any function you need along the way. Then start building those repeating the same process until you eventually get down to really simple components that are trivial to implement.
|
# ? Mar 4, 2016 02:08 |
|
So I'm taking a beginner c++ class and we're currently doing an assignment involving switch case statements. I have the gist of how the syntax is laid out I think, but I get an odd error when I actually compile and run the program. I've been trying to root out the problem, but I don't fully understand the logic that makes it work, so it's a little tough. The code was modified from a previous assignment that used an if/else statement to the same effect. Could someone explain what is happening just from a quick glance? The code code:
tweet my meat fucked around with this message at 04:46 on Mar 4, 2016 |
# ? Mar 4, 2016 04:42 |
|
Sergeant_Crunch posted:The error. "d" should read "CIS" in both spots and hours in the case of CIS hours should read 100. My guess is that it's taking the d at the end of invalid, but I'm not sure why. What is the type of the variable "major"? What kind of information are you trying to store in that variable?
|
# ? Mar 4, 2016 04:49 |
|
TooMuchAbstraction posted:What is the type of the variable "major"? What kind of information are you trying to store in that variable? I was about to answer his question, but I like your style.
|
# ? Mar 4, 2016 04:56 |
|
It's a character, and I'm trying to store text characters in it I think (CIS, BUS, etc) Is it something really obvious related to how char works? I used a string for the variable type on the previous program, but apparently that doesn't work with switch case statements. This is honestly the first time I've used character as a variable type since most of the previous programs have been pure numbers.
|
# ? Mar 4, 2016 05:05 |
|
Ok looking at it more closely I see that it's reading "d" as the input when I input "CIS" so it's reading the variable major as the wrong thing. The problem isn't in the switch case statement, or at least not this particular problem it's in some of the code before it I think. I'm not really sure why though, can char only handle one letter or something?
|
# ? Mar 4, 2016 06:20 |
|
You've got two problems (or really, the same problem twice.) One is when you read in major; the other is in the switch statement (specifically, in the default block.) What is a character?
|
# ? Mar 4, 2016 06:33 |
|
I'm gonna guess that a character can only be a single character and not multiple. Do I need to modify it so that it accepts a letter or number as the input and have a separate variable for the major and selection? I'll go ahead and give that a shot. e:Doing that made the program work, thanks! I'm pretty sure I get it, but I'll ask anyways. Was that the reason it wasn't working or did I stumble on to the solution without really understanding it? tweet my meat fucked around with this message at 06:57 on Mar 4, 2016 |
# ? Mar 4, 2016 06:46 |
|
|
# ? May 18, 2024 04:18 |
|
Sergeant_Crunch posted:I'm gonna guess that a character can only be a single character and not multiple. Do I need to modify it so that it accepts a letter or number as the input and have a separate variable for the major and selection? I'll go ahead and give that a shot. well char is a single character char test = 'w'; for a String you need an array of chars char* test = "WIN";
|
# ? Mar 4, 2016 08:14 |