How does Rails know which environment to use? - production-environment

How does Rails (5.1) know which environment it is supposed to run in? All I've been able to find is that in nginx.conf a passenger_env variable seems to be set.
I seem to remember reading about a RAILS_ENV variable but I can't find it anywhere.

Turns out that passenger_app_env is ALL that is required to let know which Rails environment to load.
I found the answer here:
http://guides.rubyonrails.org/initialization.html
It's not immediately apparent but if you work through the Initialization Process you will find where the environment variable is set.

Related

How to get Processing to work on Cloud9 using Ruby language?

I am currently working on a personal project using the Ruby language in Cloud9 IDE. Recently, I came across an environment/programming language called Processing. My goals is to make Processing available for my use in Cloud9 IDE.
I am a complete novice and have no clue what I am doing. I followed directions from the following website: Directions for setting up Processing
I entered the following commands into Cloud9's terminal:
rvm install jruby
rvm use jruby
gem install ruby-processing
PROCESSING_ROOT: "/Applications/Processing.app/Contents/Java"
Entering in PROCESSING_ROOT: "/Applications/Processing.app/Contents/Java"
outputted message bash: PROCESSING_ROOT:: command not found
I wasn't too surprised by this, since the last entry probably needs information specific to my setup. Here are my questions:
1.) Are these directions correct for what I am trying to do? (get Processing to work in Cloud9 IDE). If they are not correct, can someone please point me to the correct directions, or give me directions?
2.) If these directions are correct, how can I successfully finish the last step? I tried running DrawRuby.rb, a simple program copied from the internet that supposedly made use of Processing. When I ran the code, the message "You need to set PROCESSING_ROOT in ~/.rpsrc" appeared. I am not sure if this piece of information is relevant or not, but I figured I would add it.
This is where I am at, and I am completely stuck. If someone could give me some help, I would be very grateful. Also, please make your explanation easy to understand. I am relatively new to the programming world, and may not necessarily understand terminology or how things should work.
Cheers!
*** Edit: I created a new workspace in Cloud9 IDE and tried Jed's suggestion. This is what happened:echo 'PROCESSING_ROOT: "/Applications/Processing.app/Contents/Java"' > ~/.rpsrc
:~/workspace $ rp5 run Draw.rb
WARNING: you need to set PROCESSING_ROOT in ~/.rp5rc
NameError: uninitialized constant Processing::RP_CONFIG
Did you mean? Config
RbConfig
const_missing at org/jruby/RubyModule.java:3344
spin_up at /usr/local/rvm/gems/jruby-9.1.7.0/gems/ruby-processing-2.7.1/lib/ruby-processing/runner.rb:188
run at /usr/local/rvm/gems/jruby-9.1.7.0/gems/ruby-processing-2.7.1/lib/ruby-processing/runner.rb:105
execute! at /usr/local/rvm/gems/jruby-9.1.7.0/gems/ruby-processing-2.7.1/lib/ruby-processing/runner.rb:67
execute at /usr/local/rvm/gems/jruby-9.1.7.0/gems/ruby-processing-2.7.1/lib/ruby-processing/runner.rb:61
<main> at /usr/local/rvm/gems/jruby-9.1.7.0/gems/ruby-processing-2.7.1/bin/rp5:10
load at org/jruby/RubyKernel.java:979
<eval> at /usr/local/rvm/gems/jruby-9.1.7.0/bin/rp5:1
eval at org/jruby/RubyKernel.java:1000
<main> at /usr/local/rvm/gems/jruby-9.1.7.0/bin/jruby_executable_hooks:15
You need to add a file to your home directory (~/) called .rpsrc and then add that environmental setting (PROCESSING_ROOT) to your file. The following should work from the command line in your cloud9 environment:
echo 'PROCESSING_ROOT: "/Applications/Processing.app/Contents/Java"' > ~/.rpsrc
I know it might be a bit late for you but ruby-processing is now deprecated, and will only work with processing-2.2.1. For processing-3.3.7 use either JRubyArt or propane latter does not even require processing install.

