Tree Structures

Question: What are the benefits or advantages to using a tree structure in a managed language or framework over flat structures provided by said language or framework, aka .NET, and are there any libraries for such a structure?
Comment: benefits/advantages over what?
Comment: yes there are libraries, although .NET isn't a language...
Answer: The advantages are the same as those for a tree structure in any language.  Take a look at the Wikipedia article on balanced binary search trees.  Balanced trees get you logarithmic insert and access time, and they keep elements sorted.
The most commonly used application of tree structures is for sorted maps and sets.  In .NET, take a look at SortedDictionary, which uses a balanced search tree.
I'm assuming this is what you're talking about because it's the most common kind of tree in application programmer land, but trees are used for all sorts of things in computer science.  Take a look at the more general article on tree data structures if you want more on this.
Answer: A tree is an ideal data structure for managing information that is organized hierarchically. This is true for whatever language you happen to be using.
Here is just a small sampling of the many applications of the tree data structure:

Searching a sorted set (take a look
at Binary Search Tree)
Syntax
parsing (take a look at Parse
Tree)
Representing structure of
source code (take a look at Abstract
Syntax Tree)
Storing dictionaries
(take a look at Trie)
Answer: How long is a piece of string?
The comparative benefits of trees over other data structures depend on the type of data you are storing, and the types of operations you are planning on doing over the data.
(Being in a managed framework has nothing to do with it, by the way.)
You're going to have to fill in a lot more details if you want to get a more intelligent response.
Alternately, you can take a beginning Algorithms and Data Structures course, and learn the lay of the land.

Tree Structures


How to find midpoint of an arc in MATLAB

Question: It is necessary for me to find midpoint of some arc in MATLAB. For simplicity let this arc is a part of circle. Also, we know the radius, center and starting point and ending point of the arc. I used $atan2(y,x)$ to get the angle for each line constructed by start and end points. Then find $t_{mid}=\frac{t_1+t_2}{2}$ and use $x_{mid}=r*cos(t_{mid})+xc,~y_{mid}=r*sin(t_{mid})+yc.$
But the problem is that $atan2$ gives the angle between $-\pi$ and $\pi$. Then for example for third quarter if $t_1=\pi$ and $t_2=-\pi/2$, $t_{mid}=\pi/4$ and it is not true. If I add $2\pi$ to the angles lower than zero, then I have the same problem for fourth quarter, for example $t_1=\frac{3\pi}{2},t_2=0$, the mid angle is $\frac{3\pi}{4}$!!. How can I solve this problem?
Comment: The problem is not with $atan2$ but is in the identification and then evaluation of $t_{mid}$: Imagine both the endpoints and the center lie on the same line (let's say the x axis), how do you decide which is the arc to draw? Maybe your question can be reworded in *find the midpoint of the smallest arc between two points*, in this case, evaluate $\Delta t=t_1-t_2$, add or subtract $\pi$ until $|\Delta t|<\pi$ and then $t_{mid}=t_1-\Delta t/2$.
Answer: Compute the coordinates of the midpoint $I$ of the endpoints (which is outside of the arc, of course): its polar angle is the same as the polar angle of the point you are looking for. The rest is easy.


RuntimeError: The type numpy.ndarray(numpy.ustr) for column is not supported

Question: I am trying to convert python dataframe data types so that they can be returned through sql server using the sp_execute_external_scripts procedure. Some columns in particular are giving me issues. Sample data:
>>> df.column1
0       NaN
1      1403
2       NaN
3       NaN
4       NaN

Using the method found in another answer (https://stackoverflow.com/a/60779074/3084939) I created a function to do this and return a new series.
def str_convert(series):
    null_cells = series.isnull()
    return series.astype(str).mask(null_cells, np.NaN)

I then do:
df.column1 = str_convert(df.column1)

When I run the procedure in management studio I get an error:
Msg 39004, Level 16, State 20, Line 0
A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 0
An external script error occurred:
C:\SQL\MSSQL14.SQL2017\PYTHON_SERVICES.3.7\lib\site-packages\revoscalepy\functions\RxSummary.py:4: FutureWarning: The Panel class is removed from pandas. Accessing it from the top-level namespace will also be removed in the next version
  from pandas import DataFrame, Index, Panel

INTERNAL ERROR: should have tag
error while running BxlServer: caught exception: Error communicating between BxlServer and client: 0x000000e9

STDOUT message(s) from external script:

Express Edition will continue to be enforced.

Warning: numpy.int64 data type is not supported. Data is converted to float64.
Warning: numpy.int64 data type is not supported. Data is converted to float64.
SqlSatelliteCall function failed. Please see the console output for more information.
Traceback (most recent call last):

STDOUT message(s) from external script:
  File "C:\SQL\MSSQL14.SQL2017\PYTHON_SERVICES.3.7\lib\site-packages\revoscalepy\computecontext\RxInSqlServer.py", line 605, in rx_sql_satellite_call
    rx_native_call("SqlSatelliteCall", params)
  File "C:\SQL\MSSQL14.SQL2017\PYTHON_SERVICES.3.7\lib\site-packages\revoscalepy\RxSerializable.py", line 375, in rx_native_call
    ret = px_call(functionname, params)
RuntimeError: The type numpy.ndarray(numpy.ustr) for column1 is not supported.

No idea on where to start but when I simply do the below, it does not error but NaN values get replaced with 'nan' therefore return as the literal string rather than null in sql server which is not what I want. Hopefully someone else has some insight as to what's going on. I tried searching and nothing relevant came up.
df.column1 = df.column1 .astype(str)

Edit:
A more trivial example seems to reveal this occurring when the first value in the series is NaN.
declare @script nvarchar(max) = N'
import os
import datetime
import numpy as np
import pandas as pd

df = pd.DataFrame([[np.NaN, "a", "b"],["w","x",np.NaN],[1, 2, 3]])

df.columns = ["a","b","c"]

print(df.head())
'

execute sp_execute_external_script
    @language = N'Python',
    @script = @script,
    @output_data_1_name = N'df'
with result sets ((
a varchar(100) null
,b varchar(100) null
,c varchar(100) null
))

Answer: I believe that this might be due to the fact that np.NaN is not a string and therefore cannot be converted to varchar.
Try casting the df values to str, i.e. in your latest example:
df["a"] = df["a"].apply(str)


Find the internal bending moment, Mc

Question: A 7meter,m, long cantilever beam whose weight per meter is 19Newton, N, carries a load that varies uniformly from 43N/m, (Newton/meter), at the inbuilt side, point A, to 0 at the free end, point B. Find the internal bending moment, Mc, at a point C located 1meter,m, from point A
Answer: You shall have tried yourself. The figure below will refresh your memory of what have learned at school.

Now, just for the sake of fun, work out this problem from the free end towards point "C" and see what results.

Find the internal bending moment, Mc


How can I configure storm to receive data from a client, process the data in bolts and then return the processed data to the same client as a stream?

Question: Here my scenario: I have a client application that needs a dedicated powerful computation system that every seconds process some data in input (few kilobyte) and return a few megabytes of processed data that the client displays in a certain way. The algorithm to process the data has a sort of "precision" parameter so we can, on a normal computer, process one second of data in one second with "low resolution". Although if we want "high resolution", it could take minutes.
So that's why we need to distribute the load and we are looking into Apache Storm right now (even though Cuda or other systems are under evaluation so suggestions are appreciated but I'd like to get help for Storm here).
I've been looking into Storm in general and some tests in both Aws and Azure but what I can't understand is how to have the source and the destination to be the same sprout and so our client application.
So for example I could send the data to a sprout, the sprout partitions the data to many instances of a bolt, the processed data get saved in memory to Redis, the client accesses (or call an app that accesses) the Redis db.
It seems to me the last 2 steps could be cut out and send back the processed/output data on the same channel the client sent the input data (meaning the sprout..)
Ps: once data is sent back to the client, we don't need it anymore on the "server"/storm system and no point on be available to be requested in the future.
Answer: I think I found a possible answer with DRPC
http://storm.apache.org/releases/current/Distributed-RPC.html
but other options are appreciated too.


How to do housekeep the database in sql server 2008 by specific date range?

Question: I have database with around 160 GB size. The database contains the data is from 2013 to until today, there are 180 tables, I want to remove the records in specific date range like 2013 to 2014 in all tables. How to do in SQL Server 2008, Is there any query technique or any tool in SSMS?
Comment: Please provide the table structure for all to see
Answer: Deleting data is easy from the syntax point of view, but that's not all there is. DELETE FROM myTable WHERE someDate < deletionDate might give you a few nasty suprises.
Constraints might block you from doing a delete. A textbook example is a foreign key constraint between customer and order tables. Deleting a customer is not allowed as long as there are orders. If it would, you would end up having orders not linked to a customer. In order to overcome this kind of limitations, you must understand the database schema and start deleting from the right table first (or rely to constraint to use ON DELETE CASCADE.)
Don't underestimate the performance effects. If you are lacking proper indexing (or have overextensive indexing), deleting records might generate serious a performance hit by creating lots of unnecessary index updates and/or full table scans. In addition, write locks will cause overall performance hits for any operations from the affected tables.
Transaction log management is a common gotcha. Pruning a lot of data will generate lots of transactions and you log files will go sky high. As a best practice, break the delete operations in batches. Aaron's blog has detailed discussion about the issue.


java.util.NoSuchElementException on reading a file (Scanner)

Question: I have a text file with 3 words on it, and on trying to read these words I get the following error:
Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Unknown Source)
    at java.util.Scanner.next(Unknown Source)
    at search.search(search.java:121)
    at main.main(main.java:38)

