How to use the Features module in a 3 dev environnement?

Question: Working on a project,  making heavy use of Features, there is sometimes 3 devs for this application.
We have tried a few approaches, but when we merge our git branches it seems we often 'over-write' each other's feature changes.  Conflicts abound, breaking the feature module making it painful to use, it seems.
Features is really an awesome timesaver for configuration for one on projects, and I am quite sure there is a way to tackle this.
Is there a workflow or procedure that reduces risks of conflicts and overwrites?
Any clues on features is welcome.
Answer: Welcome to the land of Features Configuration Management, aka FCM! It is not only about Features, and not about Configuration Management (as introduced in Drupal version 8). Instead, it is a special case of Software Configuration Management, aka SCM. Mostly because Features can be considered as a code generator, whereas that generated code needs to be migrated through multiple environments. Read on for more details.
1 - Pros and cons of using Features
Advantages of using Features

Automate the deployment of changes applied to a Drupal development site to one or more target Drupal (pre-) production sites (instead of manual deployment).
Facilitates sharing (shipping) of ongoing Drupal development between Drupal developers / site builders (eg to make some View(s) created by a views expert available to a Drupal Themer working in another development site to theme that view).
Great integration with both GIT and Drush for shipping a copy of the code generated by Features (on the development site) to selected target (pre-) production sites.

Disadvantages of using Features

Avoiding Feature Conflicts and/or managing Feature Dependencies can be challenging!
It's not easy to start using Features on an existing (production) site.
Install/enable of the Features module is easy (just a module), but to learn to use Features correctly is a major challenge.

2 - Techniques for features packaging
Using Features it is up to your own imagination how to package (compose) the content of a feature. Here are some techniques that can be used for it.
A single super feature
This is a pretty simple packaging technique: everything is packaged together in a single feature (some call it the "God" feature ...). Seems easy, pretty forward, etc. But this technique also leads to "conflicts" (as explained below) more or less right away ...
A good usecase for this appears to be when creating a "Drupal distribution", where all users of it are assumed to use the same set of modules, configuration, etc. If however such distribution consists of multiple website functionalities (to not use the word "features" ...), it seems more appropriate to split such features in multiple features, as explained below.
Based on website functionality
This packaging technique creates a separated feature for each functionality of a website, such as:

Feature A = implement a "*Gallery".
Feature B = implementg a "*Blog".
Feature C = implement a "*Event Calendar".

Based on Drupal admin sections
This packaging technique creates separated features for each of the (major) admin sections of a Drupal website that is used to create the site, such as:

All required modules are contained in feature A,
All base field definitions are contained in feature B,
All content types are contained in feature C,
All permissions are contained in feature D,
All roles are contained in feature E,
All variables are contained in feature F,
All (custom) Views are contained in feature G,
All (custom) Rules are contained in feature H,
Etc.

The above list is virtually unlimited: in the end you could even think of it as 1 feature for each Drupal admin menu option ... if you want to go that far.
IMO it is also the most recommended approach to package features.
3 - Reducing the probability of conflicts in Features and/or GIT
Do not reuse fields
Quite a few conflicts seem to be caused by reusing fields among multiple content types. E.g. in content type A you have a field with machine name field_somefield, which is also used as field in content type B with the very same machine name field_somefield but which as another field type and/or some other field setting(s) that are different.
By not reusing fields among content types, you avoid running in this issue. Have a look at an interesting naming convention for the machine name of your content types and fields as shown in table of Wrapping Information Architecture and Documentation, which is part of the articles about "Relativity Model for Drupal". For more details on that refer to my answer to "How do I model content (types) from a database-centric point of view?".
Split features depending on who works on what
If multiple people are working on a single site, the amount of conflicts can be reduced by organizing (= creating separate) features based on who is working on what. An illustration of this could be as in this example:

Views goes in feature A,
Rules goes in feature B,
Charts goes in feature C,
Anything about Theming goes in feature D,

4 - Recommended Drupal environments
Everything above should help to somehow facilitate the usage of Features. However, to ensure that things will work as expected (designed), you also need to have an appropriate set of environments (logically related Drupal websites) for basically these reasons:

merge functionality provided by multiple features.
predict and resolve conflicts.
end-user testing of all merged features that are certified to not have any conflicts.

In the ideal world, these logically related Drupal websites should be configured, and used, like so:

Personal Dev Site - each website developer has a separated dev site. When some part of the development is ready to be shared with somebody else, an appropriate feature is created, which is shipped to the staging environment.
Sandbox Site - this is a Drupal environment which only contains Drupal core, used to unit test the completeness of a single feature. Should a feature, accidentally, have some unexpected dependencies (eg some module the feature depends on, which is not enabled in the Sandbox), then this is where that dependency will become clear.
Staging Site - here is where one or more features (created in a dev site) are delivered to. It could be just some hotfix for some production problem, or it could be where all development for a new release of the website is consolidated. If any conflicts between multiple features do exist, then this is the environment where they will first show up ... and need to be resolved somehow.
QA Site - after the Staging environment is considered stable, it's time to move on with the relevant features and make them available also at some higher level where they can be used for QA testing, acceptance testing, volume testing, etc. At this level you should be extremely careful in allowing any additional changes (if any). Because any such change may invalidate all prior testing efforts already completed in this environment.
Shadow Production Site - To prepare the activation in real production, you might want to first further promote the relevant features to an environment that is considered a copy (shadow) of your real production environment. If at this point during the migration process anything still breaks, then that is a red flag to revert some of your prior steps. Get it fixed, and try again, until all parties involved approve the changes.
Production Site(s) - If you completed all prior steps, then this step should be self explaining, and pretty easy. Depending on your needs, this could be a single site, or something equivalent to Drupal's Multi-sites whereas all the sites involved are running the very same versions of all features.
Baseline Site - In my experience, there are not many (if any at all) Drupal implementations where this type of site is used (also). It is simply a copy of the Production Site(s), but available to the Drupal developers, testers, etc that can be used to verify what the production sites look like, or to perform user training, etc. And any time a new development cycle is started, the components of a site that will be impacted (need to be changed) should be "copied somehow" using this Baseline Site as input, with as target a Personal Development Site.

Obviously, the above inventory of types of Drupal sites is like the ideal world. Depending on the size of your development team, and / or the available budgets to create and maintain them, not all of them may be used (or affordable). This inventory is modelled after best practises in the area of SCM, used in mostly all huge/global corporations (banks, airlines, etc).
5 - Related modules
Strongarm
The Strongarm module allows for exporting variables (of modules which store their settings in variables) with the Features module.
Node Export
The Node export module allows users to export nodes and then import it into another Drupal installation.
Role Export
The Role Export module allows roles to have machine_names and generates a unique role id (rid) based off of the machine_name. Roles can be exported with Features and get the exact same rid if imported on other sites.
Features Banish
The Features Banish module allows for completely excluding individual features components from the features UI and features exports. Here is a quote about it from its project page:

 This module is useful when there are features components that you want to make sure NEVER get exported. If you are using features for site building or deployment then you've probably ran into the issue of someone accidentally exporting timestamp variables like cron_last or update_last_check. You may also want to banish permissions for developer modules so they don't get caught up with the rest of the site permissions you want to export. Banished items will not show up in your feature module OR ANY OTHER FEATURES MODULE, so use with caution. For a central list of features that should never be exported, see https://www.drupal.org/node/2400531

BEAN
The Bean module makes your blocks exportable. Here is a quote about it from its project page:

Think of a Bean as a method to provide new types (compared to node this would be a content type) which then provides an add content interface to create as many blocks as you require (see screenshot below). The bean content can then be placed around the site just like any other block.

This module also works great in combination with the UUID and UUID Features Integration modules. This module only started as of D7, but it has been included with Drupal 8 core already. The video tutorial Drupal Bean module tutorial - using Bean Admin UI provides a great introduction to really understand the power of this module, and the kind of things you can do with it (by only using site building techniques, no custom coding involved).
Habitat
The Habitat module makes most sense in a Features-based workflow. Here is a quote about it from its project page:

In a multi-environment setup (e.g. prod, test, dev, local) there are some modules that you'd like to always be enabled or disabled on certain environments. Each time you sync a database down though you have to re-enable/disable the same modules. Worse, you get lazy and keep development modules enabled on production.
Habitat provides settings to enable or disable certain modules on each environment (habitat). Just set a variable with e.g. $conf['habitat'] = 'local'; in your settings.php file (the actual variable to use there is configurable for your current workflow). The disabling/enabling modules is done on hook_init.

6 - Recommended resources:

Community documentation about Features.
Part of this answer is based on the (amazing I think) Features debat.
Video tutorials:

Creating a Feature.
Reverting Features.
Updating Features.
Making features the right way.
Limitations of Features.

7 - Possible alternatives to using Features
If you're not able, or willing (yet), to use Features, then you may want to check to what extend the approaches/modules below may provide some type of alternative.
Manual Export/Import
These are the commonly known facilities (to avoid the word features ...) available via the admin UI, for modules such as Rules, Views, etc (incomplete list!).
Bundle copy
Some people consider the Bundle copy module as a possible alternative. It has export/import support for:

Node types.
Taxonomy.
User.
Field API fields.
Field groups.
Comment: Best answer I've ever seen.
Comment: @Pierre.Vriens - Thanks! I guess I came to the same conclusion as your excellent answer the hard way. I had tried the approach of splitting by components ( views_views, dependency, etc. ) but was having conflicts when trying to generate the feature.  I realized -> after -> that I probably needed to configure the feature to not check dependencies and ignore conflicts.
Comment: @NoSssweat Merci for the kudos ... but know that I consider it as still pretty incomplete. E.g. it hardly includes anything about the "lifecycle" of processing features, and it doesn't say a lot yet about things like impact analysis, auditing, release management, authorizations, and, and, and (another dozen of topics or so).
Answer: Merge conflicts are probably going to be a given when multiple developers are integrating their configuration into a Feature. I wrote up several guidelines for reviewing feature code, but I think the most important is this:
Only commit intended code changes.
What does this mean? This means that each developer must review code before committing. There is no "magic" to prevent unintended code changes without a developer being cautious.

Review code changes with git diff.
Make a quick diff patch using git diff > blah.patch, and manually modify the patch to only include the intended configuration changes.

Things such as "mtime", comments in view exports in the info file need not be included in the commit.
I've become quite adept at reviewing blocks of configuration code diffs over time. It is easier now to spot superfluous changes in views or panels, and a quick 10dd in vim gets rid of the change in a patch (for example).
I think "Oh, hey, I didn't change anything to do with fields, so I won't commit featurename.features.field_base.inc."

Never ever use git commit -a. This is a terrible practice that should be stricken from use. Always add and commit explicitly!
Use git rebase on local git branches to make sure the feature is most up-to-date.
A git merge strategy may also help when actually doing a merge:

git merge -s recursive -X patience (requires git 1.7+ iirc).

Finally consider adding social restrictions to developers so that a developer must have their code reviewed before merging into trunk/stable either with patch review or pull request. People will be angry about social restrictions, but they should be angry at themselves for not reviewing their code.
Comment: Better than generating a patch file is using `git add -p` to commit specific chunks only.


If a tensor space is a vector space, then why isn't a tensor a vector?

Question: On page 78 of Tensor
Analysis on Manifolds, Bishop and Goldberg state:
Let $V$ be a vector space. The scalar-valued multilinear functions with variables all in either $V$ or $V^*$ are called tensors over $V$ and the vector spaces they form are called the tensor spaces over $V$.
I thought a vector was a tensor and not the other way around. I know a tensor is a multilinear map from a set of vector spaces and dual spaces onto $\Bbb{R}$.
Is a vector a tensor or a tensor a vector? Can someone clarify this for me?
Comment: In math, a vector is an element of a vector space, so the term "vector space" is really the primary one and the term "vector" by itself comes later. There is no further content than that. (Physicists may use a different definition in terms of behavior under coordinate transformations.) If you build a new vector space from old ones then elements of the new space are vectors as well. A tensor product of vector spaces is an example of a new vector space. Calling its elements tensors is just part of remembering how they were created. But they are vectors as well.
Comment: It means a tensor product of $k$ copies of $V$ and $\ell$ copies of $V^*$. Would you rather write $a^{10}$ or $aaaaaaaaaa$?
Comment: If you start off with a vector space $V$, the standard tensor spaces created from it are $V^{\otimes k} \otimes (V^*)^{\otimes \ell}$ for nonnegative integers $k$ and $\ell$. Taking $k = 1$ and $\ell = 0$, this tensor space is just $V$, so elements of $V$ are tensors but in a *boring* way.
Comment: Thanks for replying. Why do you place the tensor product symbol in the superscript slot? That is, what does it signify?
Comment: Lol point taken. Thanks for clarifying
Answer: A tensor is a vector of the tensor space $T^{(m, n)}(V)$, which is itself forms a vector space.
A tensor space $T^{(m, n)}(V)$ is defined over a vector space $V$ as the set of functions $f$ with domain/image:
$$
T^{(m, n)}(V) = \{ f : V^m \times (V^*)^n \to \mathbb{R} \}
$$
Members of $T^{(m, n)}(V)$ are therefore of course different from members of $V$, one obvious reason is that they have the different dimensions in general: $dim(V)$ vs $dim(V) ^ {m \times n}$
Although all vector spaces of same dimension are isomorphic, the tensor space has a bit more structure than just the underlying vector space: we need to specify $m$ and $n$ for it as well. So given a arbitrary vector space $W$ it doesn't make much sense to say that members of that space are tensors unless we specify more information about which tensor space we are talking about by giving $m$ and $n$.
One identification that is natural to make is identify vectors of v of V as (0, 1) tensors over V. By definition, a (0, 1) tensor is a function T(f) that:

takes a dual vector $f$ as input, where $f$ by definition of dual space is a funcation that maps a vector v of V to a number
and outputs a number

Therefore, given $v$, we can create a (0, 1) tensor as:
$$
T(f) = f(v)
$$


Analytic functions $g$ on $|z|<1$, with $g'(1/n)=2g(1/n)$ for $n=2,3,\dots$

Question: Analytic functions $g$ on $|z|<1$, with $g'(1/n)=2g(1/n)$ for $n=2,3,\dots$
How to determine all such functions? I am thinking using Schwarz–Pick theorem but so far haven't figured out. Any ideas?
Comment: what is $\mathbb N^*?$
Answer: Hint: You have $g'=2g$ on a set with limit point in the domain. Apply the identity principle. Then consider $e^{-2z}g(z).$


Reading an xml data using phpQuery

Question: I want to read the nodes from an xml file using phpQuery..I have tried the below code but its not working ..Can anyone plz help me with the syntax of parsing xml using phpQuery....
$file = 'demo.xml'
phpQuery::newDocumentFileXML($file, $charset = 'utf-8');

$nodeElement = pq('nodes');

    $node = $nodeElement->xml();
echo '
Nodes:
';
echo '
' . htmlentities( $title) . '
';

The above code is not working .....My syntax seems to be wrong...
Comment: Clarify 'its not working'.
Comment: I meant.. 'it's not working' is not really enough information.
Comment: Dude i mentioned that the syntax may be wrong and asked for proper syntax
Comment: So what are the symptoms of your problem.. try to explain what's happening. Are you getting an error? Nothing at all?
Comment: the page is just going on loading
Comment: That doesn't make a lot of sense tbh.. Can you be more specific.. Did you mean that the page never stops loading?
Comment: @Evert I am asking whether the syntax is proper or not ???.Yes the page never stops loading
Comment: For someone who has an issue, and asking others to help him solve it.. you are not particularly friendly. So I wish you good luck solving this.
Comment: You may think the questions are silly, but they are important to help debug. For example: the fact that the browser never stops reloading is pretty critical information, as it implies there's nothing wrong with the syntax of your PHP script; but there's something different going on under the hood. I practically had to drag that out of you.
Answer: I use simplexml_load_file for most things why not use that? Where's an example using google maps api for pulling distance between 2 locations and storing the returned "text" value from the resultant xml into the $distance variable.  You can find examples of the xml as returned from google on their website.  The same can be used for your code instead of requesting a url though load a local xml file.
//create request url
                    $request_url = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=".$tslocation->TransLat.",".$tslocation->TransLong."&destinations=".$sitelocation->SiteLat.",".$sitelocation->SiteLong."&sensor=false&units=metric";
                    //perform query
                    $xml = simplexml_load_file($request_url) or die("url not loading");
                    //get distance text
                    $distance = $xml->row->element->distance->text;

Comment: do you have a reason for it having to be in phpquery? do you have any errors in your apache error.log file for why what you currently have isn't working?
Comment: phpQuery because it supports the DOM model....If i want to retrieve a particular data from a specified class in an xml , phpQuery can do it
Comment: simple xml supports the xml dom just fine. phpquery from what I understand is just a php implementation of jquery for accessing the web client side dom.  nothing that cannot be achieved with normal jquery + simple xml in alot less code and with alot less issue.

Reading an xml data using phpQuery


SAN connected through SAS with SATA disk

Question: let's have P2000 G3 with SAS Dual Controller and DL120 G6 with HP SCO3e SAS HBA cards.
1) I know it's bit dumb question, but just to be sure. The array will be filled by SATA disks. Will be the SAS connection to the host degraded to SATA performance ? I hope not ..
2) Does SAS support multipathing ? (XenServer)
Thanks.
Answer: Terribly written question, but;

In multi-user environments a single SAS disk is typically quicker than a same size/speed SATA disk due to its superior queue and cache management functions, not by a lot, perhaps onlt 10% but under heavy usage this can be as much as 50% quicker. So on a disk-by-disk basis id could be said that accessing a SATA disk over a SAS link (especially those particular SAS links as they support 4 x 6Gbps channels with those parts) could be slower than going 'fully SAS' yes.
Yes SAS supports dual pathing, but so does SATA in this configuration. Please consider that the particular disk shelf you've bought (I can't honestly call it a SAN as it's not in that configuration) support 8 single pathed hosts or 4 dual pathed ones.

I'm a huge fan of the P2000 range but have never found a use for the SAS version - what are you planning to use it for? I'm just a bit confused/concerned about any cluster functionality you may have in mind.
Comment: So, I have two possibilities, FC/iSCSI single controller with FC HBAs for 2 hosts, or SAS dualcontroller with SAS HBAs for these 2 hosts. As I would like to have dual controllers, and dual FC/iSCSI is out of my budget, I do not have any other option (MSA60 does not have any raid and so on, does it). Do you think it will be working or not ? :/ Or what do you recommend.. (array+2 hosts)
Comment: What is it you're actually trying to build here, as in functionality/operating-systems etc. ?
Comment: 2xXenServer (linux guests) with HA feature connected to the array.
Comment: So you want two or more hosts to access the same LUN at the same time then right? have you thought about how you're going to do this within the OS? i.e. what file system and locking/cluster manager and do those choices work with SAS? You need to think of these otherwise it will either not work or cause immediate and huge corruption.
Comment: Yes, the machines access the same LUN but not at the same time. If one host fails (for ex. management interface goes down) it activates host fencing  [it will be restarted so that there will be no VM running - everything done by HA feature of XenServer] , and the VMs are re-run on the second host (designated as a new master of the pool) accessing the same LUN. XenServer sees SAS HBA as FC HBA.


Solution to $u_{n+1}=u_n/n+u_{n-1}/(n-1)$

Question: What is the solution to the following recurrence relation $$u_{n+1}=\frac{u_n}{n}+\frac{u_{n-1}}{n-1}\ \forall n\geq 2$$ where $u_2=u_1=1$?
Comment: Surely your formula must be from $n=2$? Otherwise, if we start from $n=3$, we miss out $u_3$.
Comment: Yes, true @AndrewD. Thanks for pointing out that mistake. I'm editing it now.
Answer: Let $a_n=(n-1)!u_n$, and multiply the recurrence by $n!$:
$$\begin{align*}
a_{n+1}&=n!u_{n+1}\\
&=\frac{n!}nu_n+\frac{n!}{n-1}u_{n-1}\\
&=(n-1)!u_n+n(n-2)!u_{n-1}\\
&=a_n+na_{n-1}\;,
\end{align*}$$
with initial values are $a_1=a_2=1$. If you shift the index by setting $b_n=a_{n+1}$, then $b_0=b_1=1$, and the recurrence $a_{n+1}=a_n+na_{n-1}$ becomes
$$b_n=b_{n-1}+nb_{n-2}\;.$$
This is OEIS A000932, which doesn't seem to have a simple generating function or closed form, so I think it unlikely that there's a nice closed form for your sequence. The OEIS entry does have a closed form for the modified sequence in terms of several hypergeometric functions; if that's good enough for your purposes, you can simply divide it by $n!$, since $b_n=a_{n+1}=n!u_{n+1}$.


Limit Taxonomy Term references to special vocabulary

Question: I have a custom entity type with custom fields, one of them is  an entity_reference type ,
I saw this question How to create entity reference field from custom entity to specific content type , and according to it some references I googled , try the below code but it not works .
 $fields['book_cat'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Book Category'))
    ->setDescription(t('Book Category Name'))
    ->setSetting('target_type','taxonomy' )
    ->setSetting('handler','default' )
    ->setTranslatable(TRUE)
    ->setDisplayOptions('form', array(
        'type' => 'options_select',
        'weight' => -1,
        'handler_settings' => array(
            'target_bundles'=>['book_cat_agency'=>'book_cat_agency'],
            'size' => '60',
            'placeholder' => '',
        ),
    ))
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);