Tensorflow object detection: ImportError: No module named nets

I am currently attempting to install the tensorflow object detection app on Windows 7 (employer requirement) and I am failing at a few steps from the end.
Basically I get the following error when I run the installation test command:
ImportError: No module named nets.
I have read some solutions on the subject:
https://github.com/tensorflow/models/issues/729
https://github.com/tensorflow/models/issues/1842
which looks like this:
export PYTHONPATH="$PYTHONPATH:"somepath"/tensorflow/models/slim"
basically meaning that I must set the right path in the PYTHONPATH environmental variable.
Working with Windows, I tried calling this:
SET PYTHONPATH="$PYTHONPATH:C:tensorflow/models/slim
And when it didn't work, I created a PYTHONPATH variable in system-> environmental variables.
I'm still getting the error so I suppose that I am still missing something but due to my lack of knowledge I still can't figure out what.
Would someone familiar with Windows be able to point out what's missing?
Thanks
in linux:
add export export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim to ~/.bashrc
attention:you should keep single quote mark
if you work with windows, i guess it should like this:PYTHONPATH=$PYTHONPATH:'C:/tensorflow/models':'C:/tensorflow/models'/slim
just my guess, you can take a try.
good luck!
If you run the setup.py it will install all the relevant modules for object detection. The other option is download the git directory. cd to the folder and try to run the module from there. You might face protubuf issue. Try to install it before running the code. It's bit complicated to install protobuf in windows. But if you are not using ".pb" file, then you don't need to.
I figured out a way to make it work. I am not writing this as a final answer as it is mostly a workaround and due to lack of understanding from my part I cannot guarantee it will work (and also it might not be best good practice).
Anyway here it is:
As Beta previously suggested, you have to run setup.py, however running it from models folder did not do it for me, I also had to run it from object detection folder.
However there was a problem there, it generated an error saying the BUILD already existed (which was correct) so I had to delete the BUILD file from inside of model.
After that it worked, turns out the path I had set was working fine.
Now if some experts would look into this and explain how and why this workaround worked it might make this a valid solution.

TestFirst.org Learn_ruby rake and depreciation warnings :should and :expect syntax