Below is the code in question:
Scanner reader = new Scanner(path + client + "\\" + cat +"\\" + query + ".arch");
while (reader.hasNext()){
    String a = reader.next();  // line 121
    String b = reader.next();
    String c = reader.next();
    file = new File (path + client + "\\" + a +"\\" + b + ".arch");
    print(file);
}

Below are the contents of the file:

po ref refc (with a new line at the end)

What gives?
I've used a very similar system before, with the same file, and everything worked, I even use a very similar system some lines below.
Btw the String c is not yet implemented but shall be further down.
Answer: Are you sure line 121 is not one of the next lines?
You check reader.hasNext() to make sure there is another entry, but you then read 3 entries in a, b, c. If there is only one for example, b = reader.next() would fail.
Comment: Thanks for your reply;  I managed to fix it by changing the scanner to Scanner reader = new Scanner(new File(path + client + "\\" + cat +"\\" + querry + ".arch"));


Interface design? Can I do it iteratively? How should I handle changes to the interface?

Question: What is the best approach for defining Interfaces in either C# or Java? Do we need to make generic or add the methods as and when the real need arises?
Regards,
Srinivas
Answer: Once an interface is defined, it is intended to not be changed.
You have to be thoughtful about the purpose of the interface and be as complete as possible.
If you find the need, later, to add a method, really you should define a new interface, possibly a _V2 interface, with the additional method.
Addendum:  Here you will find some good guidelines on interface design in C#, as part of a larger, valuable work on C# design in general.  It generally applies to Java as well.
Excerpts:

Although most APIs are best modeled using classes and structs, there are cases in which interfaces are more appropriate or are the only option.
DO provide at least one type that is
  an implementation of an interface.
  This helps to validate the design of
  the interface. For example,
  System.Collections.ArrayList is an
  implementation of the
  System.Collections.IList interface.
DO provide at least one API consuming
  each interface you define (a method
  taking the interface as a parameter or
  a property typed as the interface).
  This helps to validate the interface
  design. For example, List.Sort
  consumes IComparer interface.
DO NOT add members to an interface that
  has previously shipped.  Doing so
  would break implementations of the
  interface. You should create a new
  interface to avoid versioning
  problems.

I recommend relying on the broad type design guidelines.
Comment: +1. Of course during development, an iterative approach is normal.  You'll add methods and see if that makes sense, then add and remove a few more methods as you gain experience.  But at some point you release the code, and from that point on, the interface needs to remain fixed, except in very exceptional conditions.
Comment: I 100% agree with this, except that IMO it is an ideal situation.  In practice I think you'll need to eventually refactor your interfaces to handle things you just didn't think of the first time around.  If you're interface is public, like a web service or an API of some sort, then definitely take @Cheeso's advice above and version them out.  If it's internal to your project only, I don't think there's anything wrong with changing it as long as there is a formal process for doing so.  You shouldn't just change it on the fly all the time.
Answer: To quote Joshua Bloch:

When in doubt, leave it out.

You can always add to an interface later.  Once a member is a part of your interface it is very difficult to change or remove it.  Be very conservative in your creation of you interfaces as they are binding contracts.
As a side note here is an excellent interview with Vance Morrison (of the Microsoft CLR team) in which he mentions the possibility of a future version of the CLR allowing "mixins" or interfaces with default implementations for their members.
Answer: If your interface is part of code that is shared with other projects and teams, listen to Cheeso.  But if your interface is part of a private project and you have access to all the change points then you probably didn't need interfaces to begin with but go ahead and change them.
Answer: If the interface is going to be public, I feel that a good deal of care needs to be put into the design because changes to the interface is going to be difficult if a lot of code is going to suddenly break in the next iteration.
Changes to the interface needs to be taken with care, therefore, it would be ideal if changes wouldn't have to be made after the initial release. This means, that the first iteration will be very important in terms of the design.
However, if changes are required, one way to implement the changes to the interface would be deprecate the old methods, and provide a transition path for old code to use the newly-designed features. This does mean that the deprecated methods will still stick around to prevent the code using the old methods from breaking -- this is not ideal, so it is a "price to pay" for not getting it right the first time around.
On a related matter, yesterday, I stumbled upon the Google Tech Talk: How to Design a Good API and Why It Matters by Joshua Bloch. He was behind the design and implementation of the Java Collection libraries and such, and is the author of Effective Java.
The video is about an hour long where he goes into details and examples about what makes a good API, why we should be making well-designed APIs, and more. It's a good video to watch to get some ideas and inspiration for certain things to look out for when thinking about designing APIs.
Answer: Adding methods later to an interface immediately breaks all implementations of the interface that didn't accidentaly implement those methods. For that reason, make sure your interface specification is complete. I'd propose you start with a (sample) client of the interface, the part that actually uses instances of classes implementing said interface. Whatever the client needs must be part of the interface (obviously). Then make a (sample) implementation of the interface and look what additional methods are both generally usefull and available (in possible other implementations) so they should also be part of the interface. Check for symetry completeness (e.g. if there is an "openXYZ", there should also be a "closeXYZ". if there is an "addFooBar", there should be a "removeFooBar". etc.)
If possible, let a coworker check your specification.
And: Be sure you really want an interface. Maybe an abstract base class is a better fit for your needs.
Answer: Well, it really depends on your particular situation. If your team is the sole user/maintainer of that interface, then by all means, modify it as you see fit and forget all about that "best practice blabla" kind of stuff. It is YOUR code after all... Never blindly follow best pracice stuff without understanding its rationale.
Now, if you're making a public API that other team or customer, will work with (think plugins, extension points or things like that) then you have to be conservative with what you put in the interface. As other mentionned, you may have to add _V2 kind of interface int these cases. Microsoft did with several web browser COM interfaces.
The guidelines Microsoft publishes in Framework Design Guidelines are just that: guideline for PUBLIC interface. Not for private internal stuff; tough many of them still apply. Know what applies or not to your situation.
No rule will make up for lack of common sense.


Error in gfortran compilation : Undefined symbols for architecture x86_64

Question: The programs have been compiled successfully using ifort. However, I don't know why I have the following error message in gfortran compilation.
Could you let me know how to solve this problem as below showed? Thank you!

gfortran main.o climate.o weather.o vegetation.o biogeochem.o initial.o humidity.o \
    radiation.o readpars.o canopy.o physiology.o snow.o soil.o utilities.o \
    ctemfire.o disturbance.o diagnostics.o io-cfs.o ies-io.o math.o stats.o nag-soil.o \
    -m64 -ffixed-line-length-132 -I/usr/local/include -L/usr/local/lib -lnetcdff -lnetcdf -o ibis

Undefined symbols for architecture x86_64:

  "_time_", referenced from:

      _MAIN__ in main.o

ld: symbol(s) not found for architecture x86_64

collect2: ld returned 1 exit status

make: *** [ibis] Error 1
Answer: I found the answer. The "time" function is an intrinsic function in ifort. I have change "time" to "dtime" for gfortran.
Michael


In a random graph, every two vertices neighbor a clique with high probability

Question: Let $G\in G(n,p)$ be a random graph, and $k \in \mathbb{N}$ a constant . I want to prove that with high probability, every two vertices have a neighboring clique of size $k$, i.e. for every $v,u \in V(G)$, there are vertices $w_1,...,w_k \in V(G)$ such that $(w_i,w_j) \in E(G)$ for all $i,j$, and $(u,w_1),(u,w_2),...,(u,w_k),(v,w_1),(v,w_2),...,(v,w_k)\in E(G)$.$$ $$
Clearly for a fixed $u,v$, the probability that they neighbor a clique is $p^{{k \choose 2}+2k}$, but how do I pass from this to a general argument?
Answer: The statement

for a fixed $u,v$, the probability that they neighbor a clique is $p^{{k \choose 2}+2k}$

is actually not as clear as you make it out to be. This is, more precisely, the probability that, for a fixed $u$ and $v$, they border a specific clique you've picked out from the rest of $G(n,p)$. From here, if you multiply by the number of ways to pick such a clique, you could conclude that
$$
    p^{{k \choose 2}+2k} \binom{n-2}{k}
$$
is the expected number of cliques that $u$ and $v$ border, but that is not too helpful. It goes to infinity with $n$: assuming $p, k$ are constant, this expression is $O(n^k)$. But this does not guarantee the existence of a clique with high probability.

However, the statement that every two vertices border a constant-size clique is actually not the best possible statement along those lines; if we use some high-powered concentration arguments, it becomes very easy to prove (and more is true).
For a fixed $u,v$, let $G_{uv}$ be the subgraph of $G$ consisting only of the common neighbors of $u$ and $v$. The number of vertices in $G_{uv}$ has the $\text{Binomial}(n-2, p^2)$ distribution, which is very closely concentrated around its mean $(n-2)p^2$; by a Chernoff-type bound, the probabability that it is below even $0.99p^2n$ is exponentially small in $n$. Since there are only $\binom n2$ pairs $(u,v)$ to consider, the union bound is enough to guarantee that with high probability, $G_{uv}$ has $O(n)$ vertices for any pair $(u,v)$.
Similarly, the number of cliques of size $k$ in $G_{uv}$ is very closely concentrated around its mean, and the probability that there are no such cliques is once again exponentially small. Unfortunately, the number of cliques is not binomial, so we need more powerful tools to prove this. Janson's inequality will work.
You can compare this to Bollobás's 1988 proof that $\chi(G(n,1/2)) \sim \frac{n}{2\log_2 n}$ with high probability. There, the key ingredient was to prove that with high probability, every subgraph of size $\frac{n}{\log^2 n}$ has a clique of size $(1+o(1))\log_2 n$. Here, you want a much weaker statement:

We only have $O(n^2)$ subgraphs $G_{uv}$ to deal with, not all of them;
They have linear size, so cliques will be easier to find;
We are looking for a clique of constant, not logarithmic size.

So we can easily conclude that each $G_{uv}$ contains a clique of size $k$ with high probability, which completes the proof. (Also, each $G_{uv}$ contains a clique of size $(1+o(1))\log_2 n$ with high probability. We can't do better than that, because with high probability that's about how big the largest clique in $G(n,p)$ is, too.)


Place google map on website

Question: I want to place google map on my website, how can I place google map on my website? can you give any already placed google map link and explain how can I add it on my website also!!!
Answer: Search on Google Maps for the map you want to embed, then click the cog icon at the bottom right.
This will give you the options for "share or embed".
The "embed" option will give you the code for an iframe along the lines of this:

Just paste that into your code where you want it to appear.  You may wish to tweak the width="600" height="450" values so that it fits on the page.
If you are using a wysiwyg editor, you may need go into "html view" to paste this and also check that iframes are accepted (some editors strip them by default but you can usually turn this off).

Place google map on website


Galaxy Nexus density issues

Question: I am developing a application for Nexus S and Galaxy Nexus.
The screen size in Portrait mode are
Nexus S 480x800
Galaxy Nexus 720x1280
The default MDPI screen is 320x480.
Now all my values of margin and borders are multiplied by the density factor if given in dp/dip
So for Nexus S its a exact mapping 320x1.5 = 480.
However, for Galaxy Nexus its a inappropriate 320x2.0 = 640.
So instead of creating a separate layout folder and adding the values in px so that i can achieve exact pixel perfect screen since galaxy nexus is my only xhdpi device that i am suppose to support.
Is there any other option where i can modify the screen density of the system and make it 2.25 for further calculations?
Really disappointed to see a flagship google product behaving this erratically.
BR,
Jayshil
Answer: Maybe this article will be helpful especially the part about -h<N>dp/w<N>dp and sw<N>dp folders.

Galaxy Nexus density issues


inline intel syntax to inline gcc

Question: I'm trying to convert a snippet of mine to a compiler that uses an inline asm syntax similar to gcc's. I read the documentation and all was fine until I encountered this line:
mov eax, dword ptr fs:[0x20]

I converted that to:
movl 0x20(%fs:), %eax

The compiled flipped, telling me that fs is not a 32bit register and that this operation is invalid. How should I access fs in at&t syntax?
Answer: Found the answer, it seems that gcc or the at&t is very inconsistent.
movl %fs:0x20, %eax

inline intel syntax to inline gcc


Prolog type definition in swi-prolog

Question: in visual prolog there is "domains" section in a prolog program in which you can define types. Is there any similar thing in swi-prolog?
In visual prolog a type is defined like:
domains
NewType = thing1; thing2

Answer: No.  But there is mode declaration in Mercury. Mercury is more than Prolog; it is a functional-logic language. Mercury still has a lot of Prolog syntax.
SWI-Prolog is a standard Prolog.  It only uses mode declarations in documentation1 as information for the users. Such declarations can be placed in comments of modules for documentation-parsing programs to compile.
In standard Prologs, outside of comments, such declarations are only allowed (and reqired) in very special situations. The block predicate of Sicstus Prolog for instance requires them.
Block/1 is used for co-routing(lazy evaluation, delay etc.).  I've only seen block used in one program in my life, PAKCS2, an interpreter for another functional-logic language.  When the interpreter was ported to SWI, block/1 was not used.
1 Type and mode declarations in SWI Source Documentation
2 PAKCS, a program using the block/1 predicate (PAKCS is an implementation of the curry language.)
Answer: While SWI-Prolog doesn't support types in a capacity quite like what you're asking for, it is worth noting that it does indeed support a simple 'type' mechanism through the use of term specification via the record/1 predicate in the record library.
This predicate allows you to specify a reasonably complex term 'type' (pattern) using a particular term specification language, and interprets it to automatically generate predicates used to perform creation (via a constructor predicate), modification via 'setter' predicates and accessors via 'getter' predicates on term instances, all by way of term-expansion with a particular predicate naming convention.
This is particularly useful when writing Prolog code that passes around reasonably complex term structures, as it provides you with a rudimentary type checking capability which Prolog typically lacks (natively). I've used this on many a large-scale Prolog project where interfaces are designed before implementation.
Answer: I remembered reading about types for Swi & Yap prolog. Here's a website with a "Hindley-Milner Type Checker for Prolog:"
Types for Prolog - Mercury-style type declarations and predicate signatures
Prolog Type Checker library

Prolog type definition in swi-prolog


Addition of honey and vanilla to cooled wort

