Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
smug forum asshole
Jan 15, 2005

A MIRACLE posted:

Also what I suspect, but I'm not sure if it's like, a hardlinking issue or some other unixy nonsense that I don't fully understand.

Bash code:
alex@pit:~$ node --version
alex@pit:~$ which node
/usr/sbin/node
alex@pit:~$ ls -l /usr/sbin/node
-rwxr-xr-x 1 root root 60688 Nov 30  2009 /usr/sbin/node

do you have other executables that you need in the /usr/sbin directory? If not, just install node somewhere else and take that directory out of your $PATH.

OR, just replace /usr/sbin's node with whatever you really want it to be.

OR, (...someone help me out here. the poster has options, let's tell him/her what options they have!)

Adbot
ADBOT LOVES YOU

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

thanks for helping. I installed node again and now it lives in a different directory. Same issue though:

Bash code:
alex@pit:~/play/node$ which node
/usr/local/bin/node
alex@pit:~/play/node$ ls -l /usr/local/bin/node
-rwxrwxr-x 1 root root 13080411 Jul 15 15:22 /usr/local/bin/node
alex@pit:~/play/node$ node hello.js 
alex@pit:~/play/node$ echo 'kill... me...'
kill... me...

smug forum asshole
Jan 15, 2005
does node --version produce any output now, or still no?

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

smug forum rear end in a top hat posted:

does node --version produce any output now, or still no?

Magically, a system restart has fixed all of my problems.

DholmbladRU
May 4, 2006
Very new to javascript. However I am attempting to extend the functionality of a website by adding or altering some javascript. I am having a difficult time locating the javascript objects which I need to use. I know what the name of the object might be like, and I know what some of the values of the properties might be like. I attempted to locate them using firebug but they seem to be nested in a complicated way. Does anyone have any pointers on getting started with something like this?

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

DholmbladRU posted:

Very new to javascript. However I am attempting to extend the functionality of a website by adding or altering some javascript. I am having a difficult time locating the javascript objects which I need to use. I know what the name of the object might be like, and I know what some of the values of the properties might be like. I attempted to locate them using firebug but they seem to be nested in a complicated way. Does anyone have any pointers on getting started with something like this?

What's the URL (if public) and what are you trying to change about it?

DholmbladRU
May 4, 2006

A MIRACLE posted:

What's the URL (if public) and what are you trying to change about it?

Unfortunately it is not external. Essentially I want to move the contents of one div to another. However the way the page is designed its a little more complicated than

doc.getelementbyid("mybox).innerhtml+="Stuff"

The page implements some MVC architecture so I need to add/remove using javascript methods available or maybe add prototype methods?

Is there a browser which will recursively search through all dom nodes instead of those just expanded?

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

DholmbladRU posted:

Very new to javascript. However I am attempting to extend the functionality of a website by adding or altering some javascript. I am having a difficult time locating the javascript objects which I need to use. I know what the name of the object might be like, and I know what some of the values of the properties might be like. I attempted to locate them using firebug but they seem to be nested in a complicated way. Does anyone have any pointers on getting started with something like this?

It sounds like you are trying to modify a specific object not in the global scope (probably it is closed into a function and not exposed externally).

If that is the case then be aware that this is literally one of the worst things you can do in terms of maintainability and legibility: 1) modifying an object, in place, 2) that is not meant to be public, 3) from a distance. Even just one of those is a very very bad idea. You are doing all three.

I'm not saying there is absolutely no case in which you should do this, but be aware that you can easily cause months of headaches for somebody else (or even yourself) down the line when you forgot that you did this and wonder why the gently caress something isn't acting the way it should. So if you do do this (and probably should not), at the very very least leave notes in really obvious places documenting what you did and why.