After many searches via Google I'm ready to get some input from the community. I'm trying to apply for App Academy in San Francisco and one of the required pre-work is TestFirst's Learn_ruby. I original had this configured on a Linux VM on my windows box. It worked very well. When I ran rake it would list one problem at a time; the text was is helpful colors; and the output was very condensed so I only got what I needed to read. I've recently wiped and configured my system as a dual boot Xubuntu 14.04/ Windows and the VM I once had is long gone. I worked to get Ruby setup in my linux vm just as I had done in the VM.
My problem now is when I run rake on my projects I get the same depreciation warning:
Deprecation Warnings:
Using should from rspec-expectations' old :should syntax without
explicitly enabling the syntax is deprecated. Use the new :expect
syntax or explicitly enable :should instead. Called from
/home/kaji/Projects/learn_ruby/05_silly_blocks/silly_blocks_spec.rb:25:in
`block (3 levels) in '.
After googling this back and forth I understand for the most part what the error is telling me. And I've even found a solution to get it to go away. Thanks to this post: RSpec's New Expectation Syntax, I was able to find a syntax to make the warning go away. (basicly had to change blah.should == # to expect(blah()).to eq(#) inside the *_spec.rb file. This seems to make the warning happy. However I still see signs that I have another problem.
The output isn't as 'friendly' as it was when I was on my VM. It's not in color; it dumps all the errors at once. What I enjoyed the most about learn_ruby was it gave me one objective at a time with minimal output. Now i have to scroll up quite a ways just to see what my issues are.
I've tired removing RVM completely and all gems and reinstalling to see if I could resolve this. No dice. I'm such a Ruby Noobie i'm a little overwhelmed with all this. I'd like to just get back to learning the basics but this has been troubling me for over a week. Has anyone had this problem/fix the except
I've also tried removing the rpsec ~<=2.0 from the Rakefile. I'm using ruby -v 2.1.2, rails 4.1.1 and i have RSpec 3.0.0, 2.99.0, 2.0.0. I even tried finding a tutorial on changing the syntax but it was real confusing as it introduced lots of Ruby concepts I have no idea on. At that point I feel like I'm over my head and there is something simple I'm missing.
Hope I provided enough info for assistance.
I hope I'm answering the correct question, since you seem to have figured out the one in the title (i.e. the preferred syntax having changed from blah.should to expect(blah).to). It would help if you changed the title to reflect the actual question.
RSpec.configure do |config|
config.fail_fast = true
config.color_enabled = true
}
will make RSpec fail at first error, rather than after running all tests, and enable the colours, for that one file.
Or you can run rspec with rspec --fail-fast --color.
Alternately, you can put this in $HOME/.rspec so it always does it:
--fail-fast
--color

Why do people say to enable NSDebugEnabled YES, when NSDebug.h comments seem to say that is the default?

as in the question, i am trying to understand using environmental variables correctly, and also harness their power, but i'm confused by what i am finding.
caveat: cocoa, and Xcode 3.2.6 here.
Comment quote is:
Here is a table of the variables/values initialized from the
environment at startup.
NSDebugEnabled
the DEFAULT listed as "YES".
is this comment trying to convey that this is how it is setup if i don't change anything ?
perhaps, i have had too much coffee, but this is confusing.
can someone explain please ? thanks.
If you haven't defined anything then NSDebugEnabled is NO, and will not be used. Once we set that yes in environment variable then only it will work.

What is the cleanest way to set the environmental variable DYLD_FRAMEWORK_PATH for a release build?

I have custom frameworks in my app bundle for WebKit, WebCore, and JavaScriptCore. I would like all other frameworks that depend on the system versions of WebKit, WebCore, or JavaScriptCore to use my custom versions also. For instance my custom version of Webkit loads private system frameworks that in turn depend on the system version of WebKit. This means both my WebKit and the system WebKit get loaded, and usually a crash happens shortly after.
The way I understand this should be done, is to set the DYLD_FRAMEWORK_PATH environmental variable before your app bundle begins execution (Search order for loading frameworks can be found here: http://code.google.com/p/macdependency/wiki/SearchPaths). You can set environmental variables in code with setenv, but it won't take effect for the currently running process. I would have to re-launch the process again for it to take effect. I would like to avoid this too.
So my question is what is the best way to set the DYLD_FRAMEWORK_PATH before the execution of the my app bundle? This has to work in a release app bundle too. Is there a way to run a script whenever someone clicks on my app bundle before the executable starts running. Or is there any other suggestions out there?
Thanks in advance.
Jeff Wolski has the right idea by referring directly to Apple's documentation on the subject. This thread also provides excellent advice on how to get that going in Xcode, including corner cases associated with alternative methods of specification (for example, by using ~/.bash_profile directly for your user).
My reason for chiming in is you also asked for a script that might be able to assist you (and a bounty provider appears to have the same issue). It turns out Webkit references such a script in its documentation, which you might want to pick apart from the applicable Webkit source code. This should give you additional guidance on how, at least according to the developers, you should do this properly.
Best of luck with your project(s).
I would recommend environment.plist or the LSEnvironment key in the info.plist. Check out the link below.
https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/EnvironmentVars.html
WebKit currently has a script to do this for you, called run-webkit-app. See http://trac.webkit.org/browser/trunk/Tools/Scripts/run-webkit-app
Newer versions of ld understand the -dyld_env flag, which inserts a LC_DYLD_ENVIRONMENT load command into the binary (and as such applies essentially as early as possible in app execution). Perhaps adding -Wl,-dyld_env,DYLD_FRAMEWORK_PATH=/folder/encosing/WebKit/and/related/frameworks to your compiler flags might do what you want?

Resources