Question: Can I add Honey to a cooled wort (Brown Ale) and then vanilla at bottling time? It is for a wort transformation contest and I will receive the Brown Ale after boil!
Answer: Yes to both.
Honey is not all that uncommon in beers, as it is often used to increase the gravity, and/or add a distinct honey flavor to the beer, giving it a mead-hybrid taste.  To avoid giving it an overly mead flavor, and adding to your fermentation time (honey is notorious for taking a while to mature in flavor), it's recommended that you use up to 10% of your grain bill (by weight) of honey.  If you want to add more more?  Whatever blows your hair back.
There's several ways you can add it to your wort.  You can dilute it in water to the same original gravity as the rest of the wort, pasteurize it by heating it to at least 176°F/80°C for an hour, cool it, and add it to the batch, or you can simply add it to the cooled wort for an increase in your original gravity.  The former method prevents your OG from going up, the latter will increase your OG.  A lot of people are advocates for adding it to the wort during high krausen, when the yeast is most active and ready for it.  Expect to wait an additional 3-8 weeks for fermentation and aging depending on how much honey you add.
A lot of people have reported greater success using vanilla later in the fermentation and aging rather than earlier.  You'll only want to add vanilla extract at bottling.  If you are using vanilla beans, you'll want to cut them down the center, scrape out all the goods inside of the been, and chop all of it up very finely.  It's best to soak them in vodka for a couple of days, and add to secondary slowly until you reach the flavor profile you're looking for.  You can add all of it at once if you're feeling brave, or add half of it, wait a week, sample it, and potentially add the other half if you're dissatisfied with the lack of vanilla flavor.
If you go the extract route, the best way to determine how much extract you would want is to find a good commercial example of a brown ale, pour it into a glass, and slowly add drops of vanilla to it over time, and stir.  Determine how many drops it takes to get the right profile you want, and then scale the number of drops up to your full batch size.  Add it to your bottling bucket and stir well before bottling off your beer, or add the drops individually to each bottle before capping.  Keep in mind extract is powerful stuff, and it is very easy to overdo it.
Comment: "honey is notorious for taking a while to ferment" - Why would you think that? Honey is virtually all simple sugars, and beer yeast will ripe through it very fast, up until you get to the high end of the yeast's alcohol tolorance. MEAD takes a long time to make (for various reasons) but adding honey to a beer takes as long to ferment as if you had added corn sugar (ie, not very long at all). I make a Blonde Ale with 3lbs of honey in the secondary, and it ferments the honey out in less than 3 days usually.
Comment: Do I still add the priming sugar at bottling time with the vanilla extract?
Comment: After doing some brief Google'ing of various extracts available (most accessible for me is [McCormick's](http://www.mccormick.com/Spices-and-Flavors/Extracts-and-Food-Colors/Extracts/Pure-Vanilla-Extract)), yes, there is no sugar in the extract, therefor you will need to still use priming sugar.  If you choose a different extract, be sure to check the ingredients to determine whether or not there are fermentable sugars, in which case you'll need to account for when priming your bottles.
Comment: I've added honey in a couple of beers, and have found that in excess, the flavor remains sticky on my palette, which refines out to a smoother, almost maple syrup character over the course of time.  At most, I believe I've added up to 2lbs to one high gravity ale, and it remained that way for about 4 months before it smoothed over.  In that sense, yes, I should have used the term "notorious for taking longer to mature".
Comment: If I add the honey to primary and don't do a secondary do I have to prepare the honey or can I just add it to the primary out of the bottle. I was thinking about 1 pound for a 5 gallon batch.
Comment: You can most likely just add it directly to the batch.  Honey has a lot of antibiotic properties and shouldn't carry any harmful contaminants.  The only time I'd consider pasteurizing it is if it's right off the comb, but that's probably not necessary either, just my paranoia.  You definitely don't want to boil it in a water diluted blend, as that will drive off a lot of the aroma and flavor of it.


SNPs and locations

Question: I am new to reading raw DNA. When comparing two people's raw data, why does one person have a different SNP than the other, at the same location, on specific chromosome? But on a different chromosome there will be the same SNP, at the same location, for both people.
Comment: Genetic variation, my friend. People are bound to share similarities and have differences in their DNA, as influenced by errors in transcription, the environment, inheritance, etc. SNPs can be functionally significant or insignificant.
Comment: I think it is important to point out that "on a different chromosome [..] at the same location" is *not* the same location, and that there is not necessarily any relation between similar positions on different chromosomes. I presume you mean something like 'at basepair #74 501 on Chr1 and then also basepair #74 501 on Chr6'. These are totally unrelated positions in the genome, these chromosomes are independent. 2 genomes may vary at one position and not at the other, it's unsurprising.

Is this what you mean? We should be clear about this.
Answer: Because that's how genetic variation works. SNPs are called single nucleotide polymorphisms for a reason: they are polymorphisms. This means that they are loci where different individuals will have a different nucleotide. This is precisely why they are studied and why we have databases of SNPs and the various genotypes they can manifest.
Remember that mutations can occur spontaneously in a single individual. In fact, they can appear spontaneously in a single cell. This means that if you sequence the genome of two different cells of the same individual it is actually possible that you will find small differences.
Finding small differences between different individuals is certain. Our genomes are not identical and while most differences will be in non-coding regions, you will also have SNPs within genes. How much of our phenotypic variation depends on such small differences is an active topic of research but it is safe to assume that small, single nucleotide changes cause at least some of the variation you see in the people around you.
In any case, what would be surprising is if two individuals were to share the exact same SNP forms for all SNPs in their genomes (I'm sure this happens, but I would expect it to be the case only for close relatives and probably not even then). This variation is the whole point of SNP and the only reason we analyze them.
Answer: It sounds to me as though you have misunderstood something about the chromosomes that make up a human genome.

on a different chromosome [..] at the same location

is not the same location at all. There is no surprise in finding 2 genomes to differ in one place, and not at another unrelated place.
edit If this is a mis-reading of your question, and you meant that the 2 persons' SNP was "at the same location" as the other person, then the rest of the answer is irrelevant. 'A SNP' refers to a location, given a name/identifier for the purpose of measuring variation with SNP-chips; necessarily the same location in any person, which may vary, but needn't always differ between everyone (come on, there are only 4 possible values). You should re-phrase your question "why do they differ at SNP 1 and not at SNP2?".
Background
SNP means nothing more than 'a single basepair in the genome, that might vary in a population', so let's just talk of 'difference at a position'.
A single haploid set of the human genome consists of 23 chromosomes, 22 of these are quite 'ordinary', while 1 is involved in sex determination. Of course, most of our cells are diploid and so we have 2 of these sets, with pairs of Chr1, Chr2, ...Chr22 and X/Y.
What I think your problem isn't, that you perhaps thought it was
I haven't analysed large bits of genomic data but I believe heterozygous positions (positions at which one individual's paired chromosomes differ) are represented in that individual's sequence data. For this reason, I do not think your question is asking 'how can 2 persons have a difference at basepair x on one copy of Chr1, and no difference on the other copy of Chr1' - because both copies of Chr1 are merged as one person's dataset.
In fact it's impossible to assign (meaning to group in to haplotypes) heterozygous sequence to either one copy or the other without more information, i.e. sequences from parents & grandparents, to see which variants are inherited together (are linked).
What I think your problem really is
I think you are asking 'how can 2 persons have a difference at basepair x on Chr1, and no difference at basepair x on Chr6 (say)?'
This is easily answered. Basepair 100 of Chr1 is a completely different and unrelated position in the genome to basepair 100 of Chr6. There is no reason to expect that these positions should be related.
A helpful thought experiment
We can concatenate the chromosomes rather than re-setting our count at the beginning of each, then bp 100 of Chr6 will instead be denoted (approximately) bp 1,080,000,100 of the genome - this makes the difference in these positions crystal clear.

SNPs and locations


Simplest method to retrieve single (and only) row in SQLite using PDO

Question: I have this PDO
$stmt = $db->prepare('SELECT * FROM channels WHERE id=:id');
$stmt->bindValue(':id', $id, SQLITE3_INTEGER);
$result = $stmt->execute();

What now is the simplest method to access the row returned using $row['column_name']?
I know that for sure the query will only ever return a single row as it's impossible to have more than 1 row with the same id so I am looking to keep the code as simple as possible to access that row.
Examples I've seen online are quite long and complex, using while loops to loop through rows etc. that I don't need.
Answer: It should be as simple as
$row = $stmt->fetch(PDO::FETCH_ASSOC);

The examples you've seen probably have something more like
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { ...

because they're designed to process a query result with multiple rows. But if you know you'll only ever have one row, you can just forgo the loop. Of course, this is assuming your query actually executed successfully and returned a result. It would be a good idea to at least check
if ($row) { ...

before you try to use it in your subsequent code.


If a baby was born on the ISS, what would its nationality be?

Question: If a baby was born on the ISS, what would its nationality be? Many countries grant citizenship to any baby born within their territory, but the ISS is not national territory ... or is it? If a spacecraft belonged to one nation, citizenship would likely be extended by that nation, as happens on a ship at sea.
Comment: One question per post, please. The legal and medical aspects are two different questions. This is also extremely hypothetical; there are no reasonable circumstances that would result in someone giving birth on the ISS.
Comment: This is a weird case where this is a very good edit that resolved the 'too broad' issue and, I suspect, reflects the OP's true intent...and yet it invalidates an existing answer, which is typically frowned on. In this case, I voted to reopen because I think the existing answer is not based on the true intent.
Comment: @OrganicMarble - complicated by the fact that the word alien has two common uses, one involves nationality, the other refers to life that did not originate on Earth. I agree that likely the OP was referring to the latter in the original post, whereas the edit changes the question to one of nationality. Regarding the latter meaning of the word, I guess it becomes a matter of semantics, but a child born to humans in space (for example on Mars) would be considered of human origin, not alien. Wikipedia defines it as _".... alien life is life which does not originate from Earth."_
Comment: Related on [politics.se] : https://politics.stackexchange.com/q/34988/12027
Comment: In terms of OG to a human baby, it seems no mammal has been born in space https://space.stackexchange.com/q/40363/26356 but results for other animals suggest a live birth without special care is unlikely.
Comment: _"If a spacecraft belonged to one nation, citizenship would likely be extended by that nation, as happens on a ship at sea."_  In the case of ships and planes, in most cases the parents will apply for citizenship for their child in their own country. In the rare case that one (or both) of their countries denies citizenship, the U.N. Convention on the Reduction of Statelessness article 3 says "_birth on a ship or in an aircraft shall be deemed to have taken place in the territory of the State whose flag the ship flies or in the territory of the State in which the aircraft is registered"_
Comment: @OrganicMarble ... was the OP asked to approve the edit? That would be polite. I assume the intent was to enquire about citizenship, not species, but I may be wrong.
Comment: @Woody - in my experience I have had edits occur to my posts without me being asked. Presumably that's the case when the editor has high enough rep. Not to start a Meta discussion, but the unwritten rule seems to be that it's okay to change intent when it's a first time poster and the question is otherwise unworkable, since a first time poster is less likely to engage in discussion, and also their attempts to fix their question often makes it worse. But to OrganicMarble's point it sometime requires some side-stepping around existing answers.
Comment: @StevePemberton ... I have (very rarely) been asked to approve suggested edits to my posts. Seems like a polite thing.
Answer: If a baby were born on the ISS, it would (probably) generally be treated the same way that it is handled here on Earth if babies are born on foreign soil. This means, it will be determined primarily on the citizenship of the parents.
Specifically, there are two primary legal contexts here: "jus soli" (right of the soil) and "jus sanguinis" (right of blood). Jus soli is the reason people born on USA-territory are automatically US-citizens, however jus sanguinis is more common worldwide, where the citizenship of the child is determined by those of the parent, regardless of birth-location.
For example, if a child that was the result of two German citizens was born on the ISS, it would be a German citizen as Germany generally uses a jus sanguinis system for their citizenship.
With US citizens it's a bit more complicated and fuzzy, but generally a child born to two US citizens will also automatically be a US citizen, regardless of where the birth takes place, provided that at least one of the parents has had a residency in the USA in the past.
Addendum: The ISS is a bit special because it is not "truly" international, but rather, each country maintains legal jurisdiction and authority over their sections. In the US sections, US law applies, in the Russian section, Russian law applies, etc. Despite this, the individual sections are explicitly not counted as "sovereign territory" which is the requirement for jus soli [source].
Comment: The question thus made more interesting by specifying ISS - International Space Station, which opens up a large number of possible situations depending on who the parents are and what their nationality is. Although while it's a likely future situation on Mars, it's unlikely to occur on ISS as it would have to be a rare type of cryptic pregnancy where realization of pregnancy doesn't occur until birth. Online sites like WebMD claim this happens about 1 in 2500 births, which seems absurdly high, I'm guessing this statistic includes people in 3rd world countries with essentially zero medical care
Answer: No
The baby might have been born in space, but its parents, i.e. the ISS astronauts, were Homo Sapiens who originally came from Earth.
So, your "baby" is about as "alien" as a panda i.e. your baby is not an "alien" even if you decided to paint him up green and attach antennas to his head.
Unless your setting in thousands of years in the future where "space-humans" and "Earth-humans" have diverged into two different species, chances are, your "baby" is about as alien as a rock.
Comment: Sometimes I feel like an alien simply by posting a question in a new Stack Exchange site, and in the real world I am required to carry an Alien Resident Certificate with me at all times. And yet, to the best of my recollection at least, my parents at least *presented as human.* Go figure :-)
Comment: Your answer focuses on only one of the meanings of "alien", i.e. nonhuman. The intent of the question is not clear, but I suspect that is not what is meant.
Comment: @OrganicMarble - true that it was not specified, but my guess is that if a first time poster uses the term alien in a question about space with no other clarification, they are more likely talking about ET. Probably a lot of people on here, including myself, read the question and dismissed that interpretation as being more nonsensical and started thinking about the more relevant question about nationality. But it's probably not unrealistic for someone to assume in an answer that the original intent of the question was about extraterrestrial not extraterritorial.
Comment: @StevePemberton the problem with that interpretation is that thinking humans on the ISS would give birth to a non human is just dumb. I give the OP more credit than that.
Comment: @OrganicMarble - I don't normally make that type of assumption without knowing more background, I think you are being generous. Which is good and a standard that I should try and live up to more often. Going only by a somewhat vague question _"if a baby was born on the iss, would it technically be an alien?_" I would normally lean towards interpreting by what a random person on the Internet would mean by that. But on further reflection the 2nd and 3rd questions that they asked (in the original question) were reasonable questions, so maybe they were referring to nationality in the 1st question.


Why can't we just increase the bit length to counteract shor's algorithm?

Question: I know that it sounds like a very stupid question but if Shor's algorithm has a complexity  of roughly $n^3$ why cant we just increase the bit size until the time for the algorithm to run is unfeasible on a quantum computer or would it just take too much memory and too much computation for RSA/ECC to be worth it?
Comment: There is a paper by Bernstein et al. that does exactly this. If I remember correctly the RSA key has to be increased up to one terabyte to be secure. Link to the paper https://eprint.iacr.org/2017/351
Comment: A question related to the pqRSA https://crypto.stackexchange.com/questions/59591/why-is-pqrsa-in-the-nist-pqc-submissions?rq=1
Answer:
if shor's algorithm has a complexity of roughly n^3 why cant we just increase the bit size until the time for the algorithm to run is unfeasible on a quantum computer

The problem is that the amount of work needed by the honest parties is also roughly $n^3$, hence we don't have that much advantage over an attacker.
To be fair, we do have a few advantages:

For RSA, there are optimizations available for the honest parties that aren't there for the attacker, for example, the CRT optimization on the private operation, and short exponents on the public one [1]

The attacker has to run his operation on a Quantum Computer, which will likely be a large constant times as expensive as a classical one.

On the other hand, both these advantages don't add up to enough (especially given that we also assume the adversary has considerably more computational resources at his disposal than we do).

[1]: I believe that, when targeting a discrete log problem, Shor's can take advantage of knowledge that the exponent is small, and so that discrete log optimization doesn't help us.
Answer: The main reason is because any such technique has at best a polynomial gap between

the effort honest parties must spend to compute the cryptosystem, and
the effort adversaries must spend to break the cryptosystem.

Cryptography from a polynomial honest-to-malicious hardness gap has been known for a while.
In fact, one of the earliest public-key cryptosystems (before RSA by a few years iirc) went by the name of Merkle's Puzzles, and had precisely this property, namely they took $O(n)$ time to compute for honest parties, and $\Omega(n^2)$ for adversaries. See Public-Key Cryptography in the Fine-Grained Setting for example.
Moreover, in the random oracle model, this is size of gap is known to be optimal, at least in the classical setting.
This is to say that if you are going to "settle" for a small gap between honest parties and adversaries, it is perhaps better to do other things than simply RSA "scaled up" appropriately, though perhaps it is best to simply use a lattice-based scheme instead.
Answer: That's what CNSA 1.0 did: minimum RSA key length is 3072, minimum AES key length is 256, and minimum SHA length is 384.  CNSA 2.0 goes beyond that with some new algorithms.
Comment: This doesn't answer the question...
Comment: How does it answer the question?  The question was "why can't we use larger RSA/ECC modulii to address concerns about quantum computers?"  CNSA 1.0 doesn't address quantum computers at all - CNSA 2.0 does by saying "don't use RSA/ECC, instead use those algorithms over there"
Comment: @poncho but it does senor, but it does.


What should a well-designed high contrast function do?

Question: I want to make my website accessible for nearly everyone. I already have a function to increase font-size. Now I am doing the high contrast function.
However, how should such an interface for visually impaired look like? I already asked another person who is visually impaired and he said light text on dark background is better for him. And in regards to color: He likes dark green.
I would appreciate it if you could give me some other best practices to make the visit of my website a good experience for visually impaired.
Should I also change the font of my website? If yes, what type of font?
Comment: Are you attempting to home-brew your own font scaling and high contrast features within a webpage? Better to provide an accessible baseline that plays nicely with browsers' built-in font scaling and contrast features.
Answer: Do more research. Asking one person will only get you that person's preference - Ask lots more people and look for patterns in the results.
The RNIB (UK organisation for blind and partially sighted people) recommends yellow text on a black background but this may not sit well with your particular users.
Not only do you have to think about contrast but you have to think about colour combinations too. Colour blindness affects around 4.5% of the population of the world - That's 9 in every 200 users. Luckily there are tools like the Colour Contrast Analyzer to help you out with that.
Also, vision is not the only area to consider accessibility. If you have small controls that are placed close together that's going to be difficult for people with muscular or motor problems who find it difficult to control a mouse easily. Some people cannot use a mouse at all - does your product allow for keyboard controls? Does your product rely on audio cues? If so then you'll need a visual equivalent for deaf people.
Finally, the most tricky thing to cover is accessibility for people with cognitive difficulties: does your product make sense? Is there too much information presented in a disorganised way or is it broken into easily understandable chunks? Have you cut out all of the unnecessary form fields and other junk?
I made a low-level simulator if you want a small glimpse into the world of someone struggling with accessibility issues.
Comment: Loved the simulator!
Comment: +1 for teh answer and +100 for the simulator. May I translate it to Spanish?
Comment: @Devin, I've messaged you on Facebook
Answer: Think of high contrast text and using more than just color.
There are a lot of accessibility guidelines out there. I'll mention two examples that I have come across in projects before. Check the attached links for extra guidelines.
High contrast text
Check the Web Content Accessibility Guidelines for a lot of useful information on this topic, including contrast for text;

1.4.6 Contrast (Enhanced): The visual presentation of text and images of text has a contrast ratio of at least 7:1, except for the
  following: (Level AAA)

Large Text: Large-scale text and images of large-scale text have a contrast ratio of at least 4.5:1;
Incidental: Text or images of text that are part of an inactive user interface component, that are pure decoration, that are not
  visible to anyone, or that are part of a picture that contains
  significant other visual content, have no contrast requirement.
Logotypes: Text that is part of a logo or brand name has no minimum contrast requirement.

Source: Web Content Accessibility Guidelines (WCAG) 2.0
Use more than color
Imagine using green and red as indicators of positive and negative in your design. Users with color blindness can have trouble with these colours. Also use shape in combination with your colours for positive and negative. For example; use a triangle pointing up or a thumbs up for positive.
Here's another list of accessibility points to consider that includes the above mentioned point (number 11);
Accessibility Checklist
Answer: To add to the above answers.
Contrast is not the only thing to keep in mind:
1) Is your website ARIA friendly? Can it be easily browsed through a screen reader?
2) Is it responsive or developed in such a way that the website remains functional in extreme levels of zoom? A lot of visually impaired users tend to zoom (often extremely) while they browse the web. I have encountered users that browse in text-heavy sites with a zoom of 500%. Will your content still look the same?
GOV.UK has several posters that sum all the accessibility issues and suggested solutions quite nicely. Check it out!
Answer: You can inspire yourself by Microsoft Windows. Its High contrast color modes have these features: (I emphasized possible takeaways with bold.)