Ok so in terms of actually reaching that object, yeah, you'll have to show us the code, it really depends. If it's declared using var as a local variable inside a function, you are just poo poo out of luck. You have to replace the whole function with one that exposes the object you want. Of course when the thing that the thing you replaced gets updated, you will break lots of poo poo (see what I mean about maintainability?). If the function it's in is also local, you have to replace the thing that contains it and so forth until you give up and do something more sane.

If it's not a local "var", then it is probably exposed accidentally and you can probably grab it from the global scope directly by name once that bit of code ran. Although easier to do this is actually the most dangerous approach because it relies on accident and there are a million and one things that will break it or break because of what you did.


Either way, it's a very very bad idea.

Post more of your problem and I'm sure we can come up with something way saner.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

DholmbladRU posted:

Unfortunately it is not external. Essentially I want to move the contents of one div to another. However the way the page is designed its a little more complicated than

doc.getelementbyid("mybox).innerhtml+="Stuff"

The page implements some MVC architecture so I need to add/remove using javascript methods available or maybe add prototype methods?

What MVC architecture? Is there a framework? Why exactly is it more complicated then modifying innerHTML. There is no way to answer your question without more details.

quote:

Is there a browser which will recursively search through all dom nodes instead of those just expanded?

I don't understand this question.

KongGeorgeVII
Feb 17, 2009

Flow like a
harpoon
daily and nightly.
Please excuse the messy code, I am sure I am probably using the most convoluted code for something that jQuery could probably do for me in a heartbeat but I am not a programmer by trade and just using what I know.

I need some help getting this to function properly, it is for a website and when a user clicks on one of the navigation buttons I want a DIV to animate based on which one was clicked but I want to do it dynamically without having to have a block of code for each div like I had before.

For instance, someone clicks a nav item with the ID of "hello", it should animate a DIV with the ID "helloDIV". I think the point that this code breaks down is in the animate line, I don't think the variable is being interpreted properly. I have tried all kinds of alternatives but I'll be the first to admit that I don't really have much of an idea what I am doing and would appreciate any insight into my fumbling.

The code works perfectly and does exactly what I want if I remove the variable down in the animate line and just replace it with the id of one of the DIVs that I want to animate, but that would mean I need a block of code like this for every piece of content I put on my website.

code:
$(".nav").click(function(){
                var name = $(this).attr('id');
                var name2 = ("'#"+name+"DIV'");
                var div_width2 = document.getElementById(this.id+"DIV").offsetWidth;
                var div_height2 = document.getElementById(this.id+"DIV").offsetHeight;
                var div_width = (div_width2 / 2);
                var div_height = (div_height2 / 2);
                
                var winW = 640, winH = 480;
                    if (document.body && document.body.offsetWidth) {
                        winW = document.body.offsetWidth;
                        winH = document.body.offsetHeight;
                    }
                    if (document.compatMode=='CSS1Compat' &&
                        document.documentElement &&
                        document.documentElement.offsetWidth ) {
                        winW = document.documentElement.offsetWidth;
                        winH = document.documentElement.offsetHeight;
                    }
                    if (window.innerWidth && window.innerHeight) {
                        winW = window.innerWidth;
                        winH = window.innerHeight;
                    }
                   
                var positionH = (winH / 2);
                var positionW = (winW / 2);
                var randomx = (positionH - div_height);
                var randomy = (positionW - div_width);
                $(name2).animate({top:(randomx),left:(randomy)},{ duration: 200 })
                name2.style.zIndex = '200';
        });
Thanks in advance!

Cawd Rud
Mar 12, 2009
Salad Prong
That code is a mess, but at a cursory glance this should get it working. Change
JavaScript code:
var name2 = ("'#"+name+"DIV'");
to
JavaScript code:
var name2 = "#"+name+"DIV";
The parenthesis aren't needed but weren't breaking it, but you had an extra pair of ' surrounding the selector which breaks it.

KongGeorgeVII
Feb 17, 2009

Flow like a
harpoon
daily and nightly.

Cawd Rud posted:

That code is a mess, but at a cursory glance this should get it working. Change
JavaScript code:
var name2 = ("'#"+name+"DIV'");
to
JavaScript code:
var name2 = "#"+name+"DIV";
The parenthesis aren't needed but weren't breaking it, but you had an extra pair of ' surrounding the selector which breaks it.

Huh, I could have sworn that was the first way I did it and I added the ' because it wasn't working. This fixed it though! Thanks!

toiletbrush
May 17, 2010
Is there any way in Javascript (in a Node context) to have an object 'catch' when an unimplemented method is called on it? A bit like forwardInvocation in Objective-C or method_missing in Ruby. The reason why is that I'm not enjoying mocking stuff in my Javascript tests when all I want to do is assert a method was called, so a 'proxy' object that could record all method calls performed on it that could be asserted against later seems like a nice idea (or possibly a Horror, I'm not sure yet). Rosetta Code has some example JS but it doesn't seem to work...any ideas?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Beta versions of node.js might have Proxy, which are what you're looking for.

