Importing same file multiple times in different files? - stylus

Eg: I want to import a file called #import 's-grid-settings' in multiple different stylus files. Is this a bad idea?

It depends :)
Stylus have two ways of “importing” other stylus documents: via #import and via #require.
The difference is that #import would import the file each time, while #require would do this only once.
#require this way could be useful to share the settings and/or some common stuff like placeholders etc. between multiple stylus files in a such way those files could be either compiled each by itself or as a bundle. If the #import was used in this case, it would include all its stuff every time it was called, while #require would do this only once at the first call.
So, the answer to your question would depend on what is there inside your file.

Related

Easiest way to merge C Dlls. Have Source

I'm working with pocketsphinx. It comes in 2 dlls. sphinxbase.dll and pocketsphinx.dll. pocketsphinx.dll calls on functions in sphinxbase.dll. I'm going to be calling functions in both. I'd like to know the easiest way to merge both source files into producing a single dll.
I've tried this before but I run into the problem of pocketsphinx using sphinxbase leading to a warning/error about importing functions I'm trying to export.
What's the common solution to get around this?
Should I remove the dllexport tags from sphinbase and then wrap those functions inside other functions that I then export?
Example
//inside sphinxbase
SPHINXBASE_DLL_EXPORT
void sphinxbasefunc();
//inside pocketsphinx
POCKETSPHINX_DLL_EXPORT
char* decode(ps_decoder_t decoder)
{
...
sphinxbasefunc();
...
}
Then I would remove the SPHINXBASE_DLL_EXPORT macro and create a wrapper that I would then export.
//inside sphinxbase
void sphinxbasefunc();
WRAPPER_DLL_EXPORT
void sphinxbasefunc_wrapper() { sphinxbasefunc(); }
This solution I think is naive on my own part though. Theres dozens of functions I would need to wrap if I took this route.
One thing to realize is like an exe, a dll is just a collection of one or more object files bound into a package. Combining object files into dlls/exes is the linker's job. If you want to combine your two dlls into one, combine the object files that make up your two dlls into one dll. When you do that your references will no longer be to dlls, but directly to the objects themselves (source code changes will be required, but mostly this is removing dllimports), so it should be a much more direct process (include the header, make sure the object is included in the link). You only need to export those functions required by consumers of the final dll. Basically put the source for both dlls into one project. I'm assuming of course that you have the source for these dlls (which is how it appears from the url given). If you end up with circular dependencies you may have to create some forward declarations or additional header files to keep the compiler happy.

How to smartly include all the necessary files?

Right now my Karma config has the following files to include:
files: [
'vendor/vendor.js',
'vendor/angular-mocks/angular-mocks.js',
'src/components/security/index.js',
'src/components/security/authentication.js',
'src/components/security/login-controller.js',
'src/components/filters/index.js',
'src/components/filters/toDate.js',
'src/components/services/index.js',
'src/components/services/alert.js',
'src/menu/index.js',
'src/menu/menu-controller.js',
'src/user/index.js',
'src/manage/index.js',
'src/manage/user/manage-user-controller.js',
'src/manage/channel/manage-channel-controller.js',
'src/stream/index.js',
'src/stream/stream-controller.js',
'src/messages/index.js',
'src/messages/messages-controller.js',
'src/app.js',
'src/**/*.spec.js'
],
The file vendor/vendor.js is automatically created by a Gulp task concatenating all vendor files using my bower config. It's all my own Javascript code that's so hard to include because order matters a great deal. The index.js files within a folder define the module (and its routes) and thus must be loaded before the individual files. And app.js always has to be last.
So my question is how I do this a bit smarter, for example with a glob that first includes all the index.js files and then all the others?
This is exactly what RequireJS is for. You can use it in your deployed code, but you can also just use it for your tests.
If you do this, your "karma.conf.js" ends up being a little shorter and less volatile. Your RequireJS config file specifies some dependency mapping. Each test spec ends up specifying what dependencies it needs, either in a "declarative" fashion in the "define" call, or sometimes manually through the "require" function (you sometimes need the latter to deal with circular reference problems).
Hm I guess asking the question gave me the idea I needed :) This works:
files: [
'vendor/vendor.js',
'vendor/angular-mocks/angular-mocks.js',
'src/*/**/index.js',
'src/*/**/*.js',
'src/app.js',
'src/**/*.spec.js'
],
Adding the *.js after index.js results in debug messages like this:
src/manage/index.js ignored. Already in the list.
Excellent!

Changing the order of concatenation of stylus files in Brunch