user interface is drawn by pre-defined minimalistic set of colors. They are Text, Hyperlinks, Disabled Text, Selected Text, Button Text and Background. (Besides these colors, there is a possibility for one or two theme colors which do not affect usability of content - the are for example used as active and passive window frame color, but on the web page the mileage may vary. Unlike in standard color modes, each of the above colors can be customized by the user. Initially, few sets of colors are offered, some using white on black and some black on white.
displaying of background images is suppressed. This is mostly visible on web pages displayed in the Internet Explorer, but actually it is system-wide.
there is a simple way to switch high color scheme on and off (toggle). This is useful when one who usually works in High Contrast mode wants to check original look and then return. (Many reasons for this exist.) Also, all open applications get a system message when high contrast is turned on or off so they can repaint accordingly.


How do I access the emulator control line in Android?

Question: I'm trying to change the time zone on my Android emulator. I'm using Eclipse on a Windows 7 machine. To do this it says to enter some commands in the command line, but doesn't say how to access the command line!
So how do I access the command line in Windows 7 using Eclipse?
Answer: Hit windows + r type in cmd
then type in
adb shell

Answer: Command line means the windows command line.  Click the windows orb and search cmd.  It might not work initially because you have to set the PATH variables properly.
Instructions from Android Developers site here
On Windows, right-click on My Computer, and select Properties. Under the Advanced tab, hit the Environment Variables button, and in the dialog that comes up, double-click on Path (under System Variables). Add the full path to the tools/ directory to the path.


Working with CDF Deployment

Question: I've been working with FreeCDFs in Mathematica 10 and it has been going fine as long as I do not pull from a database or access local files. I recently purchased the Mathematica 10.2 Enterprise Edition because I was under the impression that I would be able to create CDFs that would access MySQL. When I try to create my CDFs and embed them into my HTML code when I open up the browser I see the manipulate window but where I should see a table of computed data I just see the definition of my function and variables the manipulation should be running through. How can I get my CDFs to pull MySQL data and run it through my function?
Answer: I contacted wolfram and what I needed to do was make sure that all my code was within the Manipulate and after defining my changing variables the rest of my code lies within a Initialization command. You also must have the Enterprise edition to make CDFs with DatabaseLink.
Answer: The free CDF player can not import data. That can only be done by the CDF player pro. Did you try to use SaveDefinitions->True within Manipulate?
That should store the needed data for Manipulate inside the CDF.
Comment: I have tried that but it crashes _Mathematica_ because of the amount of data it would need to store. Would anyone trying to access my embedded CDF have to have CDF Player Pro to use my interactive function? @Elsibär
Comment: On a [Wolfram Blog posting](http://blog.wolfram.com/2013/03/11/using-mathematica-enterprise-edition-to-create-professional-apps-tools-and-reports/) it says "Enterprise Edition allows you to create EnterpriseCDF files, which provide enhanced capabilities that can be deployed via the free Wolfram CDF Player.". So I presume that Enterprise Edition produces a type of CDF that makes the free CDF Player behave as if it is CDF Player Pro.

Working with CDF Deployment


2006 Dodge Durango 4.7 L V-8 running hot

Question: My 2006 Durango runs hot after a while . It's not losing much coolant. Also if the cap is off and you start it, Iit will blow back water out the opening.
I thought it may have a head gasket crack or even a cracked block. Because it had a miss.
I put some K&W nanotechnology head gasket and block seal. I followed the instructions except I didn't pull the plugs to check for coolant remnance. I FLUSHED the radiator with water 4 times.
(Still  running hot and I believe the water pump is pumping)
Comment: Is the fan running?
Comment: When you say running hot, does it go all the way to overheating, or sits at about 3/4 of the gauge.  Does it happen when sitting, driving, or the highway, all conditions?  Loosing coolant at all is the sign of a problem and should be addressed.  If the system cannot pressurize, it cannot cool efficiently.
Answer: Head/ Block seal doesn't always work. It's also pretty controversial about what happens when you put it in. I've used it a few times and it only worked once. There is also no real scientific evidence that it works, it's more of "Theoretically" it should work.
That being said, don't automatically assume you have a head leak or block leak. Running hot can also cause misfires. Especially with that truck. Chrysler computers are super finicky.
Blowing water out of the cap, can be normal. This also could be an indication of a thermostat issue or a clogged heater core. The first and easiest thing you could do, Is grab one of those master cooling system testing kits from an auto-store. Make sure everything is sealed up and pressurize the system. See if it holds pressure. If it doesn't hold pressure, then you know you definitely have a leak.
Once you've determined whether or not, you can begin further diagnosis. There is a lack of information here unfortunately, so it's a bit difficult to tell you the proper diagnostic path you should take. You can always come back and update your question so we can edit answers to properly guide you.
Comment: Block sealer clogs the radiator more than the leak in most cases. Combustion chamber leaks into the cooling system will not always show up using a pressure tester on the radiator.


Translate Guestbook

Question: I am trying to create a website in 2 languages, Greek and English. While I translated almost everything, I can't seem to get Guestbook to translate. It only shows in 1 language. Any ideas of how to use the Guestbook module in a  multilingual way? The module I am using is this.
Comment: use i18n module
Comment: I am using it. So there is a workaround that with i18n that allows this(?)
Answer: You can download Guestbook project translations from here.

Translate Guestbook


How to Set up Data Driven Pages using arcpy?

Question: I've read a lot about the topic data driven pages. I'm writing a python script for ArcGIS and  I've defined my stripmap using the arcpy.StripMapIndexFeatures_cartography command and now I have to set up Data Driven Pages with all the parameters it needs. My only problem is that I cannot understand how to do this. Is there a specific command in the arcpy library or a specific workaround to do this?
Answer: The right answer is you can't create or set up DataDrivenPages using arcpy at all. Most up-voted general answer to read documentation is helpful only to the point that you can find in it:
"The reverse is also true: map series can be completely scripted using arcpy.mapping without using the Data Driven Pages user interface in ArcMap, but there are good reasons for combining both techniques."
It might sound like you can create such object, right? Well you have to read more to get slapped:
"Data Driven Pages must first be enabled and authored within a map document (.mxd) using the Data Driven Pages toolbar in ArcMap before it can be referenced with arcpy.mapping."
If you look at the class itself, apart "currentPageID" the rest of few properties it has are Read Only. Few methods available will also not help you to set any property at all. The workaround is to program everything yourself without using data driven pages at all.
Answer: If you have not already gone through the ESRI arcpy.mapping tutorials and ArcGIS Resources pages, they have heaps of sample scripts to comb through.  I would suggest looking at these first:

arcpy.mapping / Map Automation Group
ArcGIS Resource, Python for ArcGIS

Tutorials:

Introduction to arcpy.mapping
Getting started with arcpy.mapping tutorial
DataDrivenPages (arcpy.mapping)

If you are using 10.0, you can find similar help topics for it on the 10.0 help site.
Comment: Hi Ryan, and thanks for answering.. my exact problem is that the [tutorial itself](http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000030000000) says: "Data Driven Pages must first be enabled and authored within a map document (.mxd) using the Data Driven Pages toolbar in ArcMap before it can be referenced with arcpy.mapping."
Comment: well.. now I'm trying to write a script to automatize everything - but I cannot - from how it seems. And maybe now I will be forced to stop my script at a certain point and say the user: "please, open the ddp setup and set this parameter in this way - this other in this way.." which is near horrible to me. But it seems there's no other way if I can't ENABLE data driven pages from arcpy, or arcpy.mapping.. or wahtever it is :(
Comment: Hi! Do you have any update or solution on this issue? Is there a way to automate everything, including "enabled and authored within a map document (.mxd) using the Data Driven Pages toolbar in ArcMap" you mentioned? Thanks!
Answer: You can largely avoid opening the reference mxd by using layers. This is generally how arcpy.mapping operates anyways, is through layer files.
For example, I have used a workflow which looks something like this:

arcpy.MakeFeatureLayer_management - here is where you can subset the data
arcpy.SaveToLayerFile_management
arcpy.mapping.UpdateLayer - allows you to switch out an existing layer in the mxd with the one you have created for your needs
arcpy.mapping.DataDrivenPages.refresh()


Could not compile service support class

Question: I have been having this error since for Android compilation .
My sdk url is oky, emulators are being detected but i cant generate any apk or run any android based app. Could
Answer: Your question is quite incomplete. Which LC version are you using, which Java JDK are you using, do you use Android Studio (just for the sdk) or do you have it installed via cdm? You need the Android sdk and Java Jdk.

Could not compile service support class


Add MVC Controller with Views Using Entity Framework (2.0)

Question: Controller will not create when adding a new MVC 5 controller with Views using Entity Framework.
The error message is:

The Output window:
<code>Finding the generator 'controller'...
Running the generator 'controller'...
Attempting to compile the application in memory.
Attempting to figure out the EntityFramework metadata for the model and DbContext: 'DayRateEmps'
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available.
Using 'C:\Users\xxx.yyy\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Process is terminating due to StackOverflowException.
</code>
Comment: Clean and rebuild your project and it might solve the problem!
Answer: Rebuild your application and try again. If that doesn't work then your entity model is not working right. In my case my entity model was in another project folder hence i was unable to auto generate any of the controller. So i manually made a controller an empty controller and imported that project and model.


Nrf24l01 smd pcb placement tips

Question: I am working on pcb design with nrf24l01 smd. I have read somewhere that nrf24l01 module has problem while communication when it is placed with its antenna within the pcb. I want my module to be within the pcb as much as possible to save some space. I will be making the pcb at home and will be placing atmega 328p smd on the opposite layer. Should I fill the opposite layer with ground pad?
Answer: You need to keep the ground plane away from the antenna. The rest of the module doesn't care (and having a ground plane under it can help with unwanted EMI).
Here's a design I did recently for a customer with the same module in it. It's placed near the edge of the PCB with the ground plane cut out around the antenna:

That layout is actually set up for either the small SMD, the SMD with PA+LNB or the thorugh-hole version. The important thing is that there is a nice big exclusion zone in the ground plane where the antenna is.
Comment: Thanks for your answer
Comment: Hi @Majenko! Would it be okay to have the NRF24L01 module and ATMega module on the same PCB with also the antenna on the PCB?

Nrf24l01 smd pcb placement tips


How do objects stabilize to one Color?

Question: I have been studying how light and vision works. I've come across how colors are formed. From what I have researched ; An objects Color is created from the light that hasn't been absorbed by the object and reflected from it. This makes sense, however my questions follows: If light from a light bulb hits an apple and the Red colored light  is able to escape it, we shall see a red apple. But what happens if light from a light bulb hits a green cup and then the green colored light reflected off the cup hits the original apple. Now the light hitting the apple does not contain all the colors of like white light, only green. Do our eyes only detect the light reflecting from first contact with an object ? and how does it deal with light bouncing and reflecting of other objects after the initial contact from the light source ?
Comment: It is more complicated than your naive description see https://physics.stackexchange.com/questions/552840/what-determines-whether-colors-you-cant-see-are-visible-or-not/552878#552878
Comment: If you buy a cheap red laser pointer and point it at some non-red objects, you will find that objects we wouldn't describe as red nonetheless do reflect red light.
Answer: It would appear black.
Imagine you have a red apple and a white light bulb. If you shine the light onto the apple and you pass the reflected light through 3 filters(red, blue, and green).
the image on red filter would look completely white, and black on other filters; and if you mix the images on filters you get what the apple really looks like.
what if the apple is purple? then the image on blue and red filters would be white.
and if the apple is white, then the image on all filters is white
Answer: As anna v already pointed out, for the perception of color not only the wavelength of the light, but also the way our eyes work have to be considered. Another point to consider is that an object we perceive as red does not reflect "red" light (at the high-wavelength end of the visible spectrum) at 100% and all other wavelengths at 0%. It also reflects other wavelengths, and the sum of all reflected light is translated by our eyes into the perception "red". So, if the only available light source gave of only a specific frequency of "green" light, the apple would appear as (dark) green, since it reflects that light to a lesser degree.

How do objects stabilize to one Color?


Uncle Elroy's bedroom scene?

Question: There's a specific scene in the movie in which the main character Craig gets a tax notice from the mailman at the door of his Uncle's house. He goes upstairs to his Uncle's room to give him the mail but after two attempts get grabbed into a bed with his Uncle and Aunt trying to escape whatever is happening at the moment. What happened? I never really understood this scene in the movie. I have a link to a video of the clip that I'm talking about.
Answer: Craig's aunt and uncle are shown to be into some kinky stuff, based on what Craig sees in the room, the sex toys, the projector playing what looks like porn, and the way his aunt acts throughout the movie. They probably (probably as in I have no director or actor source) grabbed him in the continuation of some role-playing sex-game they were doing before they fell asleep, not realizing it was their nephew they were grabbing.
To back this sup a bit, here are a few lines from the script:
<code>      Craig: Unc, you got this tax notice, man.

      Elroy: Come here! I'll tear that ass up again! (Elroy implying this is not the first time he has done this)

      Suga: I like it when you treat me rough! (Suga acknowledging this as familiar treatment)
</code>

Uncle Elroy's bedroom scene?


Need some clarification on theorem connecting space dimension with geometric multiplicities

Question:
$$$$The mentioned theorems are: Theorem 9.2 Eigenvectors corresponding to distinct eigenvalues are linearly independent. Theorem 9.3 A linear mapping $ f:V->V$ is diagonalisable if and only if V has basis consisting of eigenvectors of $f$.
$$$$ $1.$ Is there a typo and $v_i\in B_i$ should be replaced by $v_i\in E_ {\lambda_ i}$?
$$$$ $2.$ If I view the line $v_i=\mu_{i1}e_{i1}+...+\mu_{id_i}e_{id_i} \in B_i$ through matrices then the matrix represented by the the enries $\mu _{ij}$
can be transpose, whence there is a matrix multiplication formula hence $v_i$ is also an $nxn$ matrix. Is that the right way to see this?
$$$$Thanks in advance for any help you are able to provide.
Answer:
There is no typo. Every vector in $B_i$ is in $E_{\lambda_i}$ since $B_i$ is a basis for $E_{\lambda_i}$. You could replace $B_i$ by $E_{\lambda_i}$ in the sentence that you are asking about, and it would still read perfectly. However, the author then goes on to talk about the linear independence of $\cup B_i$. Linearly independence is a property of sets of vectors (the $B_i$) and not of vector subspaces (the $E_{\lambda_i}$).
Comment: But then it suppose to be $v_i\in SpanB_i$ because $0$ can't be a basis, isn't it right?
Comment: The way I understand it is that each $v_i$ is an arbitrary basis vector from each $B_i$. However, having read on, the author writes $\mu_1e_1 + \cdots + \mu_de_d \in B$. This is impossible. If $B$ is a basis and the $\mu_k$ are freely chosen numbers then $B$ is an uncountably infinite vector space. I think the author may mean to say $\text{span}(B)$ when he writes $B$.
Answer:
I see this as a typo: It should be $v_i\in E_{\lambda_i}$ in this row and also in the second row $v_i=\sum \mu_{ij} e_{ij}\in E_{\lambda_i}$. In my opinion this way the proof makes more sense.
I don't see how you would view $v_i$ as an $n\times n$ matrix. I would rather say that the vector $(\mu_{ij})_{j=1,\dots,d_i}$ is the coordinate vector of $v_i$ with respect to the basis $B_i$ of $E_{\lambda_i}$. Filling in zeroes, you could also see it as the coordinate vector of $v_i$ with respect to the basis $B$ of the span of all eigenspaces.


Maine Coon attacks my face when I'm sleeping

Question: My 4 year old male Maine Coon jumps on and scratches my face when I'm sleeping, an awful way to wake up. In the dark he might view my head as prey. Besides closing the bedroom door is there any way to stop this aggressive behavior?
Comment: As he's four years old, my first question is, is this a new behaviour (I'm assuming that you've had him from a kitten - perhaps incorrectly!). If you have had him for the past four years, is there anything that's changed that might have prompted this new behaviour? Whilst cats are somewhat inexplicable (which is half the appeal!), there's usually always a good reason for any behavioural trait they show :)
Comment: My cat did the same last night. I did not weak up but there are scratches on my cheek :(. I know what he wants - attention and being petted. It is not agression but he has no idea how sharp his claws are.
Comment: My cat does this too. He has a high prey drive and often stays out all night hunting. However, he likes to come in sometimes in the middle of the night, but always first thing. He lies on my chest in bed, nuzzles my face, sucks on a scarf we have for him, purrs loudly and is lovely for about 10-15 mins. Then his eyes go black, he makes a strange squeak and pounces on my head! He digs his claws into my scalp and bites too. I yelp, he gets off and onto the floor... from where he proceeds to pounce up from the floor onto my head, attacking me again!!! Today he got on the bedside cupboard (he ofte
Answer: I can think it two possible explanations for your cat's behavior.  One is in your sleep you are doing something the cat doesn't like, and so naturally responds with clawing.  The other is that cats are nocturnal animals, and so your cat may be getting bored, lonely, hungry, or thirsty at night, and clawing you is very effective at waking you up.
I recommend making extra sure the cat is well provided for during the night.  Water and food (if you feed it at that time) full.  Plenty of toys, scratchers, and entertainment.  Litter box clean.
Unfortunately, it may be that the cat is just seeking attention, or you are annoying it in your sleep.  I can't think of a solution to that beyond shutting the cat out of your room at night.  It's much easier to discipline the cat to stop scratching at the door than it is to discipline it to not claw at you for you to wake up, especially since the cat is automatically rewarded by the clawing while you're asleep.
Answer: I gave mine a soft but firm slap on the head, just enough to show who is boss but not hard enough to hurt it, as well as yell at it. The cat has not done it since, and the cat is still affectionate.
The cat sees you as a big cat and your hand is a big claw; because you're bigger you cat will back down and accept that you are the master.
Answer: Of course there is a way.
In fact there is a way for everything, just with different level of complexity.
Most of the cats (in that count Maine Coon) love sleeping with the owner.
Doing that, it is very unlikely that it will "jump and scratch your face".
Alternatively, you can simply teach him/her to explicitly not do so.
However, you must understand that animals base actions on instincts, thus you must somehow influence danger after her doing that to you and/or joy after NOT doing that to you.
Also, what makes you think it is because of "aggressive behavior" ?
It looks like a cat's catchy game to me.. besides, everyone know that cats could be very active during the night.
Answer: I had a cat from kitten age that did this also.  It would walk along the back of the couch and pounce on heads, pounce on heads sleeping in beds, pounce on your back in the middle of the night...
I lived in the country and the cat was an indoor/outdoor cat (free access).  I was young at the time and inexperienced in cat training.  The behavior continued through all of the cat's (short) life. I believe the instinct that drove the behavior lead to an untimely demise through miss adventure.
My answer is that it maybe possible to train away this behavior, and it may not.  If it is I can't tell you how.  There are some behaviors that cannot be modified with casual training, and the investment for intensive training may be more than you want to invest.
In the case of your cat, I would recommend not allowing it outside. I would expect a negative impact on other animals in the area, until your cat picks on something a bigger, faster and stronger then it's self (besides you).
Answer: The best way to deal with cat attacks like this are to cry out loudly in pain. This tells the cat that they hurt you and that you disapprove of the attack. If you and your cat have a good relationship, they won't want to hurt you. Cats don't like loud noises so crying out will also help train the cat not to attack.
Does he attack you at all during the day? Is the cat otherwise sweet and affectionate with you?
Answer: I am a 61 year old person and have had 5 Maine Coons kitties at various times through my family's life.  I tried to lay a foundation of love, distraction if necessary (kinda like kids....rather not scold, but let's enjoy something new and fun! Like a catnip homemade sock). I now have an 11 year old Maine Coon heavyweight who has been endulged and adored by my family since we brought him to his Old Orchard home at 8 weeks old. He fit in one hand when we brought him home. Now my lap on nail-trimming day is a snuggle of a fit he and I respectively attend to every month.
Now, he pets me awake every morning. He pats my hair while purring, and pets my eyes and cheeks and chin. I typically "play possum" while my 21 pound mouser cat gently wakes me up. Cats can actually gently pet their beloved family with love. He dispatches any varmints quickly! But he pets my eyes and face exactly the way I pet my sweet Coonie.
Please be gentle and loving with your cat or kitten. They have a great capacity to return kindness and love. Please don't ever swat, hit or yell at a kitten.
My "pet" goal on my bucket list was for one cat to have a beloved life. Too many animals are unloved or abused. A beloved pet petting you back every morning on your face is, for me, a sign Heaven exists on earth. My daily gratitudes begin with a Maine Coonie wrapping his big paws around my face.


Sci-fi show where creature snatches up soldiers in the jungle?

Question: I recall seeing this scene on tv from the early 2000's. It was not from the movie Predator but it is similar. The creature came down from the sky and snatched this soldier up into the air. Next scene I remember was a bunch of military personnel being in this outdoor concrete camp and the creature coming back. Some minor details were they were in a jungle terrain and it was sunny out. The alien like creature from what I can remember was a cross between Jeepers Creepers and Predator.
Comment: If someone posts the correct answer, you can accept by clicking on the checkmark by the voting buttons as per the [tour]. You can do the same with your other question, of course.
Answer: This scene from Starship Troopers ?
Answer: Might you be looking for Code Red - The Rubicon Conspiracy as per 1990s film, knockoff of Alien and Predator franchises, included a jetpack and a fanged frisbee?

Code Red: the Rubicon Conspiracy is a 2001 TV movie aired by UPN involving a dishonorably discharged Army Lieutenant by the name of Peter Doyle (played by Brian McNamara) who is called in for a rescue mission regarding the Rubicon Station in the midst of Africa. His brother, James Doyle, may be the last remaining member of the last mission squad. He was also the reason for Peter's discharge, The Rubicon Station has a nuclear failsafe due to detonate in 20 hours if it's not reset and there are local rebels in play. Furthermore, Doyle quickly learns that some of his opposition is not from this planet, but not all of them are enemies.

There are two aliens, one reptilian in armor and one with tentacles that suck people dry. It's set in a jungle. The reptilian armored alien moves around with giant leaps, and I think there is at least one scene where he leaps in, grabs a soldier, than jumps out.

 He was actually saving the soldier from the other alien, but the squad doesn't realize that until later when they find a way to communicate.

Clip showing alien picking up fallen soldier and leaping away
https://youtube.com/clip/UgkxT70ZBiwYt0J3f14ZKWRk6t2t8NWn_kCc


How should I store an old project?

Question: As a freelancer, I come across many projects. Its almost impossible to store a backup of all of the projects on my laptop. What are some better options to store them?
Comment: Bitbucket has free private repos, if your using version control with them (hopefully you are), than I'd recommend that
Comment: I would suggest BitBucket as well.
Comment: Keep in mind that you'll probably need the corresponding software, and something that will run it, when you retrieve the project. If it is "just" artwork there may be many newer tools available. If it is a Windows Mobile application that would only build with an ancient compiler, you may be out of luck. If the tools only run on a Lisa ... . It might be wise to save a copy of the tools and the project in a media rated safe. A second copy on an external drive makes access convenient. Don't trust a single copy. Cloud services disappear, drives fail, optical discs get scratched, ... .
Comment: Some projects require full copies of the development environment and production/testing rigs. Turn them into virtual machines and put them into LTO tapes.
Answer: There are two sensible options, depending on the likelihood you'll need to look at them again:

Burn the old projects to two DVDs, storing one "off site" somewhere
Storing them in the cloud on something like Dropbox
Comment: Note the life expectancy of CD/DVD is under 2-5 years. [the National Archives](http://www.archives.gov/records-mgmt/initiatives/temp-opmedia-faq.html) who used a lot has a FAQ about it.
Answer: I have mine stored on USB flash drives.  I keep a fireproof safe to store flash drives and 'must' have development CDs.
Comment: A single-bit upset due to a solar flare or a stray GCR will fry the data. Of course, the safe may make it less probable.
Comment: @DeerHunter - With USB so cheap these days, make three copies.  Put one 'within reach' and two others in 'undisclosed locations', with appropriate environmental protection.
Answer: I'm a bit confused by your question:

Why are you storing backups on a laptop in a first place? Laptops are for work; backups are generally stored on dedicated servers or tapes or, for smaller companies, on external hard disks.
Why do you find it impossible? Because of the space it takes? What exactly is inside which takes so much place?

So, how should one store a backup of all projects? Here's some guidelines.

Have dedicated hardware dealing with backups.
Ideally and if you have enough money, you would have a machine in your datacenter which will make regular scheduled backups of your version control. Depending on the size of the changes and the risk you can take, it may be scheduled as well to one backup per hour as to one backup per week.
In a less expensive environment, you'll simply have an external hard drive you'll plug regularly to do the backups on it. Beware of everything which requires manual effort or any manual intervention: while an automated process done exclusively by machines is mostly flawless, people asked to do the same task again and again can potentially forget doing it, or make a mistake or simply stop doing it, because they consider that they have "more important things to do than a backup" in time pressure context.
Always keep at least one backup off-site
There is small benefit in making backups if all those backups are stored in the same room or building. In case of fire, flood or anything which can affect the entire building, your data can be lost altogether with every backup you made.
Test your backup strategy
A few weeks ago, I was about to make a RAID configuration change on a NAS. The operation could potentially result in losing all the files. I had a not so bad backup strategy and data replication, and was sure it works pretty well, but I still decided to check twice if everything is fine. It appeared that a configuration change done a few months ago made the backup tool switching several backup destination paths to directories the backup tool wasn't able to create. This meant that I could have lost more than three months of a part of important data.
Do incremental backups of version control
Version control can grow pretty fast if you work on large projects with lots of people involved. Dumping tens of thousands of revisions for several gigabytes of backup every hour or every day will be too expensive in terms of resources.
Most version control systems allow you to dump specific revisions. In my company, moving from daily entire dump to daily incremental dump allowed to considerably decrease the load on version control server, as well as waste more than 85% less space on backup machine (which also means wasting less network bandwidth for off-site backups).
Don't delete your work
Some small companies with no money to buy new hardware are often tempted to delete some of the files involved in the original projects.
For example, a photographer may be asked to delete RAW files which may waste 30 MB or more space when he finished to work on a photograph and has the final JPEG.
Another example is to wipe out older versions from a version control, for example older than one year.
In both cases, the idea is bad, and can have important implications. For example, it would be difficult for a photographer to prove that a stolen photo was belonging to him if the only thing he has is the same JPEG that the stolen one. Wiping out older versions from version control erases statistical data which can be used in business intelligence.
Check what's stored in your version control
Once, when I was auditing a company, I found that the version control was slow, fat, and totally unusable. Commits took forever, and desperate programmers preferred not doing any commit at all and share the source through the network directly. There were no backups, because it was practically impossible to do a dump, given the size of it.
After a bit of search, it appeared that every compiled file was in source control: every binary, every temp file, everything. This meant, if I remember well, that each commit was 30 MB in size. Indeed, this made it nearly impossible to do commits and increased the number of times programmers would go out to smoke or drink coffee.
Storing anything binary in an ordinary version control is an issue. This includes storing images or Word documents.
If your repository is fat, there may be something wrong in a way you use it. Check what's inside, and react in consequence.
Comment: Your first point is exactly what I was wondering.
Answer: Well there are many ways to store backups but because the backups are not going to change over time and you might want to store them for a long time (probably >20 years). I would suggest that you use multipliable technologies to make backups, you never know if a technology will be unable with the dates technology in the future. I would recommend that you use at least 3 or more of this option. Store them in different places, like one at home, one at the office and so on in case of a fire or something else that would destroy the device. Also use different file system technologies, preferable at least one that is open source.

CD
DVD
Blu-ray
Hard disk drive
USB flash drive
Solid-state drive

I would not recommend using online backup like dropbox or any thing like this, you never know if company that is holding your data will go bankruptcy in the future. Also if you use a service like this the company have access to your source code and can do what the hell they want with it. You can use this as a complement to what i have mention before but i would strong suggest you encrypt the file before uploading them.
Comment: There's nothing wrong with using an online backup as long as you don't make it your *only* backup. If you use Crashplan, their software allows you to encrypt your data before sending it off to them (plus, you can use it for local backups or backups to other computers you own, as well as their servers).
Answer: The technology changes too fast, there are definitely NOT any "forever" solutions that don't involve you maintaining your backups.  Keep multiple copies in different places and media.  Today, flash drives and online backup look like good choices.  As those good choices become less good and eventually die, keep moving on to new good choices.  (My first set of archives were on paper tape.  Second on 7 track mag tape.. you get the idea)
Long term archives should be in sealed checksummed packages, so you can at least
be sure they're complete and uncorrupted.
Don't overlook the importance of storing your archives with context.  I guarantee that in 20 years, you won't have a clue what most of the crap you saved was for; and worse, that if there's some particular gem you're looking for you'll despair of locating it or using it once located.

How should I store an old project?