How to use jQuery in Coffeescript Interactive (REPL)? - coffeescript

So I've done...
npm install -g jquery
and I run coffee in terminal...
then I type in require 'jquery'
And I get an error :/. I've tried variations of the above to no avail.
How can I use jQuery functions in my Coffeescript REPL ?

You installed a jquery module as global module.
Loading local modules
If the module identifier passed to require() is not a native module (e.g. http), and does not begin with '/', '../', or './', then Node.js starts at the parent directory of the current module, and adds /node_modules, and attempts to load the module from that location.
If it is not found there, then it moves to the parent directory, and so on, until the root of the file system is reached.
Loading global modules
To make global modules available to the Node.js (and CoffeeScript) REPL, it might be useful to also add the /usr/lib/node_modules folder to the $NODE_PATH environment variable. Since the module lookups using node_modules folders are all relative, and based on the real path of the files making the calls to require(), the packages themselves can be anywhere.

It appears the quirk was that I had jquery installed in the global dependency folder (i.e. the -g flag in npm install -g jquery).
Doing a simple npm install jquery does the trick and gets everything to work :).

Related

CPAN first launching configuration

I'm taking a look into Perl as a total beginner. I want to try some CPAN modules.
When I run an install command on my Osx console, CPAN asks for a configuration with the following statement :
To install modules, you need to configure a local Perl library
directory or escalate your privileges. CPAN can help you by
bootstrapping the local::lib module or by configuring itself to use
'sudo' (if available). You may also resolve this problem manually if
you need to customize your setup.
What approach do you want? (Choose 'local::lib', 'sudo' or 'manual')
What is the difference between local::lib and sudo options ?
If I understand it well, it installs some modules locally on my computer. But I don't see any difference between the two config above.
If you use sudo, CPAN will use root to install the libraries in a central location where all users on the machine can access the files without any special configuration. If you use 'local::lib', it will create a library in your home directory and install the modules such that only perl programs that have been configured to look for modules in your home directory will find the modules.
Perl uses the special variable #INC to search for module paths. So you can install modules anywhere as long as you set #INC properly before you use them. This article explains the basics.
http://www.symkat.com/find-a-perl-modules-path
You can do all kinds of fun stuff with #INC; one of my favorite hacks it to put a function pointer in there and use custom perl code to lookup modules.
Good question. When you use local::lib, you can install Modules via CPAN User specific in an given directory. Assume you choose sudo as approach, you install Modules global.
Its like installing Node.js via npm. When you install a module with npm install -g <Modul>, its global installed and you can use it everywhere. But withouth that -g flag, its just available inside your current directory.
Its about the same here, except that you choose the default way of installing CPAN Modules.

Eclipse IDE and Sass