But not working.
my vocab name is : book_cat_agency
Answer: I see two mistake in your code, first ->setSetting('target_type','taxonomy' ) is mistake and try ->setSetting('target_type','taxonomy_term' )  and try to set handler_settings with  setSetting I mean  ->setSetting('handler_settings',['target_bundles'=>['book_cat_agency'=>'book_cat_agency']] ) (although there is a way to set handler_settings in setDisplayOptions  )
and finally try  following
$fields['book_cat'] = BaseFieldDefinition::create('entity_reference')
   ->setLabel(t('Book Category'))
   ->setDescription(t('Book Category Name'))
   ->setSetting('target_type','taxonomy_term' )
   ->setSetting('handler','default' )
   ->setSetting('handler_settings',['target_bundles'=>['book_cat_agency'=>'book_cat_agency']] )
   ->setTranslatable(TRUE)
   ->setDisplayOptions('form', array(
       'type' => 'options_select',
       'weight' => -1,
       'settings' => array(
           'size' => '60',
           'placeholder' => '',
       ),
   ))
   ->setDisplayConfigurable('form', TRUE)
   ->setDisplayConfigurable('view', TRUE);


Process same file in two threads using ifstream

Question: I have an input file in my application that contains a vast amount of information. Reading over it sequentially, and at only a single file offset at a time is not sufficient for my application's usage. Ideally, I'd like to have two threads, that have separate and distinct ifstreams reading from two unique file offsets of the same file. I can't just start one ifstream up, and then make a copy of it using its copy constructor (since its uncopyable). So, how do I handle this?
Immediately I can think of two ways,

Construct a new ifstream for the second thread, open it on the same file.
Share a single instance of an open ifstream across both threads (using for instance boost::shared_ptr<>). Seek to the appropriate file offset that current thread is currently interested in, when the thread gets a time slice.

Is one of these two methods preferred?
Is there a third (or fourth) option that I have not yet thought of?
Obviously I am ultimately limited by the hard drive having to spin back and forth, but what I am interested in taking advantage of (if possible), is some OS level disk caching at both file offsets simultaneously.
Thanks.
Answer: Two std::ifstream instances will probably be the best option here.  Modern HDDs are optimized for a large queue of I/O requests, so reading from two std::ifstream instances concurrently should give quite nice performance.
If you have a single std::ifstream you'll have to worry about synchronizing access to it, plus it might defeat the operating system's automatic sequential access read-ahead caching, resulting in poorer performance.
Comment: This is true only if the original access was random. If the original access was sequential then the random access induced by the two threads would make things worse.
Comment: Indeed.  He explicitly states that reading it sequentially is not sufficient.  In this case where he must perform random access, two concurrent requests are going to be better.
Answer: Between the two, I would prefer the second. Having two openings of the same file might cause an inconsistent view between the files, depending on the underlying OS.
For a third option, pass a reference or raw pointer into the other thread. So long as the semantics are that one thread "owns" the istream, the raw pointer or reference are fine.
Finally note that on the vast majority of hardware, the disk is the bottleneck, not CPU, when loading large files. Using two threads will make this worse because you're turning a sequential file access into a random access. Typical hard disks can do maybe 100MB/s sequentially, but top out at 3 or 4 MB/s random access.
Comment: Note that he asks about _reading_ a file with `std::ifstream`.  He won't have to worry about inconsistent views in that case.
Comment: @Cory: That's true in this particular case. I'm thinking more generally.
Answer: Other option:

Memory-map the file, create as many memory istream objects as you want.  (istrstream is good for this, istringstream is not).
Comment: @awoodland: it is. And it's deprecated in C++0x too. Since deprecated implies, "required to be present in any conforming implementation", we're good to go ;-) An alternative is to rewrite the code to operate directly on the mapped array, rather than via a stream, but using `istrstream`, which necessarily is read-only, is pretty harmless.
Comment: Does your compiler need to support a certain C++ standard to use this?
Comment: @J T: Memory mapping is not covered by the standard. You'd have to use whatever calls it would take on your platform. On POSIX that'll be `mmap`, on Windows that'll be `CreateFileMapping` + `MapViewOfFile`
Comment: Memory mapping is not part of the standard.  Boost Interprocess has cross-platform memory mapping support, though.
Comment: I thought [std::strstream was deprecated](http://stackoverflow.com/questions/2820221/why-was-stdstrstream-deprecated])?
Answer: It really depends on your system.  A modern system will generally read
ahead; seeking within the file is likely to inhibit this, so should
definitly be avoided.
It might be worth experimenting how read-ahead works on your system:
open the file, then read the first half of it sequentially, and see how
long that takes.  Then open it, seek to the middle, and read the second
half sequentially.  (On some systems I've seen in the past, a simple
seek, at any time, will turn off read-ahead.)  Finally, open it, then
read every other record; this will simulate two threads using the same
file descriptor.  (For all of these tests, use fixed length records, and
open in binary mode.  Also take whatever steps are necessary to ensure
that any data from the file is purged from the OS's cache before
starting the test—under Unix, copying a file of 10 or 20 Gigabytes
to /dev/null is usually sufficient for this.
That will give you some ideas, but to be really certain, the best
solution would be to test the real cases.  I'd be surprised if sharing a
single ifstream (and thus a single file descriptor), and constantly
seeking, won, but you never know.
I'd also recommend system specific solutions like mmap, but if you've
got that much data, there's a good chance you won't be able to map it
all in one go anyway.  (You can still use mmap, mapping sections of it
at a time, but it becomes a lot more complicated.)
Finally, would it be possible to get the data already cut up into
smaller files?  That might be the fastest solution of all.  (Ideally,
this would be done where the data is generated or imported into the
system.)
Comment: It was a toss up for your solution and the one I selected. +1
Answer: My vote would be a single reader, which hands the data to multiple worker threads.
If your file is on a single disk, then multiple readers will kill your read performance. Yes, your kernel may have some fantastic caching or queuing capabilities, but it is going to be spending more time seeking than reading data.
Comment: There'll be just as much seeking on the disk when he seeks in the file.  And constantly seeking will defeat any read-ahead strategies the OS might be using.
Comment: @james-kanze Reading a file sequentially from 2 different processes or threads will have a whole lot more disk seek time than a single process or thread seeking around the file. An analogy: Think of 2 people reading from the same book.
Comment: Ok, but in your book analogy, if a single person wanted to read chapters 4 and 8 simultaneously, wouldn't he have to flip the pages back and forth just as much?
Comment: @J-t: Yes, but read OP's post: `..Reading over it sequentially..` Even if he wanted to read from chapter 4 and 8 at the same time, he'll still only be reading from one chapter at the any one time. He can decide when to flip to the other chapter.
Comment: "Reading over it sequentially ... is not sufficient"


A de-Morgan law for Heyting lattices

Question: Please show that $\lnot(a\vee b) = \lnot a\wedge \lnot b$ for any Heyting algebra. [Corrected: exchanged $\vee$ and $\wedge$.]
(I prefer to receive the answer is dual terminology, that is about co-Heyting algebras.)
Comment: Are you sure about the question? it is not a theorem in Heyting Logic
Comment: @Willemien: It is exercise (i) in  I.1.11 of "Stone Spaces" book
Comment: @Willemien: I confused $\vee$ and $\wedge$. Sorry
Comment: It seems that there is an error in this question: see https://groups.google.com/forum/#!topic/sci.math/Gqoyc_2IdYM
Comment: See [here](http://math.stackexchange.com/a/120209/5191) for the correctness of de Morgan's laws in intuitionistic logic.
Comment: @ZhenLin: How to transfer the proof from intuitionistic logic to co-Heyting lattices defined inside classic logic?
Comment: It is well-known that there is a sound interpretation of propositional intuitionistic logic in Heyting algebras, just like there is a sound interpretation of classical logic in boolean algebras.
Answer: I will prove that the corresponding formulae are logically equivalent in intuitionistic propositional logic.
First, suppose $\lnot (a \lor b)$; we wish to prove $\lnot a \land \lnot b$. Assume $a$. Then $a \lor b$, which is a contradiction, so we discharge $a$ and deduce $\lnot a$. Similarly, we may deduce $\lnot b$. Thus $\lnot a \land \lnot b$.
Conversely, suppose $\lnot a \land \lnot b$. Assume $a \lor b$. Since $\lnot a$ and $\lnot b$, we use $\lor$-elimination to deduce that $a \lor b \to \bot$, i.e. $\lnot (a \lor b)$.

Here is the proof spelled out in the language of Heyting algebras. To show that $x = y$ in a poset, it is enough to show that both $x \le y$ and $y \le x$.
First, notice that $a \land \lnot (a \lor b) \le (a \lor b) \land \lnot (a \lor b) \le \bot$, so $a \land \lnot (a \lor b) \le \bot$, so $\lnot (a \lor b) \le \lnot a$. Similarly, $\lnot (a \lor b) \le \lnot b$. It follows that $\lnot (a \lor b) \le \lnot a \land \lnot b$.
On the other hand, $\lnot a \land \lnot b \land (a \lor b) = (\lnot a \land \lnot b \land a) \lor (\lnot a \land \lnot b \land b)$ by the distributive law, and $\lnot a \land \lnot b \land a = \lnot a \land \lnot b \land b = \bot$, so $\lnot a \land \lnot b \land (a \lor b) = \bot$. Thus, $\lnot a \land \lnot b \le \lnot (a \lor b)$.
Comment: The definition of $\lnot a$ is $a \to \bot$, so by the deduction theorem, to prove $\lnot a$, it is enough to show that a contradiction follows from $a$. Now, once we have shown that two formulae are logically equivalent in propositional intuitionistic logic, it follows that the corresponding equation is true in all Heyting algebras.
Comment: I don't understand something: Do you use **contradiction** in intuitionistic propositional logic?
Comment: Sure. That's the only way to prove a negative.
Comment: I'm finally confused. Could you clear? (especially whether the original formula is true in all Heyting algebras)
Comment: Yes, the original equation is true in all Heyting algebras.
Comment: And where is the proof?
Comment: Also clarify usage of contradiction in your proof about intuitionistic logic
Comment: Maybe I ask too much, but please provide me with a proof for Heyting algebras inside classical logic, without referring to intuitionistic logic. I want to put this into my book and need a simple direct proof
Comment: @porton: there is now an extended comment about the word **contradiction** at http://math.stackexchange.com/questions/915803/

A de-Morgan law for Heyting lattices


IndexedDB - search index event.target.result always null

Question: I can't figure out what's wrong with this snippet of code. I have an indexedDB instance. The keyPath is auto-generated. I can successfully add objects to the DB and get all objects in the DB, but I can't successfully search for an object in an index I created.
See my jsfiddle: http://jsfiddle.net/R5ngM/13/
Comment: I updated the code to confirm that the index "lname" is successfully created: http://jsfiddle.net/R5ngM/16/
Comment: thanks for including a fiddle. i'll take a look
Answer: Haven't nailed it perfectly yet but the issue seems to be that you're opening the cursor on your object store, rather than the index. With the default keyPath that works fine but it won't work when you're trying to use a secondary index.
What I think you're looking to do should look like:
    var request = null;
    if ( null === index || 'undefined' === typeof index ) {
        request = transaction.openCursor( keyRange );
    } else {
        request = index.openCursor( keyRange );
    }
    request.onsuccess = on_success;

UPDATE: I spent a lot of time looking in the wrong place after finding the above issue with the index cursor. Here's the issue: The object you're storing is an array not an object literal.
I was looking into the object you were storing and noticed this:
        var entry = '
'+row[0].fname+' '+row[0].lname+'
';

See how you're accessing the first element of the row array? You're storing an array. Your keypath (and me) assumed an object was stored. I believe it's possible to have an index on an array but in any case your keyPath is off.
Here's a largely-similar chunk of working code. I mucked it up a bit while debugging but you'll get the gist. (It's a nice snippit so if you don't mind, I'll use it as the base of other StackOverflow examples later on.)
Keep the cursor on the index as explained in my answer above. Then change to this line:
var entry = '
'+row[0].fname+' '+row[0].lname+'
';

And the change this:
var newUser = [{fname:$('#fname').val(),lname:$('#lname').val()}];

To this:
var newUser = {fname:$('#fname').val(),lname:$('#lname').val()};

Comment: Your code won't work in FF because it's the Dec 2011 version of the IDB API and not the latest. The difference is that for DB install the former uses a `setVersion` request (what you have) and the latter uses an `onupgradeneeded` callback. Try looking at my WIP library if you're having issues. Library: https://github.com/editor/InDB/blob/master/indb.dev.js Example app skeleton: https://github.com/editor/InDB/blob/master/indbapp.dev.js
Comment: None of my attempts are returning a `IDBCursorWithValue` object yet they all return something in `onsuccess` and no `onerror`s. I'm leaning toward the same conclusion but the question is why?
Comment: I opened a cursor on the index to try to see the contents, but it's null. http://jsfiddle.net/R5ngM/17/ I wish jsfiddle had line numbers. I guess I just have an empty index...
Comment: I just tried the latest version of FF to see if my broswer fixes were bad and FF doesn't seem to recognize any attempt I make to initialize indexedDB even though I'm using examples from mozilla docs. This is lame.
Comment: Note that in the event object it's saying `returnValue: true`
Comment: You're awesome. I thought it was weird I could only get the value with row[0].lname not row.lname, but completely missed those extra brackets. Thanks a ton. That code is actually the best example code I've seen yet -- or will be until the specs change again :)
Comment: thanks! i've yet to clean up & package my InDB library, but in the meantime it's a pretty good example and covers most bases. better, i've been building apps on top of it to make sure it works from a developer's perspective and it seems to be teaching me a lot about a) how IDB works and b) when it should be used and not used. in any case, two favors: 1) join the `firstname.lastname@example.com` group if you can so we can spread the good word and 2) star this chrome issue so we can see their support for the new IDB spec come to pass http://code.google.com/p/chromium/issues/detail?id=108223
Answer: It must also be noted that the above issue can even arise when you open a cursor on the index. If you open the cursor on index and still you always get null you should double check the data type that you created the index on and the the data type on which you're creating your index cursor on. In my case I'd created the index on string data-type and was opening a cursor on the index with int and it was driving me crazy.