It sounds like a horror, though.

thezoidburg
Dec 26, 2005

Hey all,

Figured this would be the best place for a typescript question. I saw a demo today of typescript, basically a 101 on what it does. I've been interested in it for a while but haven't got around to using it on a project yet. Has anyone got any experience with it they could share?

Also when watching the demo there were a few minor issues e.g. Some incorrect assignments were not being flagged as errors, and some inaccurate jquery.d.ts definitions. Do you guys feel typescript is t a decent level for use on commercial projects yet?

Iaman
Apr 9, 2008

Oh butt traps

toiletbrush posted:

Is there any way in Javascript (in a Node context) to have an object 'catch' when an unimplemented method is called on it? A bit like forwardInvocation in Objective-C or method_missing in Ruby. The reason why is that I'm not enjoying mocking stuff in my Javascript tests when all I want to do is assert a method was called, so a 'proxy' object that could record all method calls performed on it that could be asserted against later seems like a nice idea (or possibly a Horror, I'm not sure yet). Rosetta Code has some example JS but it doesn't seem to work...any ideas?

What testing framework are you using? If you don't mind pulling in a library explicitly for stubbing and spying, bond has a spy that should be able to collect method calls (and their arguments) for you to assert against later.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Any tips on using JSFiddle with a 1366x768 screen? Ugh. So tiny.

Deus Rex
Mar 5, 2005

Bob Morales posted:

Any tips on using JSFiddle with a 1366x768 screen? Ugh. So tiny.

JS Bin works better for me on smaller screens since you can easily toggle the HTML/CSS/JS/Console/Output views.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Deus Rex posted:

JS Bin works better for me on smaller screens since you can easily toggle the HTML/CSS/JS/Console/Output views.

Oh that is nice.

Kobayashi
Aug 13, 2004

by Nyc_Tattoo
I've got a weird NPM permissions issue. I'm running Mountain Lion, and have my umask set to 0027. NPM works fine except for when I want to install packages globally via sudo, which inherits my permissions. I can install packages globally, but I cannot use them because the files are not world readable:

code:
$ sudo npm install -g supervisor
npm http GET [url]https://registry.npmjs.org/supervisor[/url]
npm http 304 [url]https://registry.npmjs.org/supervisor[/url]
/usr/local/bin/node-supervisor -> /usr/local/lib/node_modules/supervisor/lib/cli-wrapper.js
/usr/local/bin/supervisor -> /usr/local/lib/node_modules/supervisor/lib/cli-wrapper.js
supervisor@0.5.3 /usr/local/lib/node_modules/supervisor
code:
$ supervisor
fs.js:695
  return binding.readlink(pathModule._makeLong(path));
                 ^
Error: EACCES, permission denied '/usr/local/bin/supervisor'
<snip>
code:
$ ls -l /usr/local/bin
<snip>
ls: /usr/local/bin//supervisor: Permission denied
lrwxr-x---  1 root   wheel    49B Jul 31 21:21 supervisor
It looks like there is an NPM config option to change the umaks, but I can't figure out how to use it. I've tried a number of variations, but nothing seems to stick:

code:
$ sudo npm config get umask --global
18
$ sudo npm config set umask 0022 --global
$ sudo npm config get umask --global
18
Any idea what I'm doing wrong? Is there something inherently dumb about my umask in the first place? How should I install packages globally, short of manually changing my umask every time?

Strong Sauce
Jul 2, 2003

You know I am not really your father.





I don't think you're suppose to use sudo when installing npm modules.

It looks like sudo changes the owner to root, which you shouldn't be running as? Installing things into /usr/local that should belong to the current user and not to root.

Sab669
Sep 24, 2009

Haven't touched Javascript since I took an Intro to JS course like 3 years ago; is there any equivelant to String.Empty from C#? Watching some tutorials for Unity and this guy tends to use a set of empty quotes frequently. Wasn't sure if there was a more "proper" way to get the same results.

akadajet
Sep 14, 2003

Sab669 posted:

Haven't touched Javascript since I took an Intro to JS course like 3 years ago; is there any equivelant to String.Empty from C#? Watching some tutorials for Unity and this guy tends to use a set of empty quotes frequently. Wasn't sure if there was a more "proper" way to get the same results.

Empty string literal. That's how you do it.

You do empty arrays and objects in a similar manner...
code:
var emptyObj = {};
var emptyArray = [];

akadajet fucked around with this message at 13:21 on Aug 1, 2013

Mogomra
Nov 5, 2005

simply having a wonderful time

Sab669 posted:

Haven't touched Javascript since I took an Intro to JS course like 3 years ago; is there any equivelant to String.Empty from C#? Watching some tutorials for Unity and this guy tends to use a set of empty quotes frequently. Wasn't sure if there was a more "proper" way to get the same results.

code:
// Completely worth it
if (!String.isEmpty) {
  String.prototype.isEmpty = function stringIsEmpty() {
    return this.toString() === '';
  };
}

// Or just this (you should do this instead, really)
var isSomeStringEmpty = someString === '';
:v:

If you want to fiddle around with loose typing you can drop one of the equal signs. The only reason I put ".toString()" in the first method is because some rear end in a top hat developer might decide they need to call that method on something that's not a string. loving around with "this" in javascript is a pretty common thing, which is why doing the straight comparison is usually a better idea for stuff like this.

akadajet
Sep 14, 2003


He's not asking how to test for an empty string. Just how to create one.

Kobayashi
Aug 13, 2004

by Nyc_Tattoo

Strong Sauce posted:

I don't think you're suppose to use sudo when installing npm modules.

It looks like sudo changes the owner to root, which you shouldn't be running as? Installing things into /usr/local that should belong to the current user and not to root.

I don't know man, I'm just doing what I'm told. Modules install locally just fine (without using sudo). It's only when I try to install global packages that I run into trouble.

quote:

$ npm install -g supervisor
npm http GET https://registry.npmjs.org/supervisor
npm http 304 https://registry.npmjs.org/supervisor
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/supervisor'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/supervisor']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/supervisor',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/supervisor',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





You need to change your entire /usr/local folder to set yourself (not root) as owner. That is why you cannot run without sudo is because you borked it before by using sudo.

sudo chown -R $USER /usr/local

http://foohack.com/2010/08/intro-to-npm/#what_no_sudo

Mogomra
Nov 5, 2005

simply having a wonderful time

akadajet posted:

He's not asking how to test for an empty string. Just how to create one.

I was bored, and what the heck else do you use String.Empty for?

akadajet
Sep 14, 2003

Mogomra posted:

I was bored, and what the heck else do you use String.Empty for?

Beats me. I never thought it was worth the extra characters in C#.

xtal
Jan 9, 2011

by Fluffdaddy

Strong Sauce posted:

You need to change your entire /usr/local folder to set yourself (not root) as owner. That is why you cannot run without sudo is because you borked it before by using sudo.