I've recently started using the Eclipse IDE for web development.
In the past when I've used Scout to complie my Sass.
Is there a way in Eclispe to automatically compile my Sass.
Is this the best option - http://www.only10types.com/2012/02/get-eclipse-to-automatically-compile.html
I've tried this but I get a BUILD FAILED becuase of
<apply dest="css" executable="/var/lib/gems/1.9.1/bin/sass">
I realise that executable needs to point to sass on my system but how do I find where sass is on my system?
I posted about this recently here: http://mikekelly.myblog.arts.ac.uk/2015/02/09/sass-with-eclipse-in-os-x/
My post refers to OS X but it should be easy enough to adapt the process to other setups.
Here's the text from my post:
Preparation
1. Make sure Ruby is installed. You’re going to need this as SASS is a ruby app. OS X should have Ruby installed by default. To check, open a terminal window and enter:
ruby -v
This should display the version information, something like:
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
If you don’t have Ruby, install it now. Come back once you’ve figured it out.
If you develop using Ruby at times, you are likely to be using RVM to manage different Ruby versions. If you’re using RVM we need to take some precautions. Don’t worry – we don’t need to get rid of RVM. We just need to make sure we install SASS to the system version of Ruby.
Let’s check to see if we have RVM installed:
rvm -v
If we get version information back, then we have RVM. (If we don’t we can just move on to step 2 below.) Let’s see which versions of Ruby we have installed:
rvm list
This should show you a list of Ruby versions, along with info. about which one is the default and which is the current version. We want to install SASS to the OS X default version of Ruby, not the RVM-installed versions, so enter this:
rvm use system
And now check again on our current Ruby version:
ruby -v
OK, if we’re happy that we have Ruby and that we’re using the OS X default Ruby, let’s proceed.
2. Install SASS
Do we have SASS?
sass -v
If that doesn’t return version information, you will need to install SASS:
gem install sass
If you get permission errors, use sudo:
sudo gem install sass
Once you have installed SASS, let’s check on its location:
which sass
That should return:
/usr/bin/sass
If a different path was returned, look again at the information above about RVM.
OK, now that we have SASS installed in the OS X default version of Ruby, we can now switch back to a different version of Ruby via RVM, if required.
Set up a Builder in your Eclipse project
In Eclipse, we’re going to use a Builder to set up SASS auto-compilation.
Ctrl-click on the title of your project in the Explorer view (I’m working on a PHP project in this case, so I’m using the PHP Explorer view.)
Select Properties.
Click on Builders, then on New… to make a new Builder.
Select the Program option and click OK.
Now we can give our Builder a name, e.g. sass.compiler
In the Main tab we need to put in the path to the installed sass application:
/usr/bin/sass
N.B. If you were using SASS with an RVM-installed Ruby, at this point you might have tried putting in something like:
/Users/myusername/.rvm/gems/ruby-2.1.5/bin/sass
However that gives problems as SASS then tries to find required resources but they're not in the path, and so the operation fails with the error:
sass env: ruby_executable_hooks: No such file or director
Hence the need to install SASS into the OS X default version of Ruby.
Now we need to pass the appropriate arguments to SASS, so that it knows what to do and what files to do it with. If we were running SASS from the command line, we would probably do something like this at the start of our development session:
sass --watch sourcefolder:destinationfolder
In a real project that might look something like this:
sass --watch app/sass:public/stylesheets
This is a one-off command which forces compilation of any scss files in app/sass, into css files in public/stylesheets, whenever changes are made to the scss files. However, we want our Builder to trigger the compile process each time we save our scss files, so --watch is inappropriate.
If we enter:
sass --help
we discover that the option we want is --update. Luckily this works just like --watch in that it checks the designated folder recursively – so if we have many folders with scss files, we just specify a common parent folder.
You may have some scss files which you want to include into other scss files, and should not be compiled into their own css files. If that is the case, rename those files with an underscore at the beginning, e.g. rename mixins.scss to _mixins.scss Sass will still recognise those files for inclusion, but won’t compile css equivalents.
In my Arguments field I have this:
--update ${workspace_loc:/project1/htdocs/theme}:${workspace_loc:/project1/htdocs/theme} --sourcemap=none --style compressed
In my case, the scss files are in the same folder as the compiled css files, so my source folder and destination folder are the same. I used the Browse Workspace button in one of the form fields to generate the ${workspace_loc} placeholder values for my source folders and destination folders.
I also added a few more SASS options – one to turn off the generation of .map files, the other to output css in a compressed style.
Under the Build Options tab I have Allocate Console and During auto builds ticked, but nothing else.
Click on OK to finish.
Now, when I edit one of the scss files in my project1/htdocs/theme folder, in the Eclipse console view I see that SASS is doing its work, compiling the scss into css. Success!
Alternative method
Use Webstorm ; )
An easy solution would be to use Eclipse Wild Web Developer:
https://github.com/eclipse/wildwebdeveloper#-get-it-now
The editor will simplify developing with web technologies. Besides automatically compiling SCSS files to CSS files it provides many more features. Check them out, I think you will like them.