DIY: automate cloning of Xen VMs, gold templete?

Question: looking for DIY way without commercial tools like XenServer LabManager product.
Answer: Check out the libvirt based tools, virt-clone can copy them without issue and if you need to code something there are libvirt code for a lot of languages. I use the perl bindings for an inhouse project and they are quite solid.
Comment: does libvirt support Xen, please suggest any tools that you are aware of
Comment: yes libvirt supports Xen, KVM, VMWare and Virtualbox - its pretty powerful. Libvirt's frequently used tools are: virt-clone, virsh, virt-install, and virt-manage which is a GUI that allows you to do all of this.
Comment: thanks, correction virt-manager is the GUI not virt-manage


iOS - Thread1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

Question: I know questions like this have been asked on here before but they are not really related to the same problem. First of all I am very new to Swift and Xcode. So, I am creating a simple notes app and the error I am trying to come across is the one that is highlighted in the image attached to this question. The error is this one for the ones who can't view the image: "Thread1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)".
I am at a point where I am trying to get the prepareForSegue function but I do not know what is causing this error as I do not understand it. Could someone people help or advise on how I could fix this error. Many thanks in advance.
Comment: try debugging to see what is causing the problem, navigationItem might be nil
Comment: or, (in addition to luk2302 comment) the index `self.selectedIndex` present an index that does not exist for the object `arrNotes` (i.e. out of bounds). Try some "manual" debugging, e.g. writing out the index to console (`print("\(self.selectedIndex)")`)
Comment: @luk2302, `navigationItem` can't be `nil`.  It isn't optional, and it is created the first time the property is accessed.
Comment: @vacawama even before the view is loaded? Was not sure about it - does not change the rest of the statement regarding OP: debug it.
Answer: You have to make sure that NotesViewController do have the UINavigationController embedded at that. Because that property refers to the existing navigationItem from UINavigationController. Otherwise, that line will return nil and that's the reason why it crashes.
If you don't want to embed an UINavigationController, you can just drag and drop Navigation Bar to make one in the Storyboard.


Modulo equation, retrieve K from d

Question: Here's an equation:
d is the multiple inverse of 3 modulo K.

Assuming I have d, can I find K?
Also, K is not necessarily prime.
Thanks!
Comment: This question appears to be off-topic because it a purely mathematical question and belongs at [math.se]
Comment: and what you tried so far?
Comment: I've tried brute force, with different d's. I can't find any patterns that occur over and over, which is quite disturbing. Perhaps i'm missing some number's theory lemma or some other Group's algebra rule.
Comment: How about `K = 3*d - 1`?
Comment: This really has nothing to do with programming, it is suitable for math.stackexchange.com not here.
Comment: I agree with @AliAmiri, this is not an algorithm question, since it doesn't actually discuss an algorithm; it's a math question all the way.
Answer: You know that
d*3 = 1 (mod K)

this means
d*3 = 1 + n*K

independently of K this however means
d*3 = 1 (mod n)

i.e. that d is the inverse of 3 modulo n too, thus the answer is in general not unique (actually you can use any divisor of nK as answer).
Comment: Yes, this is correct. The question is a result of a different question regarding RSA Algorithm. I have m=(p-1)(q-1), p,q are primes s.t N=pq. e is relatively prime to m, i.e gcd(e,m)=1 (makes sense because e=3), d is the multiple opposite of e modulo m. So the question was assuming e=3 and I get a hold of d, I need to show that I can factor N (that is find q,p). So i thought, if I could find m via e(3) and d, I can easily find p,q and solve it. Perhaps there's another way to factor N?

Modulo equation, retrieve K from d


True-False condition inline on HTML element (checkbox)

Question: I have this code:
<input type='checkbox'>

I want to make conditional using jQuery, for example, if data[1].condition is true, then set it checked, if not then not.
May be something like:
<input type='checkbox' + if data[1].condition is false, unchecked + "'>

<input type='checkbox' + if data[1].condition is true, checked + "'>

Is there a way to set it inline? Something like:
<input type='checkbox' + data[1].condition | checked + "'>

Comment: What templating language are you using? You can't do this in HTML only.
Comment: Are you using any JS library or JS at all?
Comment: I'm confused... are you trying to avoid JS or jQuery?
Answer: Simple answer: No!
You cannot do this using HTML and JS the way you are using it. However, if you use a templating library like EJS then it can be done inline as you want to.
<input type="checkbox" <%= data[1].condition ? 'checked' : '' %> />

The other option is to use JS/jQuery to set the property using a script as done by Brad above.
Answer: There's not really a way to do this inline.
Using jQuery...
if(data[1].condition === false){
    $('input').removeAttr('checked');
} else {
    $('input').prop('checked', true);
}


Skip recordset in loop and continue to next

Question: I inherited an Access program that reads Excel files in a directory and brings them in to Access in a For/Each Ofile loop using DoCmd.TransferSpreadsheet acLink and Set rs1=db.openrecordset.
It then goes into a loop:  Do While not rs1.EOF.
In the loop it immediately checks the first two fields (ID and ID2) for correct formatting.
The previous code would just cancel out of the entire loop if there were any errors in the formatting and skip to the top of the For/Each loop and read the next spreadsheet.
I would like to test those two fields but skip to the top of the Do While loop if there is no error.  I can't seem to do this.  So I want to skip the recordset that is in error but read the next one.
My code is below.  I've skipped the For/Each loop since it just reads the next Excel file.  The following code is within the For/Each loop.
set rs2 = db.openrecordset("tblIn_Access")

source="C:\Documents\Test_for_import\" & oFile.name
doCMD.TransferSpreadsheet acLink, 10, ofile.name, source, true

Set rs1=db.openrecordset("Select * from " & ofile.name & " ;")

Do While not rs1.eof
   IDVal=rs1.fields(0).value
   ID2Val=rs1.fields(1).value

   if len(idVal) < 9 then
       'Here is where I want to stop and read the next record in the spreadsheet.
       ' I don't want any more processing to occur
   if left(id2Val) = "H" then
       'This is another case when I want to stop and read the next record
       ' and not do any more processing on the record

   'If these two errors do not occur then I want to continue with the next record
   'There is a lot of data manipulation here to get fields in the right format.
   ' Once they are correct I add the values to a table in Access
 rs2.AddNew
 rs2.("MBR_ID")=idval
 rs2.("ORD_ID")=id2val
 rs2.("DATE_IN")=dateinval
 rs2.("DATE_OUT")=dateoutval
 rs2.Update
 rs2.movenext

 rs1.movenext

Loop

I can't get the processing to stop on the first two fields and go back and read the next record if they are not correctly formatted.  The only thing I've been able to do is what the code originally did, stop and read in the next Excel sheet.  There is a lot of manipulation in the code following the checks on ID &  ID2 but I only want that code to run if the two fields are in the proper format.
Answer: This is time for the otherwise unused 'GOTO command.
set rs2 = db.openrecordset("tblIn_Access")

source="C:\Documents\Test_for_import\" & oFile.name
doCMD.TransferSpreadsheet acLink, 10, ofile.name, source, true

Set rs1=db.openrecordset("Select * from " & ofile.name & " ;")