sudo chown -R $USER /usr/local

http://foohack.com/2010/08/intro-to-npm/#what_no_sudo

Anything outside of /home being owned by a standard user is bad practice, especailly in /usr. He should fix his problem by uninstalling the NPM module and reinstalling it without sudo.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Mogomra posted:

I was bored, and what the heck else do you use String.Empty for?
It was marginally faster than "" in C# 1.0 (to a degree that is unlikely to have ever mattered in any application ever created). These days it's just there for people who love making everything as verbose as possible.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Plorkyeran posted:

It was marginally faster than "" in C# 1.0 (to a degree that is unlikely to have ever mattered in any application ever created). These days it's just there for people who love making everything as verbose as possible.

But but if you use magic values in your code and you have to redefine the empty string... :ohdear:

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Munkeymon posted:

But but if you use magic values in your code and you have to redefine the empty string... :ohdear:

I get that you're not serious. That said, aren't strings in C# immutable, like in Java and Javascript? And because of that, don't Java string literals get translated into static code and every instance of a particular string literal is the same instance? Is that not the case in C#?

If it is, then string.Empty is the same as every "" in code.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Wheany posted:

I get that you're not serious. That said, aren't strings in C# immutable, like in Java and Javascript? And because of that, don't Java string literals get translated into static code and every instance of a particular string literal is the same instance? Is that not the case in C#?

If it is, then string.Empty is the same as every "" in code.

You used to be able to change the value of string.Empty via reflection, but not the value of "". Barring stupid shenanigans like that, they do compile to the same thing (after the JIT gets to it; the IL is different).

Strong Sauce
Jul 2, 2003

You know I am not really your father.





xtal posted:

Anything outside of /home being owned by a standard user is bad practice, especailly in /usr. He should fix his problem by uninstalling the NPM module and reinstalling it without sudo.

Eh, if you run npm install without sudo, who else would own the files created by npm?

Even doing an ls -la /usr/local just now, everything is owned by me.

Sab669
Sep 24, 2009

I was basically just told you should use String.Empty in C# because it's more "apparent" to someone else reading your code (or yourself in the future) what you're doing, where as just a set of quotes might imply to the reader something was left out. Or something.

I used to always just use the double-quotes all the time for appending non-strings to strings instead of the Convert class' ToString method, or use them when I just want an empty string until someone much smarter than I said otherwise :shrug:

overeager overeater
Oct 16, 2011

"The cosmonauts were transfixed with wonderment as the sun set - over the Earth - there lucklessly, untethered Comrade Todd on fire."



Is there a proper way to replace images with canvas elements to modify them "in place"? (Trying to apply an image filter to all the images in a page, if it helps.)

Right now, for each image I'm creating a canvas element, drawing the image onto the canvas and then replacing the image element with the canvas. That seems to work alright, but calling getImageData() then spawns a "This operation is insecure" error.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Vlad the Retailer posted:

Is there a proper way to replace images with canvas elements to modify them "in place"? (Trying to apply an image filter to all the images in a page, if it helps.)

Right now, for each image I'm creating a canvas element, drawing the image onto the canvas and then replacing the image element with the canvas. That seems to work alright, but calling getImageData() then spawns a "This operation is insecure" error.

Yep, can't do that by default, because it's insecure, because you could maliciously modify or use the image data.

If the image server has the appropriate CORS ( http://en.wikipedia.org/wiki/Cross-origin_resource_sharing ) headers set, then you can do it.

overeager overeater
Oct 16, 2011

"The cosmonauts were transfixed with wonderment as the sun set - over the Earth - there lucklessly, untethered Comrade Todd on fire."



That makes sense. I don't suppose there's a workaround for that, then?

Adbot
ADBOT LOVES YOU

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Vlad the Retailer posted:

That makes sense. I don't suppose there's a workaround for that, then?

Probably not, and if there was, it would be soon closed as a security hole.

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