Perl - Use lib with perl module which have dependencies

I have a Perl script which uses the module Net::SSH::Any. Since it does not belong to the “default” Perl installation, I have to use the use lib functionality to include it in my script.
Now, I have the directory c:\lib\net\ssh\any\ on my drive and I specify this: use lib c:/lib; at the beginning of my script.
It “works”: it didn’t say that the module is missing but it says that it couldn’t locate auto/Net/SSH2/autosplit.ix and at the end no backend available at...
When I add the auto directory (containing the correct structure) in the c:\lib\ directory and launch the script, I get this error:
No backend available at...
Which is an internal error of Net::SSH::Any mentioning it could not access the backend directory (which is already included :/)
Does anyone know how to solve something like that? I hope I was clear enough.
You need to use Local::Lib.
This will let you install and load a whole bunch of libraries and their dependencies in an alternate location. I use cpanm to manage my modules and a command something like this (which I put in a wrapper script).
cpanm -L $cpandir $M --no-skip-installed
Where $cpandir is your locallibdir and $M is the module you are trying to install.
Then in your code you would specify
use local::lib '~/foo';
However, I recommend setting a PERL5LIB environment variable, which will append your custom location to #INC and make the extra use local::lib line unnecessary. You would typically edit .bashrc or .profile in your home directory with a line like:
export PERL5LIB=/home/myusername/mymods/
The issue was caused by the fact that the module was downloaded and installed on a 32bits windows but I tried to run it on a perl 64bits installation! So the Net::SSH2 required module couldn't be executed properly.
To resume:
-How to detect the issue: by executing this command: (thanks to Salva)
"perl -Ic:\lib -MNet::SSH2 -e1"
-Modules definitions in my script:
use lib 'c:\lib';

How do I specify the Perl include path for a Catalyst fastcgi process?

i have installed all my dependencies for Catalyst in ~/perl5/lib/perl5 using local::lib
I want to run my app under Apache2 using mod_fcgid, but the fastcgi perl script cannot find the modules in my custom path. How can I specify that (apache config?) my custom lib dir is to be included in the INC directory without explicitly hacking it into myapp_fastcgi.pl? I want to be able to move my app between servers that have the perl includes installed in different directories.
Thanks,
Rob
You can set the environment variables with DefaultInitEnv. You probably want something like this, but with your regular includes too,
DefaultInitEnv PERL5LIB /home/rob/perl5/lib/perl5
You can also do things like setting your app config like that too,
DefaultInitEnv APPNAME_CONFIG /srv/app/appname.conf

Local cpan builds

I'd like to use a home directory specific, non-root directory for stuff I install from cpan. How can I configure it?
Normal CPAN configuration tries to install packages into /usr. After adding 'makepl_arg' => q[PREFIX=~/cpan_local], simple packages seem to build, but I cannot build a package that pulls its dependencies - the dependency is not found.
After I changed it to 'makepl_arg' => q[PREFIX=~/cpan_local LIB=~/cpan_local], I get the following message: Warning: Prerequisite 'ExtUtils::CBuilder => 0.27' for 'D/DA/DAGOLDEN/Module-Build-0.3607.tar.gz' already installed but installation looks suspicious. Skipping another installation attempt, to prevent looping endlessly.
How can I configure this properly? I want everything that's built to do to ~/cpan_local automatically. (or for people familiar with python, I'd like this to work like virtual-env and running easy_install from it).
Even better, install App::cpanminus first. Then just use it to install modules as a regular user. If this user can't write to the /usr/local/lib/perl* directories it will resort to writing in its home directory, or you pass it the -l or --local-lib option to directly install it in your home directory without it figuring out if it can install them system wide.
Finally, installing local::lib and setting up your environment automatically with your .bashrc file will allow you to omit the --local-lib option and install to your home directory directly.
Use local::lib. The bootstrap instructions should do the trick for you.