Do While not rs1.eof
   IDVal=rs1.fields(0).value
   ID2Val=rs1.fields(1).value

   if len(idVal) < 9 then GOTO SkipRecord

   if left(id2Val) = "H" then GOTO SkipRecord

 rs2.AddNew
 rs2.("MBR_ID")=idval
 rs2.("ORD_ID")=id2val
 rs2.("DATE_IN")=dateinval
 rs2.("DATE_OUT")=dateoutval
 rs2.Update
SkipRecord:
 rs2.movenext

 rs1.movenext

Loop

Comment: Please don't use `GoTo` instead of a normal conditional statement. See things like [this post](https://stackoverflow.com/q/3517726/7296893). You can just as easily use `End If`. And you've even used it wrong, it's `SkipRecord:` and not `:SkipRecord`.
Comment: Shows how much I use GoTo doesn't it.


Machine Learning to filter similar loess curves from a large dataset

Question: I think I have a good dataset to apply machine learning.
I have a bunch of scatter plots and I generated a loess for each. Each loess is stored as a series of Y coordinates that correspond to X coordinates in a dataframe. All X coordinates are identical (1-34) Some of the loess curves are "desirable" - or what I would want to filter out, some are not.
So I looked through and found about 50 "ideal" loess curves. Each is a dataframe containing an X and Y column with a third column containing the Identifier.
in this case, CpG is the identifier, SmoothRange is the loess Y and AVGMOrder is the loess X.
<code># A tibble: 34 x 3
   CpG        SmoothRange AVGMOrder
   <chr>            <dbl>     <int>
 1 cg21119901      0.0898         1
 2 cg21119901      0.0898         2
 3 cg21119901      0.0898         3
 4 cg21119901      0.0898         4
 5 cg21119901      0.0898         5
 6 cg21119901      0.0898         6
 7 cg21119901      0.0898         7
 8 cg21119901      0.0676         8
 9 cg21119901      0.0676         9
10 cg21119901      0.0676        10
</code>
I have about 50 of these to use for training and about 20,000 to filter through to find "similar" loess curves.
I started by trying to adapt this dataset to a simple caret vignette:
https://machinelearningmastery.com/machine-learning-in-r-step-by-step/
The problem is, I get stuck very quickly.
the "createDataPartition" step is proving to be difficult to these "sets of loess curves".
So I have two questions here really,
1) Will this Vignette help me filter out the loess curves that best matches my dataset?
2) How do I make validation and training datasets for this type of data?
<code># create a list of 80% of the rows in the original dataset we can use for training
validation_index <- createDataPartition(unique(GoodCpGs$CpG), p=0.80, list=FALSE)

# select 20% of the data for validation
validation <- unique(GoodCpGs[-validation_index,])

# use the remaining 80% of data to training and testing the models
dataset <- GoodCpGs[validation_index,]
</code>
in case you are confused, I have a few photos that might help explain.
TL;DR: I have a lot of curves. Some look like the first, some look like the second. I need to figure out how to only select the curves that look like the first photo. I have a dataframe that contains all of the coordinates to graph. Is there a machine learning vignette or book that can help me out?
Photo 1: a few examples of Good "Preferred" loess curves
Photo 2: One example of a loess curve to be filtered out
Comment: Please show your own thoughts and include a TL;DR. – *From Review*
Answer: EDIT: UPDATE: It worked. I am retraining the model to optimize this. K nearest neighbor seems to work the best. I hope this might help someone one day.
I have come up with a way to approach this issue that is compatible with caret.
The line will be split into 5 groups (see photos above). A slope will be determined for each group. The groups will be the observations for each CpG.
From there, the slopes per each group are used to define wether the line is "preferred" or "not preferred".
I will be trying to set this up over the next few days and will post my results.


Drupal 7, Looking for a module that can geo-locate a user and feed them specific data?

Question: I'm trying to build a site where I can geo-locate anonymous users when they visit the site and feed them the appropriate data.
Example: I want to display a certain block if the anonymous user's IP is located within 100 miles radius of NYC.
Is there a module that can plug into Rules as a condition and geo-locate anonymous uses?
Answer: Smart IP module (https://drupal.org/project/smart_ip) will do the job. It will locate the visitor based on his/her IP address. Anything better than that (e.g. street address) requires Device Geolocation, which comes as a submodule of Smart IP.
Comment: just what i needed! thx


How can I deploy Windows Server 2003 with the latest service packs across my forest?

Question: I have a number of servers running different NOS and I would like to get them all running the same standard platform. I have chosen Windows Server 2003 as I have some spare licences for it and it seems mature enough now. I have had issues with Windows Server 2008.
Is there a way to get an installation that will have all the latest service packs and updates on it ready to install so I don't have to download updates again for each server?
Comment: I would be very wary of rolling out Server 2003 onto production networks. It's 10 years old. There's also Server 2008 R2 which is much newer than 2008, and later this year Server 2012. I'd suggest investing time into looking into the "issues" you've had rather than spending time on a really, really out-dated OS.
Comment: The 2008 "issue" I am having is when trying to login to the server it gives me the not part of the trusted domain - I have previously also seen this on workstation logging in to the domain to repair I have had to add them again to the domain but I can not add the domain controller to the domain I can not even login to do anything to it.
Answer: Install 2003 on your server, or a Hyper-V VM, update it with the latest security fixes and SP's, then simply image it ready to roll out to all your other servers. ImageX is the Windows tool used for this, plenty of info about it online - but basically it requires booting into a PE environment, imaging the drive/s, booting into PE on the servers you want to blow the image onto, and running imagex /apply .
A technet article for example: http://technet.microsoft.com/en-us/library/cc722145(v=ws.10).aspx
Comment: Thanks I didn't realise that there was an option similar to Norton Ghost available by Microsoft. :-)
Answer: This scenario explains how to create an integrated installation of Windows Server 2003 and the corresponding service pack in a shared distribution folder on a network. This integration is called "Slipstreaming".
The integrated process installs the service pack during Windows 2003 Setup, so when the setup process is done, you'll have the OS + SP in one operation.
Important: Do not update Windows 2003 integrated with a service pack in a shared distribution folder if there are users who are still using a previously installed integrated version in the same shared folder.
The Slipstreaming process
Prerequisites
Before we begin anything, you'll need to have a few things:
Installation CD of Windows Server 2003.
Service Pack 1 for Windows Server 2003
Download Windows Server 2003 SP1 Network Installation (329mb)
Lamer Note: This guide is based on the English versions of Windows Server 2003, and of their corresponding Service Packs. If you're using a different localized build of Windows, you will need to find the right version of SP for your build.
At least 800MB (for Windows Server 2003 SP1) of free space on your hard drives (you can later delete these files).
A CDR/CDRW drive, CD burning software and (This is actually only optional, but if you want to burn the resulting slipstreamed Windows Server 2003 you'll need it).
To create an integrated installation of Windows Server 2003 and the service pack:
Connect to the network or computer on which you want to create the distribution folder.
In the shared folder on the network, create a distribution folder for the Windows Server 2003 installation files. For example, to create a distribution folder named Win2003\i386, type the following:
mkdir C:\Win2003\i386
Lamer Note: This is only an example. You can obviously use any drive letter or any folder name you want, just make sure your partition has enough free space.
Ensure only the system administrator has full access to this folder. Other users should have only read and execute permissions.
Insert your original Windows Server 2003 CD into the CD-ROM drive, and then copy the contents of the CD to the distribution folder that you created in step 2. For example, to copy the installation files and folders from the Windows Server 2003 CD in the CD-ROM drive (E:) to the distribution folder named Win2003\i386, type the following:
xcopy E:\i386 C:\Win2003\i386 /e
Lamer Note: This is only an example. Substitute E: with the drive letter of YOUR CD drive, and C:\Win2003\i386 with YOUR folder settings.
Another Lamer note: You can also drag and drop the folder's content.
Extract the service pack source files from the downloaded SP file and put them in a folder you choose on your hard disk. For example, if you've downloaded SP1 for Windows Server 2003 to a folder called C:\Win2003SP1 then type the following:
C:\Win2003SP1\WindowsServer2003-KB889101-SP1-x86-ENU.exe /x
Note: You can use "-x" instead of "/x" if you want.
In the Choose Directory For Extracted Files box, type
C:\Win2003SP1
Lamer Note: This is only an example. Substitute the path with the settings.
Another note: It will be easier for you if you chose a folder name that has no spaces in it. If you do use spaces, make sure you enclose it in quotation marks, i.e. "folder name" from now on through the entire guide.
After you've extracted the files you can apply the service pack to the Windows Server 2003 installation files located in the folder named C:\Win2003\i386 by typing the following:
C:\Win2003SP1\i386\Update\Update.exe -s:C:\Win2003
Lamer Note: Notice there IS a space between the "-s" and the "Update.exe". Also, notice there is NO space between the "-s:" and the path of the installation files folder.
Another Note: You can use /integrate: instead of the /S:.
Note: You do NOT need to specify the i386 folder in the path. The slipstreaming process will automatically look for it in the folder root.
Take a look at the folder's properties, it should be approximately 532mb in size.
You can now deploy Windows Server 2003 to your users' computers from the shared distribution folder in either attended or unattended Setup mode. Alternatively, you can burn a CD containing the files from the distribution folder. During the standard installation process, Windows Server 2003 Setup (Winnt.exe or Winnt32.exe) installs the updated operating system with the service pack already applied.


Installing TinyMCE Text Editor

Question: I followed this video tutorial in youtube for installing TinyMCE Editor in drupal. Below are the steps I did.
1. Downloaded and installed the updated WYSIWYG 7.x-2.2, IMCE 7.x-1.9 and IMCE Wysiwyg API bridge 7.x-1.0 succesfully.

2. Downloaded TinyMCE and placed it on `htdocs\drupal\sites\all\libraries` succesfully.

3. Installed TinyMCE unsuccesfully.

I refresh drupal's page and still gets the 'Not installed.' message.

I suspect the path may be wrong/different from the image above. The actual path in my computer is sites\all\libraries\tinymce\js\tinymce\tinymce.min.js
I downloaded TinyMCE here. Where did I go wrong?
Comment: please use the version 3.5.x to work properly. I hope it will work.
Comment: Hi @Aliyah, which version of the TinyMCE  you are using like 4.x or 3.x?
Comment: @PankajSachdeva TinyMCE 4.2.7 :)
Comment: Have you tried just changing the folder names to match the correct path?
Answer: There might be TinyMCE version issue with 4.7.x. Once I have facing the same problem. Then I uses the version 3.5.x of TinyMCE and its worked fine for me.
I hope it will work.
Answer: I had to do quite a bit of work to get WYSIWYG to work properly. While I preferred TinyMCE, I ended up using CKeditor 4.4.4 after it was all said and done, since I am using "Footnotes" Add-on. The setting for this editor were much easier to configure and get working.
Good documentation on this is easy to find and troubleshoot: http://ckeditor.com/
I ended up adding the editor the Libraries folder and changed settings in the modules folder to point to the file directory that was needed. It's been over a year since I did this and I changed things so many times that I can't remember what was right or wrong.
The end result is, it's nice having a WYSIWYG that works, that I haven't had to mess with for over a year.

Installing TinyMCE Text Editor


How to redirect System.out and System.err to tinylog logger?

Question: I am trying to use tinylog but can't figure out how to redirect System.out and System.err to the logger. With log4j2, I did it like this (from java code):
System.setErr(IoBuilder.forLogger(LogManager.getRootLogger()).setLevel(Level.ERROR).buildPrintStream());
System.setOut(IoBuilder.forLogger(LogManager.getRootLogger()).setLevel(Level.INFO).buildPrintStream());

I assume I should use same mechanism (System.setOut and setErr), however I'm not sure what is the right way to do it. I've read the online documentation but could not find any answer to my question (which is strange, since this is such a basic functionality that any logger must support in my opinion).
Any ideas?
Answer: I solved the problem myself, not sure if my solution is the best, but anyway. I introduced these two methods:
    /** Redirects all writing to System.out stream to the logger (logging messages at INFO level). */
    public static void redirectSystemOut() {
        System.setOut(new PrintStream(new LineReadingOutputStream(Logger::info), true));
    }

    /** Redirects all writing to System.err stream to the logger (logging messages at ERROR level). */
    public static void redirectSystemErr() {
        System.setErr(new PrintStream(new LineReadingOutputStream(Logger::error), true));
    }

As far as LineReadingOutputStream class goes, I found it here: Java OutputStream reading lines of strings
One final element of this solution is creation of custom console writer, since the default one outputs everything to System.out / System.err, and that would create an infinite loop. The trick is to wrap the two streams and send strings to them. This is the code of my class that I call "IsolatedConsoleWriter" and has to be registered via META-INF (as described in the tinylog docs):
package com.betalord.sgx.core;

import org.tinylog.Level;
import org.tinylog.core.ConfigurationParser;
import org.tinylog.core.LogEntry;
import org.tinylog.core.LogEntryValue;
import org.tinylog.provider.InternalLogger;
import org.tinylog.writers.AbstractFormatPatternWriter;

import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

/**
 * Console writer based on org.tinylog.writers.ConsoleWriter class, with one difference: this one
 * doesn't write logs to System.out/err but rather to our own streams, that output to the same system
 * streams but wrapped. This enables us to redirect System.out/err to the logger (if we were to use
 * normal console writer, we would create an infinite loop upon writing to System.out(err).
 *
 * Comes as a solution to this problem:
 * https://stackoverflow.com/questions/75776644/how-to-redirect-system-out-and-system-err-to-tinylog-logger
 *
 * @author Betalord
 */
public class IsolatedConsoleWriter extends AbstractFormatPatternWriter {
    private final Level errorLevel;
    private final PrintStream outStream, errStream;

    public IsolatedConsoleWriter() {
        this(Collections.<String, String>emptyMap());
    }

    public IsolatedConsoleWriter(final Map<String, String> properties) {
        super(properties);

        // Set the default level for stderr logging
        Level levelStream = Level.WARN;

        // Check stream property
        String stream = getStringValue("stream");
        if (stream != null) {
            // Check whether we have the err@LEVEL syntax
            String[] streams = stream.split("@", 2);
            if (streams.length == 2) {
                levelStream = ConfigurationParser.parse(streams[1], levelStream);
                if (!streams[0].equals("err")) {
                    InternalLogger.log(Level.ERROR, "Stream with level must be \"err\", \"" + streams[0] + "\" is an invalid name");
                }
                stream = null;
            }
        }

        if (stream == null) {
            errorLevel = levelStream;
        } else if ("err".equalsIgnoreCase(stream)) {
            errorLevel = Level.TRACE;
        } else if ("out".equalsIgnoreCase(stream)) {
            errorLevel = Level.OFF;
        } else {
            InternalLogger.log(Level.ERROR, "Stream must be \"out\" or \"err\", \"" + stream + "\" is an invalid stream name");
            errorLevel = levelStream;
        }

        outStream = new PrintStream(new FileOutputStream(FileDescriptor.out), true);
        errStream = new PrintStream(new FileOutputStream(FileDescriptor.err), true);
    }

    @Override
    public Collection<LogEntryValue> getRequiredLogEntryValues() {
        Collection<LogEntryValue> logEntryValues = super.getRequiredLogEntryValues();
        logEntryValues.add(LogEntryValue.LEVEL);
        return logEntryValues;
    }

    @Override
    public void write(final LogEntry logEntry) {
        if (logEntry.getLevel().ordinal() < errorLevel.ordinal()) {
            outStream.print(render(logEntry));
        } else {
            errStream.print(render(logEntry));
        }
    }

    @Override
    public void flush() {
        outStream.flush();
        errStream.flush();
    }

    @Override
    public void close() {
        outStream.close();
        errStream.close();
    }
}

So this writer is exact copy of ConsoleWriter, it add only two fields: errStream and outStream.
So, putting all of these elements together, I managed to achieve what I wanted - all System.out.println() and similar calls are rerouted to my logger, which formats all the data according to the defined rules (I actually use several writers - isolated console, as shown here, then the rolling file one, the "normal" file one, and also logcat, when I run my app under android).
If anyone comes up with a better solution, please let me know.
However I believe that the functionality that achieves what I want should be part of the tinylog library itself (rather than using custom hacks like this one).
Comment: Great solution! Feel free to submit your changes as pull request on https://github.com/tinylog-org/tinylog


Need help to loop through and extract variable from a object within an array

Question: first of all, I´m a noobie to say at least in programming, and this is actually my first project. But now i seem to be stuck and need some help. :)
Mission:
Im trying to grab the lat and lon variables from the MQTT stream, and return it like this
[{"lat":54.9619349,"lng":-1.6003813},{"lat":54.9656694,"lng":-1.5239833},{"lat":54.9696456,"lng":-1.5069755},{"lat":54.9378907,"lng":-1.5273729}]