I have Brunch compiling Stylus for a Backbone.js app and I can't seem to figure out how to manipulate the order. I've read the documentation, but I haven't been able to get any further. The files always get concatenated in alphabetical order, and what's worse, if I use an #import command in a given stylus file, that file will get concatenated both where I've added it as well as where it would appear alphabetically.
My config.coffee file looks like this:
stylesheets:
joinTo:
'assets/stylesheets/app.css'
order:
before: [
'vendor/styles/bootstrap.less'
]
after: [
'vendor/styles/helpers.css'
]
My folder structure looks like this:
|__details.styl
|__footer.styl
|__global.styl
|__header.styl
How can I
Omit certain files that I'm manually importing?
Specify my file order, e.g. global, details, header, footer?
I've tried to change the order in the config file by trying
order:
before: [
'app/styles/global'
'vendor/styles/bootstrap.less'
]
but this yielded no change.
I know I could just rename the files to be something like a_global and z_footer, but that's obviously hacky and it also doesn't solve my file omission problem. I'd also like to take advantage of the stylus index import ability so I can better organize my styles. However, if I were to do that now, while it works from a stylus perspective, those files are also getting concatenated to app.css in the alphabetical order of their parent directory.
Files that start with _ are ignored by compilers.
Which means, you can do
#import _first
#import _second
#import _third
in your main stylus file and _first etc will be added only once to result.

How to tell the preprocessor to search for a particular folder for header files, when I say #include <xyz.h>

I have around 120 header files (.h files) , and in all of them each one includes many other header files using #include <abcd/xyz.h>, but as I kept .h files in a specific folder, preprocessor is generating filenotfound error.
I moved all the .h files to the single .C file that is calling the first headerfile.
One way to do is make #include <abcd/xyz.h> as #include "abcd/xyz" , but I need to do this in all the header files wherever there is an include statement, and there are hundreds of them.
I can't include many of them in the headerfiles section in Visualstudio because, some of the headerfiles have the same name, but they reside in different directories. (<abcd/xyz.h>,<efgh/xyz.h>).
Any way to do this?
You should add a path into "Additional include directories" in the "C++" section of the project options (the "General" tab). You can use environment variables as well as "this folder" (.) shortcut and "up one folder" (..) shortcut for this setting to not be bound to a certain directory structure.
and I can't include many of them in the headerfiles section in Visualstudio because , some of the headerfiles have the same name, but they reside in different directories.(,)
That's a pretty big problem unless the files that are including those non-uniquely named headers are in the same directory as the header files themselves.
You have no way to guarantee that the compiler will locate one header before another without modifying the #include directive itself (and adding a relative path as one example).
EDIT: It looks like Visual Studio will allow you to specify different Additional Include Directories for each source file in a project (rt-click on the source file in Solution Explorer and modify C/C++ properties). But I think this would be more work than modifying the #include directives themselves - depends on how many non-unique header filenames you have.
In the project settings (under C/C++ in VS2005/2008) there's an option for "additional include directories". You can add the folders containing your header files here, using relative paths.
You can also do this at the IDE level in Tools -> Options -> Projects and Solutions -> VC++ Directories -> Include Files. Typically this method is reserved for headers included as part of a formal library. The first option is typically preferred as it's portable (you can ship your project file to another developer and, provided you use relative/macro'd paths, they can build the project as-is).
What you're looking for is the -I flag and you give the directory...
If you have a Makefile, you should add it to the CPP_FLAGS something like that....
You can also add an INCLUDE variable to your environment variables.

Apache: SSI inside SSI

Is there a way I can include include files inside include files? (Say that five times fast!)
For example:
Inside index.html:
<!--#include virtual="/include-1.shtml"-->
Inside include1.shtml:
<!--#include virtual="/include-2.shtml"-->
So the tree looks like this: index.html <-- include_1.shtml <-- include_2.shtml
As is, this is not working on my Apache. The first include works fine, but the content for the nested include doesn't display.
As it is relevant, I am using the XBitHack on Apache 2, and I've double checked that both files are executable by the web user.
Help?
I know that this question is more than four years old, but for the benefit of people who, like me, find it thanks to StackOverflow's amazing search engine juice, here's how I made it work.
Under Apache2, you need to know this.
Relevant text:
This command inserts the text of the included file into the parsed file. SSI files may be nested, that is the included file may contain additional SSI statements (but in this case must have an .shtml suffix irrespective of the setting of XBitHack).
(Emphasis mine) For me, the solution lay in uncommenting two lines in the default httpd.conf:
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
… and changing the filename extension of the first-level included file to .shtml:
index.html
  └─┬─ include1.shtml
    └─── include2.html
Boom! Nested SSI works like a champion.
Make sure that Apache is actually trying to process the *.shtml files. Try putting
<!--#echo var="DATE_LOCAL" -->
in a *.shtml file and seeing if you get the expected results. Do you get the same result in a *.html file? If you don't see the dates in both, your configuration is off.

Resources