This is how far i got:
var msg.payload = {"id":10,"created":"2014-05-24T07:31:05","location":{"disposition":"mobile","waypoints":[
{"at":"Friday","lat":43.64,"lon":10.73,"ele":"15"},{"at":"Saturday","lat":43.68,"lon":10.78,"ele":"26"},{"at":"Monday","lat":43.72,"lon":10.83,"ele":"43"},{"at":"Tuesday","lat":43.41,"lon":10.36,"ele":"98"}]}};

for (var i = 0, l = msg.payload.location.waypoints.length; i < l; i++) {
    var obj = msg.payload.location.waypoints[i];

    return obj
}

This just gives me the first object like this and not an array like above:
{"at":"Friday","lat":43.64,"lon":10.73,"ele":"15"}

Confused! :)
Answer: You will have to make the variable obj into a array, and push JSON Objects with lat & lon as keys with its respective values into the array.
var obj = [];
for (var i = 0, l = msg.payload.location.waypoints.length; i < l; i++) {
    obj.push({
        "lat" : msg.payload.location.waypoints[i].lat,
        "lon" : msg.payload.location.waypoints[i].lon
    })

    return obj
}

Comment: Looks better.. But it still its just returning one set of waypoints:

`var obj = [];
for (var i = 0, l = msg.payload.location.waypoints.length; i < l; i++) {
    obj.push({
        "lat" : msg.payload.location.waypoints[i].lat,
        "lng" : msg.payload.location.waypoints[i].lon
    })

    msg.payload = obj;
    return msg
}`

Returns:

`(Object) { "topic": "API-KEY/v2/feeds/#######.json?duration=24hours", "payload": [ { "lat": 39.653055555555554, "lng": 6.637777777777778 } ], "qos": 0, "retain": true }`
Comment: Thats strange, can you put a console.log right after the loop and print the contents of obj.
Comment: Funny, your solution works. Tested it in jsfiddle..
Im using node-red and but this within a function node which basically is a js. hmm, back to square one.. :)


Are there fewer professional heavyweight boxers today than there were in the Golden Age of boxing in the 1970s?

Question: I've often heard that today there are far fewer professional heavyweight boxers than there were in the 1970s, particularly due to more lucrative opportunities in other sports, and the long-term health risks of boxing as evidenced by figures like Muhammad Ali.
It's a claim I often see when people are claiming professional heavyweights of today to be far less capable than the golden age boxers.
I wouldn't have thought this to be true, as the global population is much bigger. Is there any truth to this claim?
Comment: Professional or just famous? I know of several boxers fighting professional (one even personally) who are known in their home region only.
Comment: @dly professional
Comment: Surely there cannot be less unless the weight categories have changed.  Or do you mean to say 'fewer'?
Comment: @Chenmunka I made a grammatical error but I'm not sure how you're reading it. Is the total amount of heavyweight boxers today X, less than the heavyweight boxers Y at some point in the 1970s?
Answer: I don't have the statistics but it could be a very definite possibility. I don't know the exact cutoff for the 70s but in the 1920s the heavyweight limit started at 175lbs, and I don't believe cruiserweight was introduced until the late 70s or 80s. So a lot of guys boxing today at light heavy and cruiser would have been heavies back then.


Guitar bassline and melody independence

Question: I come from a self-taughting background, so I'm sorry for any bad terminology in the question.
Some time ago, when learning Blind Willie Johnson - Nobody's fault but mine, I first practiced the slide guitar melody (the sharp notes). Once I had it down, it was time to add the bass line, which was simply alternating between octaves (6th and 4th open strings) on every beat.
Even with its simplicity, it was really hard to add the bass line because some of the notes would land between rests or in some "odd" places, like the melody wasn't completely in sync with the bass (which is probably one of the things that makes it sounds so nice). I ended up slowly figuring out where the bass notes were and after some practice I could get it. It felt like almost relearning the song, except I had practiced the slides already. I'd find out that there was a bass note somewhere, and would either change the pluck to include it or play it alone in the rests.
I was just worried that this approach is actually keeping me from creating some independence between my bass and melody in other songs, requiring me to do this whole process every time I have to learn a song with an "odd" bass line. I just imagine it's very hard to create independence between the thumb and the other fingers, since the plucking style kind of changes if you have to use the thumb at the same time or not (meaning they are not entirely separated).
Should I keep adding the bass lines that way? If not, what could I do to begin creating independence between the thumb and the other fingers? After that, will it feel natural to add bass lines to other songs?
Comment: its important to remember that lots of blues artists were awful at playing in time. John Lee Hooker was terrible and studios struggled to find a bad that could be  loose with their time keeping to suit him. Moral: if it sounds good, go with it.
Answer: Syncopation (playing notes that fall between the beats) is very common in all styles of music and is a great technique to practice.
The way you are doing it is great. Learn the melody (what you are referring to as the "sharp notes" which you should avoid using because it will be confusing) first so you can play it, then work in the bass line (learning the bass line separately in between if needed). You will find that as you do this more it will take less time, seem familiar and get easier and easier. There are really only so many combinations of notes (rhythms anyway) that you can have (bass by itself followed by an off beat melody note : bass and melody together, etc) and once you get a feel for a few of those you will find that the coordination will work for other songs.
keep at it, it will get easier.
Comment: Thanks, I'll keep practicing that way then! I made some confusion by using the word "sharp", I forget that in English it's the word for the notes accident, when I actually mean't higher notes :p

Guitar bassline and melody independence


GLSL dark seams between masks

Question: Texturing follows:
gl_FragColor=texture2D(my_main_texture, vUv);

gl_FragColor= mix(gl_FragColor,texture2D(texture[1], 32.0*vUv),texture2D(mask[0], vUv).r);
gl_FragColor= mix(gl_FragColor,texture2D(texture[2], 32.0*vUv),texture2D(mask[0], vUv).b);

For example, using a mask:

But for some reason on the border between the red and blue masks do not produce a texture value, although the number of channels for each pixel between the blue and red mask is 255
For example, the following code having:
gl_FragColor=vec4(0.0);

gl_FragColor= mix(gl_FragColor,vec4(1.0),texture2D(mask[0], vUv).r);
gl_FragColor= mix(gl_FragColor,vec4(1.0),texture2D(mask[0], vUv).b);

I get:

The shaded circle - this is the border between the red and blue mask, it should not be
How to get rid of it? Perhaps the reason to use mix (), and there are other ways to achieve the desired result?
Answer: This is because of linear interpolation of texels. You get "in beetween values" which are half blue and half red. Thus resulting in grey. you may switch off texture interpolation.
Or try:
vec4 m0=texture2D(mask[0], vUv);
gl_FragColor= gl_FragColor*(1.0-m0.r-m0.b)+texture2D(texture[1], 32.0*vUv)*m0.r+texture2D(texture[3], 32.0*vUv)*m0.b;

Comment: Thank you, I picked the formula

GLSL dark seams between masks


Enable Parent window menus on child button login event in WPF MVVM

Question: I have a scenario, I am having a MainWindow.xaml. This window has menus (which are initially disabled) and user controls. On one of the user control I have a login button clicking which Login pop up window open up. After successful login I want to Enable my main window disabled menu items. How can I achieve this functionality in WPF MVVM?
Answer: Are you using any kind of MVVM Framework?
If so.
Most of them have some kind o event service. For example Caliburn.Micro has EventAggregator.
I would call such event in child view model and subscribe to it in parent one.
In your scenario it would be something like that (in Caliburn.Micro):
<code>class ChildViewModel
{
    ...
    public void HandleLogin()
    {
        ...
        _eventAggregator.Publish(new LoginEventArgs);
    }
}

class ParentViewModel : IHandle<LoginEventArgs>
{
    public void Handle(LoginEventArgs args)
    {
        ..
    }
}
</code>
With the use of such event service you achieve separation of your ViewModels and you much flexibility because you can handle such LoginEvents in other view models in your application.
As mentioned before many MVVM frameworks has such service:

Caliburn
Prism
MVVM Light

If not.
You can assembly your own event aggregator.
Here are some sources which can be helpful in such homebrew implementation:

SO
MSDN


Get changes from the perforce

Question: I am trying to get last changes from the perforce
So I go to perforce folder and executing following command, as I found in tuturial
p4 changes -m 5 //depot/main//project/ result.txt // should save last five changes to result.txt

but gives me the following error
result.txt - must create client 'IM000001' to access local files // IM000001 is the name of my computer

any ideas?
Answer: Try writing the command like this:
p4 changes -m 5 //depot/main/project/... > result.txt

The main thing you got wrong was no redirection of the output into your result.txt file so p4 changes tried to interpret result.txt as a versioned file, but without a valid client spec (aka workspace) it couldn't resolve the depot path for it.

Get changes from the perforce


Change Front page for anonymous user in sugarcrm?

Question: What I Want ?
I want my sugarcrm site Look like a normal site like any other site. on which their is Home, About us, Contact us and LOgin options are their?
What I have done ?
when I see the url of my site it look like "localhost/crm/index.php?module=Users&action=Login"  thats why I have created a custom module for contact us and home page. and try to fetch that  links through passing url.
face Hurdle in it?
Whatever I pass The link over it that was only open when  any user login into it. it does not open for Guest user.
Please give some Idea about it.
I have also try to chang the LDAP Authentication but I can`t understand the behaviour of LDAP authentication.
Answer: This isn't the answer that you are looking for, but SugarCRM is not a CMS but a CRM. It isn't meant to look and work like any other site. It is a business application. That being said there are always ways to manipulate the theme/layout to match your business' theme so that all your business apps have a similar theme for your organization's users. If you are looking at doing something with external users having access to SugarCRM I then highly advise using a portal that talks with SugarCRM via the API. There are Joomla, Drupal, and other 3rd party portal solutions that integrate with SugarCRM for this.


How to scrap a table from a website without a specific tag?

Question: I'm developing a python script to scrape data from a specific site:
https://www.abs.gov.au/statistics/economy/price-indexes-and-inflation/residential-property-price-indexes-eight-capital-cities/latest-release
I'm using BeautifulSoup. The interesting data on this page are :

I would like to scrap the above data and have tried this way
import requests
from bs4 import BeautifulSoup
res=requests.get("https://www.abs.gov.au/statistics/economy/price-indexes-and-inflation/residential-property-price-indexes-eight-capital-cities/latest-release")
soup=BeautifulSoup(res.text,"html.parser")
table=soup.find_all('table', class_='chart-data-table has-chart responsive-enabled double-headers')
print(table.get_text())

Once I tried to run it, error occurred:
Traceback (most recent call last):
  File "/Users/ryanngan/PycharmProjects/Webscraping/seek.py", line 6, in <module>
    print(table.get_text())
  File "/Users/ryanngan/PycharmProjects/Webscraping/venv/lib/python3.9/site-packages/bs4/element.py", line 2289, in __getattr__
    raise AttributeError(
AttributeError: ResultSet object has no attribute 'get_text'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?

How can I scrap the above data in the website? Am I referring to a wrong tag? Thank you very much.
Comment: `find_all` returns a `List` you are treating it as a single item
Comment: I wish you web scrapers would learn how to spell scrape
Answer: The easiest way is to use pandas.read_html:
import requests
import pandas as pd
from bs4 import BeautifulSoup

url = "https://www.abs.gov.au/statistics/economy/price-indexes-and-inflation/residential-property-price-indexes-eight-capital-cities/latest-release#residential-property-price-indexes"

soup = BeautifulSoup(requests.get(url).content, "html.parser")
table = soup.select_one(
    'table:has(caption:-soup-contains("Residential Property Price Indexes, capital cities"))'
)

# parse the table manually or use pandas.read_html
df = pd.read_html(str(table))[0]
print(df)

Prints:
   Unnamed: 0  Sydney  Melbourne  Brisbane  Adelaide  Perth  Hobart  Darwin  Canberra  Weighted average of eight capital cities
0      Dec-11    98.4      100.0     100.2     100.7   99.4   101.9    98.2     100.9                                      99.4
1      Mar-12   100.3       99.4     100.0      99.3  100.5    99.4   100.8     100.8                                     100.0
2      Jun-12   101.4       99.3      99.9      99.6  101.0    98.2   104.1      99.5                                     100.4
3      Sep-12   100.9       98.6     100.8      99.2  102.1    98.1   105.5      99.5                                     100.2
4      Dec-12   103.7      100.4     101.7     100.2  105.2    98.4   107.8     101.8                                     102.4
5      Mar-13   104.7      100.8     101.9      99.8  107.5   100.0   109.6     100.3                                     103.1
6      Jun-13   108.7      102.7     103.2     100.9  110.6   100.0   111.0     101.0                                     105.7

...

Manual parsing:
header = [th.text for th in table.thead.select("th")]
print(*header, sep="\t")
for row in table.tbody.select("tr"):
    tds = [td.text for td in row.select("th, td")]
    print(*tds, sep="\t")

Comment: Thank you so much. This works. Is it because I am referring to a wrong tag and class  therefore my method does not work?
Comment: @ryantl Your code doesn't work because `.find_all()` returns `ResultSet` object that doesn't have `.get_text()` method. You need to iterate over items returned by `.find_all()` and call `.get_text()` on those items.
Comment: super clean answer
Answer: find_all() returns an array of elements. You should go through all of them and select that one you are need. And than call get_text()
for el in table:
   print el.get_text()

Comment: Thanks you. Should I just use `find` instead? I have tried to use find and run the program but I still can't scrap the data from the table. I should have referred to the correct tag: `table`, and `class:'chart-data-table has-chart responsive-enabled double-headers'`. Just don't know why it won't work.


Am I using my noise gate wrong?

Question: So I originally had a Behringer noise gate pedal, didn't think it was working correctly, eventually upgraded to a Boss NS2.
I've put the pedal in the effects loop of my amps (a Bugera TriRec and a Blackstar HT20) and have had the same problem with both pedals. I have to have the threshold dialed up all the way to the left to get any kind of reduction and if I set it to mute mode, I get no sound whatsoever.
Am I doing something wrong here?
Comment: @DrMayhem that's why I originally put the gate in the FX loop, to try and reduce some of the hiss from the preamp gain. probably need to look into other solutions, but I did try putting the NS-2 before the amp and it helped a noticeable amount!
Comment: Did you HAVE a noise problem?
Comment: @LaurencePayne yeah - hiss from the amp's gain
Comment: Jamie - ahhh, that is a separate issue...if the amp is introducing hiss, then that is what you need to fix first.
Comment: If it helps before the amp, then you have a normal situation: noise is from your instrument and cables. This is what a noise gate is for. If your amp is introducing hiss then it is usually a problem - I think I saw you posted on one of the tube amp questions, so you probably are aware of this already.
Answer: The best place for a noise gate is before the preamp, otherwise you already have that gain stage in place making your signal permanently above the gate threshold (or at least requiring the threshold to be set so high it is effectively pointless)
So run your noise gate first, so you can use the dynamics of the guitar, then the gain stage, with the other effects on the loop, then the output power stage.

Am I using my noise gate wrong?


EntityReference causes a NullReferenceException error

Question: I've only just started delving into LINQ to CRM.
I've built the following query that gives me a bunch of data about each contact and their company from the CRM:
var contacts =
        (
            from c in context.ContactSet
            join m in context.py3_membershipSet on c.ContactId equals m.py3_Member.Id
            where m.statuscode.Value == 1
            orderby c.LastName
            select new
            {
                FirstName = c.FirstName,
                LastName = c.LastName,
                BranchCode = c.py3_BranchArea,
                Branch = (c.FormattedValues.Contains("py3_brancharea") ? c.FormattedValues["py3_brancharea"] : "N/a"),
                JobTitle = c.JobTitle,
                Organisation = c.ParentCustomerId.Name,
                joinedAsCode = c.py3_SOLACEMemberJoinedAs,
                JoinedAs = (c.FormattedValues.Contains("py3_solacememberjoinedas") ? c.FormattedValues["py3_solacememberjoinedas"] : "N/a"),
                Expertise = c.py3_SOLACEMemberAreasofExpertise
            }
        );

I then use a simple foreach to loop through each record and write it out:
foreach (var a in contacts)
        {
            Response.Write("Firstname: " + a.FirstName + " | LastName: " + a.LastName + " | Job Title: " + a.JobTitle + "| Org: " + a.Organisation + " | Branch: " + a.Branch + " | Expertise: " + a.Expertise + " | Membership Product: " + a.JoinedAs + "
");
        }

However, I get an 'object reference not set to an instance of an object' error when I run the page. The error gives the following info which currently means nothing to me:
[NullReferenceException: Object reference not set to an instance of an object.]
lambda_method(Closure , <>f__AnonymousTypef`2 ) +658

From a process of elimination I know that the issues lies with trying to write out the 'a.Organisation' which relates to 'c.ParentCustomerId.Name'.
Usinq LinqPad I can see that this LINQ brings up the ParentCustomerId and shows it having four children, namely:

Id
LogicalName
Name
Extension Data

So I know that I want 'c.ParentCustomerId.Name', however I'm not sure why I'm having this issue. It's possible but unlikely that some records (entities?) don't have a value for this.
Is there something I'm not doing right in terms of grabbing this data or is it simply that I'm not populating it with some sort of default data for when a record is empty/null ?
Answer: You just need to add some guards when you're using Contains or accessing child properties on something that may or may not be null:
FirstName = c.FirstName,
LastName = c.LastName,
BranchCode = c.py3_BranchArea,
Branch = (c.FormattedValues != null &&
          c.FormattedValues.Contains("py3_brancharea") ?
          c.FormattedValues["py3_brancharea"] : "N/a",
JobTitle = c.JobTitle,
Organisation = c.ParentCustomerId != null ? c.ParentCustomerId.Name : "N/a",
// ...

Comment: Its not the FormattedValues thats causing the issue. Its on the Organisation as stated in my OP. Branch and JoinedAs  are working fine and are coping with nulls perfectly. Ive tried a similar approach with Organisation and it still throws the same error.
Comment: @PhillHealey - That was a basic example. I expanded it to cover Organisation as well. It's good practice to use them anywhere you could run into a null though.
Comment: Ok, I see what you are doing now. However, Ive tried that suggestion for organisation previously and it still throws the same error.
Comment: Ah. I've redone it and now for some reason the damn thing works. Oh, well Im obviously a bit screen blind. Thanks for the help Justin.


Problem with temporary URL in new host

Question: I'm migrating my Drupal website to a new host.
Here's what I've done:
1 - Create an DB.mysql.gz using backup and migrate module (in old host)
2 - Create a new database and user in new host and restore this DB.mysql (step 1) directly using mysql -u USER -pPASS MYBD < /home/DIR/DB.mysql
3 - Install in new host the drupal using QuickInstall (installed v7.32)
4 - Transfer all data by directory www (old host) to a new host (hostgator - public_html) overhidding all files of Drupal 7.32 (installed by QuickInstall) to my current install v7.34.
5 - Change settings.php database content
I need check if all site is running OK before change DNS, for it, i need login using www.URL_TEMP/~MYUSERHOST/user/login, but this URL return 404 - Page not found.
Home page is load disfigured and browser log say 404 not found in css/js files, eg: www.URL_TEMP/~MYUSERHOST/sites/default/files/css/css_xE-rWrJf-fncB6ztZfd2huxqgxu4WO-qwma6Xer30m4.css and others. This file exists in public_html/sites/default/files...
I try change hosts file in my local machine (http://support.hostgator.com/articles/general-help/technical/how-do-i-change-my-hosts-file) but not solved.
This problem does not allow that I access with admin and change file temporary path in /admin/config/media/file-system, clean cache and test website.
Am I missing something, or do something wrong?
Ps: In old host the website is running OK!
Comment: You need to clear the cache, and if the existing temporary file path is invalid you'll need to change it.
Comment: If you're using DB caching (likely if you're on shared hosting), you can truncate the cache table, and any others who's name begins with 'cache_' to get the same effect. Also check the `$base_url` in settings.php is sensible. As a temporary measure you can add `$conf['file_temporary_path'] = '/path/to/real/tmp/folder';` to settings.php to unconditionally override the tmp location
Comment: For it I need login with Drupal Administrator using www.URL_TEMP/~MYUSERHOST/user/login but it return 404 error :)
Comment: I changed base_url to URL_TEMP/~MYUSERHOST and add $conf in settings.php but no success :(
Comment: Add $conf['cache_lifetime'] = '60';  in settings.php. No success again
Answer: If you are sure that settings.php and ftp files are all set right, my guess is you miss some package in php or in appache. Please compare php and appache settings between old host and new host. For example, rewrite_module in apache
Answer: I add RewriteBase /~MYUSERHOST in .htaccess and solved problem!
I can now logging using URL_TEMP/~MYUSERHOST/user/login. I'm testing website, but initially everything is ok.

Problem with temporary URL in new host


How to do pairwise column regression of a big matrix in R?

Question: I have a big A = M x N matrix and I want to regress each column (except last) with the last column. I want the result to be a dataframe with following columns

First column has the col names of A (except last)
Slope of linear regression
Adjusted r-squared
Number of non-na points in regression (this is meant to capture that for any given regression pair, I only want to include points for which both columns exist, basically exclude nulls, which I think the lm function does automatically already)

Whats the best way to do this in terms of elegance (not having to write a loop to go through columns, but using existing functions) and performance (doesnt take forever)?
Answer: Something like the following:
A <- iris[1:4]
res <- apply(A[ , 1:(ncol(A)-1)], 2, function(x) lm(A[ , ncol(A)] ~ x, data = A))
slope <- sapply(res, coef)
r_squared <- sapply(res, summary)[8, , drop = FALSE]
t(rbind(slope, r_squared))
##              (Intercept) x          r.squared
## Sepal.Length -3.200215   0.7529176  0.6690277
## Sepal.Width  3.156872    -0.6402766 0.1340482
## Petal.Length -0.3630755  0.4157554  0.9271098


Como fazer meu servidor feito em python funcionar em rede externa usando o ngrok?

Question: Eu criei um server em python que roda na porta 50000... Logo após disso criei meu cliente. Se os dois estiverem na mesma rede ambos se conectam e da tudo certo! Porém em rede externa não consigo fazer a conexão com os dois.
Então descobri uma ferramenta chamada ngrok, fiz download dela e comecei a usar. Eu estou fazendo da seguinte forma:
Executo meu servidor na porta 50000 a após isso executo o seguinte comando:
ngrok.exe http 50000
O ngrok funciona, abre o link e beleza, mas quando eu entro no link gerado o meu servidor feito em python se conecta com o que eu acho ser o ngrok, pois ele me retorna isso:
Host: 66907fd55f8a.ngrok.io
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7
Sec-Ch-Ua: "Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"
Sec-Ch-Ua-Mobile: ?0
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Upgrade-Insecure-Requests: 1
X-Forwarded-For: Meu ip
X-Forwarded-Proto: https

Digite o comando:

Mas eu quero que o meu cliente se conecte ao servidor para eu mandar comandos para ele.
O código resumido do servidor e do cliente, ele está resumido pois está bem longo, pois em ambos os códigos eu adicionei varias funções:
servidor.py:
import socket
from time import sleep

def abrir_servidor():
    bind_ip = ''  # local onde o servidor roda
    # bind_ip = ''
    bind_port = 50000  # porta onde roda o servidor

    print('Iniciando servidor: ')
    sleep(0.5)

    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.bind((bind_ip, bind_port))
    server.listen(1)

    print('Servidor iniciado!')

    print('Aguardando cliente...')
    global conexao
    global endereco
    conexao, endereco = server.accept()
    print(f'Conectado em: {endereco}')
def main():
    abrir_servidor()
    while True:
        global comandos
        comandos = input('Digite o comando: ')

while True:
    main()

cliente.py:
import socket
import os

def conectar():
    #conectando no servidor:
    target_host = 'localhost'
    target_port = 50000
    global cliente
    cliente = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    cliente.connect((target_host, target_port))
    # localizar script:
    for a in range(1):
        cliente.send(os.getcwd().encode())

def main():
    conectar()
    while True:
        global comandos
        comandos = cliente.recv(4000).decode()

while True:
    main()

Como eu faço isso? Já estou ficando sem ideias. Será que existe outro jeito de fazer meu servidor rodar em rede externa?
Comment: Consegue editar a pergunta e colocar o código do servidor ou, caso ele seja muito grande,
um [mcve]? Fica mais simples para tentar responder, caso seja um problema no código e não na infraestrutura
(rede, firewall, etc).
Comment: Eu acabei de editar a pergunta, colocando o código do cliente e do servidor. Obrigado pela dica de adiciona-los, tinha até me esquecido
Comment: Quando você diz "na mesma rede", quer dizer no mesmo computador? Ou em computadores
diferentes conectados por uma rede? A conexão do cliente está apontando para
'localhost', o que sugere que os dois programas estão rodando na mesma máquina. O código inicial do servidor está correto, falta apenas o recebimento da primeira mensagem (os.getcwd) e
o envio (para o cliente) dos comandos digitados.
Comment: Mesma rede eu digo tanto na mesma maquina quanto em computadores diferentes conectados na mesma rede wifi. No código esta localhost pois eu estava testando no meu pc. Sobre o recebimento da mensagem (os.getcwd) já arrumei. Mas ainda não sei como deixar meu servidor pronto para receber clientes em rede externa.
Answer: No contexto de servidores, o endereço 0.0.0.0 significa todos os endereços IPv4 na máquina local. Se um host tiver dois endereços IPs, por exemplo: 192.168.1.1 e 10.1.2.1, e um servidor em execução estiver escutando no endereço 0.0.0.0, ele estará acessível para ambos os IPs.
Portanto, use o endereço 0.0.0.0 para fazer o bind da porta na qual o seu servidor vai escutar, por exemplo:
bind_ip = '0.0.0.0'  # local onde o servidor roda
bind_port = 50000    # porta onde roda o servidor

Isso vai fazer com que seu servidor aceite conexões independente da origem.
Referência: https://en.wikipedia.org/wiki/0.0.0.0