reloadData not working for UITableView dataSource?

Question: Currently I have a NSMutableArray that loads from NSUserDefaults in my app and feeds the data to my UITableView. The NSMutableArray consists of NSDictionarys which consist of 5 or 6 keys each.
Then in the view where the UITableView is, I have a UISegmentedControl where the user can then sort the UITableView based upon Date or some other things.
So when they click the date segment, I execute this code:
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"Date" ascending:NO];
[self.cellArray sortUsingDescriptors:[NSArray arrayWithObject:descriptor]];

The sorting itself works as I can see self.cellArray being sorted through NSLogs. Although when I call my tableview to reloadData, none of the NSDictionarys actually re-sort in the tableview itself. So programmatically they are being sorted but not in the UI which is extremely odd.
If use this for statement right after the code I posted above:
for (NSDictionary *dict in self.cellArray) {
            NSLog(@"DateKey: %@", [dict objectForKey:@"Date"]);
}

This is what my NSLogs look like if I do ascending:YES :
2012-05-20 13:48:21.008 App[71308:707] DateKey: 2012-05-13 18:19:22 +0000
2012-05-20 13:48:21.009 App[71308:707] DateKey: 2012-05-13 18:19:29 +0000
2012-05-20 13:48:21.009 App[71308:707] DateKey: 2012-05-15 01:54:13 +0000
2012-05-20 13:48:21.010 App[71308:707] DateKey: 2012-05-15 04:01:15 +0000
2012-05-20 13:48:21.011 App[71308:707] DateKey: 2012-05-16 04:08:20 +0000
2012-05-20 13:48:21.012 App[71308:707] DateKey: 2012-05-16 04:13:59 +0000
2012-05-20 13:48:21.012 App[71308:707] DateKey: 2012-05-16 04:32:29 +0000
2012-05-20 13:48:21.013 App[71308:707] DateKey: 2012-05-16 04:32:38 +0000

If I do ascending:NO this is what my NSLogs look like:
2012-05-20 13:56:25.956 App[71468:707] DateKey: 2012-05-16 04:32:38 +0000
2012-05-20 13:56:25.960 App[71468:707] DateKey: 2012-05-16 04:32:29 +0000
2012-05-20 13:56:25.961 App[71468:707] DateKey: 2012-05-16 04:13:59 +0000
2012-05-20 13:56:25.961 App[71468:707] DateKey: 2012-05-16 04:08:20 +0000
2012-05-20 13:56:25.962 App[71468:707] DateKey: 2012-05-15 04:01:15 +0000
2012-05-20 13:56:25.962 App[71468:707] DateKey: 2012-05-15 01:54:13 +0000
2012-05-20 13:56:25.963 App[71468:707] DateKey: 2012-05-13 18:19:29 +0000
2012-05-20 13:56:25.964 App[71468:707] DateKey: 2012-05-13 18:19:22 +0000

So as you can see, the sorting indeed works properly but once I do reloadData after that code, my UITableView does not re-order the cells based upon the Date key.
My tableview is in fact connected in IB and is not nil. I do have a setter and getter for it to if that matters.
Does anyone have any idea why this happening? Or do you need more context/code?
Thanks!
Comment: Show us `tableView:cellForRowAtIndexPath:`. i.e. is it actually reading from `cellArray`?
Comment: I added my cellForRowAtIndexPath
Comment: I'm confused then. That looks fine. Is `cellForRowAtIndexPath:` definitely being called after `reloadData`?
Comment: Yes it is. I NSLogged it and it shows the cellForRowAtIndexPath getting called when I call reloadData. I even added the willDisplayCell delegate method and NSLogged that too and that gets called also. So this is really odd! One other thing I would like to mention is that the cellForRowAtIndexPath and willDisplayCell both get called while I am scrolling my UITableView also, is this normal behavior for iOS 5?
Comment: Yes it's normal whilst you're scrolling - it's getting the cells that are about to appear on screen. Still no idea why this isn't working for you. Can you perhaps post the project somewhere for download?
Comment: Sorry no I cannot since it is part of a bigger project which cannot be shared at all. Any other possible remedies?
Comment: Are you sure you're not setting `cellArray` back to the original array later on or something?
Comment: Aha! That was it! In my segmented control update method I was not setting my cellArray to NSUserDefaults so in my numberOfRowsInSection that was where I was updating the array with what was in NSUserDefaults so that what was preventing it form working! If you post that comment as an answer, I will accept it!
Answer: I'd be inclined to put your logging statement ...
for (NSDictionary *dict in self.cellArray)
    NSLog(@"DateKey: %@", [dict objectForKey:@"Date"]);

in, right after you invoke sortUsingDescriptors as well in your cellForRowAtIndexPath method. I'd also put a NSLog statement right where cellArray is getting initialized (to make sure that you're not accidentally invoking that again ... easy to do if your routines get complicated).
I have to believe that the order in cellForRowAtIndexPath will not reflect the order you got immediately after your sort. Assuming this is the case, either cellArray is getting reset somewhere (i.e. where do you populate it? in viewDidLoad or somewhere else?), or your sortUsingDescriptors is not getting invoked like you think it is.
Just start putting break points and/or debugging messages in your various routines. It's got to be something simple. I just did a test of reloading where I resort as I reload, and the sort orders are being preserved. So it's got to be something simple.


What is Iron Ore used for in leatherworking?

Question: I have been mining Iron Ore and I have maxed out my collectibles store (250 lumps). I've been able to use it since I became level 75 in leatherworking, but I have no idea what I can use it for.
What can leatherworkers use Iron Ore for?
Answer: Short answer: As it seems for me only for the Runes of the Engineer.
These are the recipes I found who uses Iron Ore:

Minor Rune of the Engineer
Major Rune of the Engineer
Superior Rune of the Engineer

I haven't found othere recipes for it, but maybe another user may know more than me.

EDIT: Well, just look on the Iron Ore wiki page and look for Recipes -> Leatherworker. Seems as my mentioned runes are the only recipes that need Iron Ore.


Is there any difference between dual boot Ubuntu and and windows system and a Stand alone Ubuntu system?

Question: I have a dual boot windows 7 and Ubuntu 13.04 system(not wubi)and I wanted to know is there any difference when we install Ubuntu by erasing whole hard disk(Stand alone) and when we dual boot it by giving it available free space.
Answer: The short answer:
Dual booting works very well, but if it was me I would go stand alone.
If you need the ability to run Windows software natively, then dual boot is the way to go; otherwise stick with stand alone.
As far as performance, there would be no difference between dual booting and stand alone, unless you use WUBI to install Ubuntu, then there will be a performance issue.  Now, my personal opinion, generally speaking Ubuntu will perform better on the same machine than Windows.
Comment: thanks for reply but I want know that is there any performance difference between the two or they are same.
Comment: Well, you didn't specify that in your question.
Comment: Sorry.I unaccepted it by-mistake..
Comment: I have added a bit about performance.
Comment: Glad to help. You're welcome :)


What can be that pure white grease used within a coffee mill?

Question: Earlier today I decided it was time to disassemble my Kalita Nice Cut coffee mill and clean it a bit.
I initially removed the 2 huge screws to take out the front part where the burrs are located (that actually mill the beans) and cleaned that.
Then I wondered what is that part between the motor (rear) and the burrs. Does that need some adjustment or cleaning? So I unscrewed that middle block which was made of 2 parts, having gears on each side.
I was amazed at how clean this was, after years and years of utilization. Anyway, there was pure white grease everywhere.
What can be that pure white grease, which is usually found in kitchen appliances? Can it be handled safely? (I think the gears where made of ceramic(?)).
[unfortunately I didn't think of taking pictures at the time]
Comment: Grease used in a device for food products is probably food safe type, instead of the regular wheel bearing white grease.  Besides not tasting that good it should be safe.  Would check the seals between the gear housing and the burr section.  Mixing of coffee and grease in the gears might not be good for long life of the mill, coffee might taste different also.
Comment: I'm voting to close this question because questions about small appliances are off topic.
Comment: Assuming it's a matter of taking some screws out, for the sake of helping us answer this question, adding some photos would really help :)
Comment: Can't think a picture of white greasy gears is going to help identify the specific white grease, really, @MiG
Comment: I had to replace a gear in a Kitchen Aid mixer years ago.  The existing gear set had grease on it, and the new gear came with a tube of grease.  I sure that grease has to be food safe.  I don't think you have anything to worry about.
Comment: @Ecnerwal Can see colour, consistency, viscosity (based on how it has spread inside) etc from that. It would at least narrow it down a bit.
Comment: @MIG Actually the gear part was not so easy to re-assemble, + holding and contaminating these greasy things also...
Comment: @crip659 The gear section was amazingly clean. There is a shaft between the gears and burrs that seems to be well insulated.
Answer: Food-Safe grease is a common product. Exactly which one you have you'd have to ask the makers of your mill. However, since the area appears from your description to be well-sealed against contamination from the outside, you can probably just leave it alone, unless the owner's manual specifies a regreasing interval.
Two examples, there are many others, just ask your search engine of choice food safe grease (no endorsement implied)
Answer: Many types of grease exist, so it will be hard to be sure.
However, early white greases were lithium based, what a white grease may contain now may be different.
Comment: Usually think white grease used/know  for wheel bearing grease.


GraphQL and Mongoose overwrite property to null with not passed argument in mutation

Question: I've tried to simplify example as possible so if any additional information needed I could provide it. Let's say we have easy Schema with embed GraphQLObjectType:
const nameType = new GraphQLObjectType({
  name: 'NameType',
  fields: {
    first: new GraphQLNonNull(GraphQLString),
    last: GraphQLString,
  },
});

const userType = new GraphQLObjectType({
  name: 'User',
  fields: () => ({
    id: new GraphQLNonNull(GraphQLID),
    name: new GraphQLNonNull(nameType),
    email: new GraphQLNonNull(GraphQLString),
  }),
});

So I have name with properties first and last here. For updating I've written mutation as below. There is GraphQLInputObjectType represent as NameType.
const nameType = new GraphQLInputObjectType({
  name: 'NameInput',
  fields: {
    first: new GraphQLNonNull(GraphQLString),
    last: GraphQLString,
  },
});

const updateUser = {
  name: 'UpdateUser',
  type: userType,
  args: {
    id: new GraphQLNonNull(GraphQLID),
    name: nameType,
    email: GraphQLString,
  },
  resolve: (_, args, context) => User.findOneAndUpdate({ _id: args.id }, args, { new: true })
};

So when I'm passing any mutation with name: {first: "Foo"} property last always get overrides with null value. I'm forced to pass previous first name and new last name if I need to change last name. I would like to have a possibility to update only one first or last without affect another. How I can reach it out?
Comment: I know that the reason in JavaScript. It doesn't support deep clone or deep merge, so i'm still seeking the solution.
Answer: That's because Mongoose update property modify nested objects as a whole. So if we need to deep merge within update operation, we need something as here.
If we need to cover more nested layers we can use this code in while loop.


How to make ViewPager scroll and making header image as a collapsing toolbar?

Question: I have a recipe fragment that has a header image and a ViewPager, and I'm facing two problems with the current design:
1- The tabs content are not scrolling vertically unless I press on the header image and start scrolling. What I mean by this is that if I swipe vertically on the header image the view will scroll. BUT if I try to swipe vertically from the text area it doesn't scroll. (I have an image below)
2- The header image is not all the way up to replace the toolbar like the current version Google Play Store displays apps like the the first screenshot below, and the second screenshot is how my app looks like.

Here is my my fragment_recipe.xml:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/tab_app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:layout_scrollFlags="scroll|exitUntilCollapsed">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/tab_collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_marginTop="25dp"
        android:layout_height="256dp"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/recipe_header"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/header"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            />

        <android.widget.Toolbar
            android:id="@+id/tab_toolbar"
            android:layout_width="match_parent"
            android:layout_height="104dp"
            android:gravity="top"
            android:minHeight="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:titleMarginTop="13dp" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:textStyle="bold"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="bottom"
            app:layout_scrollFlags="scroll|enterAlways"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:tabIndicatorColor="@android:color/white" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:tabMode="scrollable"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

And here is my FargmentRecipe.java:
import android.annotation.TargetApi;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import java.util.ArrayList;
import java.util.List;
import mamoonbraiga.MealMate.activities.MainActivity;
import mamoonbraiga.MealMate.extras.Recipe;
import mamoonbraiga.MealMate.network.VolleySingleton;
import mamoonbraiga.poodle_v3.R;

public class FragmentRecipe extends Fragment{

private ImageView header;
private VolleySingleton volleySingleton = VolleySingleton.getsInstance();;
private ImageLoader imageLoader=volleySingleton.getImageLoader();;
private Bundle bundle;

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){

    final View view = inflater.inflate(R.layout.fragment_recipe, container, false);
    MainActivity mainActivity = (MainActivity) getActivity();
    header = (ImageView) view.findViewById(R.id.recipe_header);  //setting up the header
    bundle = mainActivity.getSavedData();
    Recipe recipe = bundle.getParcelable("recipe");

    //load the header
    loadHeader(recipe);
    ((MainActivity) getActivity()).getSupportActionBar().hide();
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.tab_toolbar);
    mainActivity.setActionBar(toolbar);
    mainActivity.getActionBar().setDisplayHomeAsUpEnabled(true);

    /** view pager and tab setup **/
    final ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewpager);
    viewPager.setVerticalScrollBarEnabled(true);
    setUpViewPager(viewPager);
    final TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FF5722"));
    tabLayout.setupWithViewPager(viewPager);
    /** view pager and tab setup **/

    return view;
}

private void loadHeader(Recipe recipe) {
    imageLoader.get(recipe.getImageUrl(), new ImageLoader.ImageListener() {
        @Override
        public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
            Drawable d = new BitmapDrawable(getResources(), response.getBitmap());
            header.setBackground(d);
        }

        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });
}

private void showToast(String msg) {

    Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
}

private void setUpViewPager(ViewPager viewPager) {

    ViewPagerAdapter adapter = new ViewPagerAdapter(getActivity().getSupportFragmentManager());
    adapter.addFrag(new FragmentDescription(), "Description");
    adapter.addFrag(new FragmentIngredients(), "Ingredients");
    adapter.addFrag(new FragmentNutrition(), "Nutrition");
    viewPager.setAdapter(adapter);

}

static class ViewPagerAdapter extends FragmentStatePagerAdapter{

    private final List<String> mFragmentTitleList = new ArrayList<>();
    private final List<Fragment> mFragmentList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFrag(Fragment fragment, String title){
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }
    @Override
    public CharSequence getPageTitle(int position){
        return mFragmentTitleList.get(position);
    }

}
@Override
public void onPause(){
    super.onPause();
    ((MainActivity) getActivity()).getSupportActionBar().show();
}

}

Answer: 1) I don't have your fragments layouts xml (FragmentDescription, FragmentIngredients and FragmentNutrition layouts) but I am guessing your are using ScrollView instead of NestedScrollView. Try this at the root of your nested fragments:<android.support.v4.widget.NestedScrollView>
2) When your header collapse, do you still have the black status bar? If so, you have to add transparency to your status bar.So in your theme: <item name="android:statusBarColor">#80000000</item>
(here I am using a dark transparent color, to make it look nicer, but it's up to you)
Note also that you cannot get full transparent status bar on pre-Lollipop devices.
2bis) if you already have a transparent statusbar (you see the image passing behind after a bit of scrolling up), then you can try this hack:
    <ImageView
        android:id="@+id/recipe_header"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/header"
        android:layout_marginTop="-24dp"
        android:fitsSystemWindows="true"
        android:scaleType="centerCrop"
        app:layout_collapseMode="parallax"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        />

This will move the image up by the height of the status bar, thus making it fit with the top of the window. There is probably a proper solution, but it is the one I am using at the moment.


Is it okay to glue mirror cabinet to tiles ? (IKEA LILLÅNGEN)

Question: I want to buy something like this LILLÅNGEN Mirror cabinet with 1 door:

The problem is that I don't have permissions of owner to drill through tiles. Can you advise me, is safe to glue this kind of cabinet to tiles or not? And if is safe, which glue would you use?
Comment: Yeah, usually these things need two screws at the top, which you can put through the gap between two tiles. As to glueing: I wouldn't do that, because either the glue isn't strong enough and the cabinet will come crashing down, or it is so stron you wont be able to remove the cabinet later. At least this is what would happen to me.
Comment: can you drill through the mortar between the tiles?
Comment: As i commented below to @mikes, If there is no problem if tile is damaged when cabinet is removed which glue would you use?
Comment: you can use hot glue, which is removable with a steam cleaner. use a lot of it, and rough up the back of the cabinet first. I also wouldn't keep anything irreplaceable in it, but it should work fine.
Answer: In a word no. First issue is you are renting. The owner has specified no holes in the tile. There is no guarantee the adhesive, if it held won't damage the tile when the cabinet is removed. I would suggest getting some sort of a base cabinet, perhaps a bookcase size piece and mount the mirror cabinet to the top .
Comment: edit: ... in other word owner agrees to any kind of glue just no drilling. Sounds stupid and it is, but here we are. :)
Comment: Thanks for reply and tips! Its a little bit more complex then renting but that is another story. If there is no problem if tile is damaged when cabinet is removed which glue would you use?
Answer: I would get some foam tape labelled "permanent" and use that. The stuff holds impressively well, and it'll do the job if installed properly. I've seen hundreds of towel and soap dispensers in commercial buildings installed this way for years.
When you're done with the cabinet you'll be able to slide a metal blade behind the cabinet and slice the foam, then scrape away the residue (maybe with the help of an adhesive solvent).

Clean the tile and cabinet back with alcohol.
Apply 2" strips of foam tape to every tile (or major portion thereof) that falls behind the cabinet. Orient them vertically. Don't put tape within about an inch of the cabinet sides (where it might be visible), and don't put tape over the grout joints (where it'll be difficult to remove). Keep it on the flat portion of the tile.
Mark a plumb line where one side of the cabinet will be located. This could be done on masking tape so you can strike a complete line. I say a plumb line rather than a level line because that side of the cabinet is longer, so you'll have greater accuracy.
With a helper, position the cabinet over the tape and aligned with the plumb line. Do not make contact with the tape yet.
Slowly ease the side of the cabinet near the mark back to the tile. Make any final position adjustments, then swing the entire cabinet back, making contact with the tape.
Firmly press the cabinet back into each piece of tape to ensure a good bond.
Wait a few minutes for the adhesive to grab well, then test the bond by tugging on the cabinet.

The most likely failure point will be the cabinet back. If the paint is particularly slippery (like a vinyl coating), or if it's not clean, you may see the tape not holding. It may be wise to test this beforehand. I have no such concerns with the tile.
Be sensible about what you load the cabinet with. 30 pounds of lotions and warm day could prove troublesome.
Occasionally test the bond with a tug.
Answer: Instead of drilling through the tiles to hang the cabinet, you could also drill through the grout lines only. Obviously, you will need a small enough drill and screws to not damage the tiles, and depending on how the cabinet mounts, it may not allow you to place screws in the right location. But the grout would be easier to repair than tile (though it might be tough to get a perfect color match).


what is a good way to get test data to a mock repo

Question: I have a database (SQL Server, Entity Framework) with 10-12 tables, around 5000 records. I want to code a unit test for a complex report that uses the data from those tables. What would be a good way to do that? I really do not want unit tests hitting an actual database...
Comment: Where do you generate report - in business service or in repository (i.e. its just generation of complex SQL query)?
Comment: the report is generated in a component in the business layer
Comment: Well, then I think you can mock repositories, provide some test data for different reporting scenarios and verify generated data
Comment: My question was towards how to automate getting the test data from a database to a mock repository.
Answer: Late to answer but its worth pointing out the NuGet package Effort allows you to fake an entire DbContext in memory from either a code-first or a database-first model.
I use it frequently & like it's ease of set up. You can use it to test issues that one could miss if trying to unit test with concrete fakes such as List<Entity>. (Issues caused by trying to load nav properties after the context is disposed for example)
A downside is that it does slow down the unit test a little1 which may be a concern for TDD or with a huge number of tests but I have always found it perfectly acceptable.
Simple use case outline for a db first set up would be as follows:

Add the nuget package for your EF version (package id: Effort.EF6 perhaps?)
Add an override to the constructor of your "MyEntities" class to enable Effort to pass in it's own connection string:

public partial class MyEntities
{
    public MyEntities(DbConnection connection) : base(connection, true)
    {
    }
}

You can now create a 'Persistent' db store (persistent means it stays available after the context is disposed - it's not saved anywhere after the test run finishes!) with the following code:

var context = new MyEntities(Effort.EntityConnectionFactory.CreatePersistent("name=MyEntities"))

Just make sure you have the connection string to the db available in your app.config for the test project (used only to create the model)

Set up whatever mock data you need to test the context (I often have some simple data loaded using [ClassInitialize] or [TestInitialize] methods but it's easy to do whatever makes sense for your own set up):

[ClassInitialize]
public static void Initialise()
{
    using (var context = new MyEntities(Effort.EntityConnectionFactory.CreatePersistent("name=MyEntities")))
    {
        context.Employees.Add(new Employee { Name = "John Doe", Skills = null});
        context.Skills.Add(new Skill { Type = "C# Coding"});

        context.SaveChanges();
    }
}

Run your unit test using the in memory context:

[TestMethod]
public async Task CsSkillCanBeAssociatedWithEmployee()
{
    //Arrange
    using (var context = new MyEntities(Effort.EntityConnectionFactory.CreatePersistent("name=MyEntities")))
    using (var sut = new SkillsMatrixService(context))
    {

    //Act
        await sut.AddSkillToEmployeeAsync("Joe Bloggs","C# Coding");
    }

    //Assert
    using (var context = new MyEntities(Effort.EntityConnectionFactory.CreatePersistent("name=MyEntities")))
    {
        var joesCSharpSkills = context
            .Employees
            .First(e => e.Name == "Joe Bloggs")
            .Skills
            .Where(s => s.Type == "C# Coding");

        Assert.IsTrue(joesCSharpSkills.Any());
    }
}

I'm given to understand you can load the initial set up for your db from csv config files to live in your project but I've always just set up dummy data in code as above.
1. Anecdotally, in my own (fairly limited) experience, 1 second or so is about usual to set it up and load some dummy data for a smallish model with around 20 entities and lots of nav properties - my machine isn't ultra fast. Naturally, your mileage may vary according to the complexity of your model and your hardware setup


$k$-th moment of product of gaussian and sinc

Question: I would like to calculate the following integrals:

$$\int_{-\infty}^{+\infty} \quad x^k\quad \left(\frac{\sin(\pi a x)}{\pi ax}\right)^2\quad \exp(-bx^2)\,dx$$
$$\int_{-\infty}^{+\infty} \quad x^k\quad \left(\frac{\sin(\pi a x\pm\pi)}{\pi ax\pm\pi}\right)^2\quad \exp(-bx^2) \,dx$$

Thanks!
Comment: For the first one (with $k\ge2$), it suffices to calculate  the gaussian integral $\displaystyle\int_{-\infty}^{\infty}\exp\left(-bx^2+\alpha x\right)dx$ and differentiate with repect to $\alpha$. For the second, you should in addition to that first make the change of variables $y=x\pm 1/a$.
Comment: Can you please show me the steps on how to get this solution? thanks.
Comment: ok, I will just wait some time in case if somebody comes with a more clever method.
Answer: First one:

The only non-zero moments correspond to even $k=2m$. In this case we have
$$I_k=\int_{-\infty}^{\infty}x^k\left(\frac{\sin(\pi a x)}{\pi ax}\right)^2\quad \exp(-bx^2)\,dx=\frac{(-1)^{m-1}}{\pi^2a^2}\frac{\partial^{m-1}}{\partial b^{m-1}}\int_{-\infty}^{\infty}\sin^2\pi a x\, e^{-bx^2}dx$$
But the last integral can be written as
\begin{align}
\int_{-\infty}^{\infty}\sin^2\pi a x\, e^{-bx^2}dx=\frac14\int_{-\infty}^{\infty}\left(2-e^{2\pi i a x}-e^{-2\pi i a x}\right)e^{-bx^2}dx=\\
=\frac12\sqrt{\frac{\pi}{b}}\left(1-e^{-\pi^2a^2/b}\right),
\end{align}
where at the last step we have used the gaussian integral $\displaystyle \int_{-\infty}^{\infty}e^{-\beta x^2+2\alpha x}dx=\sqrt{\frac{\pi}{\beta}}\,e^{\alpha^2/\beta}$.

Therefore one finds
$$I_{2m}=\frac{(-1)^{m-1}}{2\pi^2a^2}\frac{\partial^{m-1}}{\partial b^{m-1}}\left[\sqrt{\frac{\pi}{b}}\left(1-e^{-\pi^2a^2/b}\right)\right].$$
Concerning the integrals of the 2nd type, consider the change of variables $y=x\pm a^{-1}$ and try adapt the above, it's not difficult.
Comment: It turns out to be the same in the 2nd case. Is that correct?
Comment: I don't think so, as the exponential in the integrand in the 2nd case contains not only quadratic, but also a linear term.
Comment: Why not? Check [this](http://www.wolframalpha.com/input/?i=int+exp%28-b*%28x-1%2Fa%29%5E2%29*exp%28-2*pi*i*x*a%29)
Comment: Do you agree that are the same?
Comment: Who are the same and in which sense? For example, the values of $0$th moment are different in the 1st and 2nd case with the same $a$ and $b$. On the other hand the recursion formulas for the moments are obtained in a very similar way.
Comment: I have found that the values of $k$-th moments ($k>0$) are equal in the 1st and 2nd case (check the link out in my previous comment). But I have problems to derive the values of $0$-th moment in the 2nd case. Could you help me please? The substitution $y=x\pm a^{-1}$ does not seem to help.
Comment: I've checked the link, but I don't understand the conclusion you made out of it. My statement is, once again: if we fix k, a and b, then numerical values of integrals 1) and 2) are different. As I have not tried to derive analytical expression in the 2nd case, I cannot tell what exactly makes that difference. The recursion relation is derived in the same way as before, but the calculation of $0$th moment is probably more difficult, I have to think about this.
Comment: OK. Now I understand your point about different values while evaluating the first and the second integrals. I was making a mistake in the substitution and now I don't know how to calculate the second case at all (in the zero or positive order!) :( Please help me.
Comment: Can you please help me with the second case?
Comment: I could *try*. But, since I don't immediately see how the $0$th moment can be computed in the 2nd case, this may be difficult and even impossible. Unaccepting the previous answer will not motivate me to try anything, however.
Answer:
$$\int_{-\infty}^{+\infty} \quad x^k\quad \left(\frac{\sin(\pi a x)}{\pi ax}\right)^2\quad \exp(-bx^2)\,dx$$

can be solved using known integrals involving bessel function of the first kind.
Since
$$\left(\frac{\sin(\pi a x)}{\pi ax}\right)^2=\frac{1}{2ax}J_{\frac{1}{2}}(\pi ax)J_{\frac{1}{2}}(\pi ax)$$

can be written as

$$\int_{-\infty}^{+\infty} \quad\frac{1}{2a} x^{k-1}\,J_{\frac{1}{2}}(\pi ax)J_{\frac{1}{2}}(\pi ax)\, \exp(-bx^2)\,dx$$
That is a known integral from Volume II of "Higher Transcendental Functions". It holds for $k\geq 0, \,a>0,\,b>0$.


how to switch focus between different layouts

Question: I have three layouts one for showing main menu, second for sub menu, and third for details menu. I have to navigate between these layouts using keyboard arrow buttons. Moving down for main menu to sub menu and from sub menu to details menu works,
but the problem is when I'm in details menu I cannot go up  sub menu. I tried using the property android:nextFocusUp but it didn't work for me.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#1c1c1c"
            android:layout_marginLeft="100dp"
            android:layout_marginRight="100dp"
            >

            <LinearLayout
            android:id="@+id/pagelogolayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:background="@drawable/logoborder">

        <ImageView
            android:id="@+id/logoimage"
            android:layout_width="170dp"
            android:layout_height="90dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/listpagelogo"
            android:layout_marginLeft="10dp"
            android:layout_marginBottom="15dp"
            />

    </LinearLayout>

    <RelativeLayout
        android:id="@+id/mainmenu"
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:layout_below="@+id/pagelogolayout"
        android:orientation="horizontal"
        android:background="@drawable/main_menu_border"
        android:nextFocusDown="@+id/submenu"
        android:focusable="true">
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/submenu"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_below="@+id/mainmenu"
        android:orientation="horizontal"
        android:background="@drawable/sub_menu_border"
        android:nextFocusDown="@+id/container" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_below="@+id/submenu"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="30dp"
        android:nextFocusUp="@+id/submenu"
        />

        </RelativeLayout>
</RelativeLayout>

Answer: view.requestFocus();

note: your layout has too many nested layout, it will make app's performance is down


Installing a floating stone wall around the TV

Question: I just wanted to add some stone veneer tiles around the TV.
The tv is 55" (32x5" x 57")
The frame behind the TV would extend 16" on each side.
By frame, I mean stone tiles. These are the tiles
I can create a 2x4 frame and install cement board on it which will hold the stone tiles.
My dilemma is that I do not want to extend the stone tiles all the way to the floor. Can I attach some 2x4 on the wall horizontally (screwed into the studs behind the drywall ) install cement board on it and then add tiles?
OR
Build a proper frame that sits on the floor, screwed to the drywall with cement board and stone tile? With this approach I can install a piece of drywall in the bottom to hide the bottom part of the frame.
By frame, I mean stone tiles. s on the floor, screwed to the drywall with cement board and stone tile? With this approach, I can install a piece of drywall in the bottom to hide the bottom part of the frame.
In both cases, stone tiles will only be attached to the cement board and won't be sitting on the floor. What kind of issues I can run into with this approach?
Comment: It's not clear what you are concerned about.  What assumptions are you making that you think are restricting you from doing what you want?  You can build a stone facade around the TV.    You maybe are suggesting that the stone veneer should be *supported* by the floor?  Is that your assumption?  (It's wrong).  Otherwise it's not clear what you mean by "Can I ...." because why do you think you maybe cannot?
Comment: @jay613 Hi, yes, that's exactly is my concern. That tiles may get heavy and need to be supported by the floor. So do you think I should put some horizontal 2x4 or just put cement board over the drywall and screw in to the studs? Thanks
Comment: You want to build a miniature wall with a top plate, bottom plate, and window cut into it. Screw the horizontal pieces into the stud framing in the wall behind your pop-out. To accomplish that, use a spade bit to cut a 2" deep hole in the edge of the 2x4s so that you can install a few deck ledger screws ithrough to the back wall's studs.
Answer: Wall tiles are not supported by the floor or by the tile beneath.  They are glued to the wall with tile adhesive, and gaps in between that are later filled with grout.  The adhesive does all the work.
You do not need to build a wood frame to support your tiles.  If your tiles do not extend all the way to the floor, ceiling, or adjacent walls, you will have to create an edge for them, but how you do that is entirely a matter of appearance.  If you are framing a TV you might want your tiles to be quite deep.  Maybe then you'll build a 2x4 frame all around the TV, place drywall over that, and tile over that so it will be a couple of inches proud of the surrounding wall.   Or maybe you think that's a terrible idea.  It's up to you.  Some tiles have available custom edge strips and corners.  You can buy generic contrasting edge and corner tiles to go with anything. They can also be made of metal, resin, wood, etc.  For the stone veneer you chose around a (black) TV you might choose a black acrylic edging strip.  Or you might thing that's ugly .. I'm not a decorator.
Whether you glue the tiles directly to existing drywall, or cover the drywall with cement board, or replace the drywall with cement board, depends on the environment, the tile, the adhesive and more.  If the room is not humid and does not fluctuate too much in temperature or humidity and if the drywall was put up properly with a view to tiling ... you can just tile over it.
Answer: The frame does not have to go to the floor.  It just has to be constructed strong in the first place.  I have almost the same situation with really heavy unpolished marble tiles.  The support frame cantilevers over the fireplace with glass walls.  It has been 6 years and it hasnt dropped.
Comment: Yes. This is what I'm trying to achieve without the fireplace. I will add tv console later but that won't adding any support to the frame. How did you build the frame for your tv wall? Thanks.


Why are there gaps on the garage door seal of my garage door?

Question: I'm looking into thermally insulating the bottom of my Garage door (I live on Long Island NY, so the winters can get a bit cold), and I noticed that there are gaps in the sides of the garage door bottom.
What are these intentional gaps in the bottom of the rubber on the garage door?
Are they there intentionally?
Do they pose a problem for keeping the garage warm during the winter since air can go through them?
How would I get rid of them?
You can see it in the pictures that I shot:
Answer: Looks like you need a new garage door seal that's the actual length of your garage door width, not several inches shorter.
I know my "nominal" 10 foot wide door is "actually" 10 feet 2 inches wide, for instance. But if I forgot that and got a "10 foot" seal it might come up short like that.
Answer: Rubber (and synthetic rubber) is stretchy and it's hard to install without stretching it.
If you stretch it when you install it it will shrink and after a year or so you
get a result like that.
Comment: Having recently installed a new garage door seal, it definitely stretched as I pulled it into the groove, but it _immediately_ snapped back to it's original size, there was no slow return. I find it hard to believe that the seal would have been stretched to fit on original install and have shrunk back over a year or so.


Simple Calculus Problem

Question: The temperature on the coldest winter day in $2009$ is determined by $\frac{t}{20} * (t-12) * (t-24)$. If $t$ is measured in hours and $t=0$ is at midnight, which of the following is the average temperature between $7$am to $3$pm.
How is the answer not integral of $[\frac{t}{20} * (t-12) * (t-24)]$ from $7$ to $15$ which is about $50.8$?
The answer was like $6.35$? How??
Comment: Suppose this was a discrete question and you had the temperature $t_i$ at $N$ distinct time intervals, then the average would be:
$\frac{\sum_i t_i}{N}$. An integral is really just a sum in the discrete case, so what are you missing?
Comment: gotta divide by 8 thank you
Comment: It is not about $50.8$; it is exactly $50.8$. It is not like $6.35$; it is exactly $6.35$.
Answer: You're being asked for the average, so divide it by the number of hours... You essentially are right at the finish line with your answer.
http://tutorial.math.lamar.edu/Classes/CalcI/AvgFcnValue.aspx (for some extra reading)
Comment: O SHOOT I NEED TO DIVIDE BY 15-7=8. thank you

Simple Calculus Problem


How to build an object with a loop in CoffeeScript

Question: Currently I have:
  newObject = {}
  for item in myArray
     newObject[item.id] = item.data
  newObject

As you can see i have an array of objects and I want to end up with an object which is keyed by one of the fields on the objects in the array with the values being the items in the array. i.e turn an array into a dict/keyed hash.
The above works but doesn't look very CoffeeScript to me. how do I do this in a nice CoffeeScript way?
Answer: On top of comprehension (second code snippet in Daniel Cioata answer), you can add destructuring assignment:
newObject = { }
newObject[id] = data for { id, data } in myArray
newObject

Answer: I would recommend to use each function from underscore library: http://underscorejs.org/#each
The above code would look like this:
newObject = {}
_.each myArray,(elem)->newObject[elem.id]=elem.data
newObject

The advantage is that underscore has other useful functionalities which can be used.
A simpler approach (without using underscore library), would be:
 newObject = {}
 newObject[elem.id]=elem.data for elem in myArray
 newObject


What are good examples of problems that graphs can solve better than the alternative?

Question: After reading Stevey Yegge's Get That Job At Google article, I found this little quote interesting:

Whenever someone gives you a problem, think graphs. They are the most fundamental and flexible way of representing any kind of a relationship, so it's about a 50–50 shot that any interesting design problem has a graph involved in it. Make absolutely sure you can't think of a way to solve it using graphs before moving on to other solution types. This tip is important!

What are some examples of problems that are best represented and/or solved by graph data structures/algorithms?
One example I can think of: navigation units (ala Garmin, TomTom), that supply road directions from your current location to another, utilize graphs and advanced pathing algorithms.
What are some others?
Comment: By the way, don't buy those myths about Google interviews. Compared to other places, they sometimes ask super simple and straightforward questions, which can actually throw you off.
Answer: Computer Networks: Graphs model intuitively model computer networks and the Internet. Often nodes will represent end-systems or routers, while edges represent connections between these systems.
Data Structures: Any data structure that makes use of pointers to link data together is making use of a graph of some kind. This includes tree structures and linked lists which are used all the time.
Pathing and Maps: Trying to find shortest or longest paths from some location to a destination makes use of graphs. This can include pathing like you see in an application like Google maps, or calculating paths for AI characters to take in a video game, and many other similar problems.
Constraint Satisfaction: A common problem in AI is to find some goal that satisfies a list of constraints. For example, for a University to set it's course schedules, it needs to make sure that certain courses don't conflict, that a professor isn't teaching two courses at the same time, that the lectures occur during certain timeslots, and so on. Constraint satisfaction problems like this are often modeled and solved using graphs.
Molecules: Graphs can be used to model atoms and molecules for studying their interaction and structure among other things.
Comment: +1 for Constraint Satisfaction.
Comment: The part on constraint satisfaction sounds interesting. Do you have any articles or papers on this topic to share?
Comment: @MahlerFive, I'd love to learn more about constraint satisfaction that as well. Could you please point to the resources worth looking into?
Answer: I am very very interested in graph theory and ive used it solved so many different kinds of problem. You can solve a lot of Path related problem, matching problem, structure problems using graph.

Path problems have a lot of applications.
This was in a career cup's interview question.
Say you want to find the longest sum of a sub array. For example, <code>[1, 2, 3, -1]</code> has the longest sum of 6. Model it as a Directed Acyclic Graph (DAG), add a dummy source, dummy destination. Connect each node with an edge which has a weight corresponding to the number. Now use the Longest Path algorithm in the DAG to solve this problem.
Similarly, Arbitrage problems in financial world or even geometry problems of finding the longest overlapping structure is a similar path problem.
Some obvious ones would be the network problems (where your network could have computers people, organisation charts, etc).
You can glean a lot of structural information like

which point breaks the graph into two pieces
what is the best way to connect them
what is the best way to reach one place to another
is there a way to reach one place from another, etc.

I've solved a lot of project management related problems using graphs. A sequence of events can be pictured as a directed graph (if you don't have cycles then thats even better). So, now you can

sort the events according to their priority
you can find the event that is the most crucial (that is would free a lot of other projects)
you can find the duration needed to solve the total project (path problem), etc.

A lot of matching problems can be solved by graph. For example, if you need to match processors to the work load or match workers to their jobs. In my final exam, I had to match people to tables in restaurants. It follows the same principle (bipartite matching -> network flow algorithms). Its simple yet powerful.
A special graph, a tree, has numerous applications in the computer science world. For example, in the syntax of a programming language, or in a database indexing structure.
Most recently, I also used graphs in compiler optimization problems. I am using Morgan's Book, which is teaching me fascinating techniques.

The list really goes on and on and on. Graphs are a beautiful math abstraction for relation. You really can do wonders, if you can model it correctly. And since the graph theory has found so many applications, there are many active researches in the field. And because of numerous researches, we are seeing even more applications which is fuelling back researches.
If you want to get started on graph theory, get a good beginner discrete math book (Rosen comes to my mind), and you can buy books from authors like Fould or Even. CLRS also has good graph algorithms.
Answer: Your source code is tree structured, and a tree is a type of graph. Whenever you hear people talking about an AST (Abstract Syntax Tree), they're talking about a kind of graph.
Pointers form graph structures. Anything that walks pointers is doing some kind of graph manipulation.
The web is a huge directed graph. Google's key insight, that led them to dominate in search, is that the graph structure of the web is of comparable or greater importance than the textual content of the pages.
State machines are graphs. State machines are used in network protocols, regular expressions, games, and all kinds of other fields.
It's rather hard to think of anything you do that does not involve some sort of graph structure.
Answer: An example most people are familiar: build systems. Make is the typical example, but almost any good build system relies on a Directed Acyclic Graph. The basic idea is that the direction models the dependency between a source and a target, and you should "walk" the graph in a certain order to build things correctly -> this is an example of topological sort.
Another example is source control system: again based on a DAG. It is used for merging, for example, to find common parent.
Answer: Well, many program optimization algorithms that compilers use are based on graphs (e.g., figure out call graph, flow control, lots of static analysis).
Many optimization problems are based on graph. Since many problems are reducable to graph colouring and similar problems, then many other problems are also graph based.
I'm not sure I agree that graphs are the best way to represent every relation and I certainly try to avoid these "got a nail, let's find a hammer" approaches. Graphs often have poor memory representations and many algorithms are actually more efficient (in practice) when implemented with matrices, bitsets, and other things.
Answer: OCR. Picture a page of text scanned at an angle, with some noise in the image, where you must find the space between lines of text. One way is to make a graph of pixels, and find the shortest path from one side of the page to the other, where the difference in brightness is the distance between pixels.
This example is from the Algorithm Design Manual, which has lots of other real world examples of graph problems.
Answer: The following are based on graph theory:

Binary trees and other trees such as Red-black trees, splay trees, etc.
Linked lists
Anything that's modelled as a state machine (GUIs, network stacks, CPUs, etc)
Decision trees (used in AI and other applications)
Complex class inheritance
Answer: One popular example is garbage collection.
The collector starts with a set of references, then traverses all the objects they reference, then all the objects referenced there and so on. Everything it finds is added into a graph of reachable objects. All other objects are unreachable and collected.
Answer: To find out if two molecules can fit together. When developing drugs one is often interested in seeing if the drug molecules can fit into larger molecules in the body. The problem with determining whether this is possible is that molecules are not static. Different parts of the molecule can rotate around their chemical bindings so that a molecule can change into quite a lot of different shapes.
Each shape can be said to represent a point in a space consisting of shapes. Solving this problem involves finding a path through this space. You can do that by creating a roadmap through space, which is essentially a graph consisting of legal shapes and saying which shape a shape can turn into. By using a A* graph search algorithm through this roadmap you can find a solution.
Okay that was a lot of babble that perhaps wasn't very understandable or clear. But my point was that graphs pop up in all kinds of problems.
Answer: Graphs are not data structures. They are mathematical representation of relations. Yes, you can think and theoretize about problems using graphs, and there is a large body of theory about it. But when you need to implement an algorithm, you are choosing data structures to best represent the problem, not graphs. There are many data structures that represent general graphs, and even more for special kinds of graphs.
In your question, you mix these two things. The same theoretical solution may be in terms of graph, but practical solutions may use different data structures to represent the graph.
Answer: Graphs are great for managing dependencies.
I recently started to use the Castle Windsor Container, after inspecting the Kernel I found a GraphNodes property.  Castle Windsor uses a graph to represent the dependencies between objects so that injection will work correctly. Check  out this article.
I have also used simple graph theory to develop a plugin framework, each graph node represent a plugin, once the dependencies have been defined I can traverse the graph to create a plugin load order.
I am planning on changing the algorithm to implement Dijkstra's algorithm so that each plugin is weighted with a specific version, thus a simple change will only load the latest version of the plugin.
I with I had discovered this sooner. I like that quote "Whenever someone gives you a problem, think graphs." I definitely think that's true.
Answer: IMHO most of the domain models we use in normal applications are in some respect graphs. Already if you look at the UML diagrams you would notice that with a directed, labeled graph you could easily translate them directly into a persistence model. There are some examples of that over at Neo4j
Cheers
/peter
Answer: Social connections between people make an interesting graph example. I've tried to model these connections at the database level using a traditional RDMS but found it way too hard. I ended up choosing a graph database and it was a great choice because it makes it easy to follow connections (edges) between people (nodes).
Answer: Profiling and/or Benchmarking algorithms and implementations in code.
Answer: You could take a look at some of the examples in the Neo4j wiki,

http://wiki.neo4j.org/content/Domain_Modeling_Gallery

and the projects that Neo4j is used in (the known ones)

http://wiki.neo4j.org/content/Neo4j_In_The_Wild .

Otherwise, Recommender Algorithms are a good use for Graphs, see for instance PageRank, and other stuff at

https://github.com/tinkerpop/gremlin/wiki/pagerank
Comment: This answer is a great example of why link only answers should not be well received on stack overflow. All of your links are broken now.
Answer: Anything that can be modelled as a foreign key in a relational database is essentially an edge and nodes in a graph.
Maybe that will help you think of examples, since most things are readily modelled in a RDBMS.
Answer: You can utilise graphs anywhere you can define the problem domain objects into nodes and the solution as the flow of control and/or data amongst the nodes.
Considering the fact that trees are indeed connected-acyclic graphs, there are even more areas you can use the graph theory.
Answer: Analysing transaction serialisability in database theory.
Answer: Basically nearlly all common data structures like trees, lists, queues, etc, can be thought as type of graph, some with different type of constraint.
To my experiences, I have used graph intensively in network flow problems, which is used in lots of areas like telecommunication network routing and  optimisation, workload assignment, matching, supply chain optimisation and public transport planning.
Another interesting area is social network modelling as previous answer mentioned.
There are far more, like integrated circuit optimisation, etc.


Using WCF REST with POST

Question: I have an WCF service which is working mostly with GET but one contract should work with POST.
I can't get it working - it returns "405 Method Not Allowed" all the time.
The service should recieve JSON and return a JSON.
I guess it something with the configuration. Here is my web.config file:

<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
  multipleSiteBindingsEnabled="true" />
<standardEndpoints>
  <webHttpEndpoint>
     <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json" />
  </webHttpEndpoint>
</standardEndpoints>

and the service itself

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "LoginUser", BodyStyle=WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat=WebMessageFormat.Json)]
    public int Login(string user, string password)

{
....
}

Any ideas? Help would be much appreciated!
Comment: Possible duplicate of http://stackoverflow.com/questions/911859/wcf-rest-post-xml-the-remote-server-returned-an-error-400-bad-request and http://stackoverflow.com/questions/41155/wcf-service-returning-method-not-allowed
Comment: sadly it's not a duplicate :)
Answer: Make sure that you're really making a POST. Because your code seems valid.
Try it by creating a new html-file containing something like:
<form action="http://{Address to your service}/Service.svc/LoginUser" method="POST">
    <input type="submit" value="Fire away!" />
</form>

Answer: Check out my comments for the duplicates but it boils down to making sure you have the correct verb supplied in your operation contract.  Here is an example:
[ServiceContract(Namespace = "http://www.test.com/youruri")]
public interface ISomeService
{
    [OperationContract]
    [WebInvoke(Method = "POST")]
    string SomeMethod();
}

Comment: It seems all is ok. changed the "BodyStyle" to Bare - and get a server error. So I guess it's not it :)
Comment: Okay, my example was a little muddied, forget about the RequestFormat stuff, just make sure the Method = "POST" is in there.
Comment: Yes. It's all there... That's the strange part. Maybe it's a web.config problem?
Comment: Thanks. I couldn't find anything useful for the problem. I think it's something with the WCF and the HTTP itself.
Comment: Yeah, I think you are right.  I dug around for about an hour or so and nothing really points out definitively what the problem is.  A colleague of mine at work just passed the WCF exam for MCSD so I'll ask him tomorrow if you still haven't found the answer then.  Good luck!

Using WCF REST with POST


I need to fix a recess light in my kitchen?

Question: I have recessed lighting in my entire house. It has vaulted ceilings and there is not attic access. One fixture keeps going through lamps and now just flickers on and off. Well, it did until my nephew removed the screw completely from the housing to see if he could take out the can.
What do I do now? We have taken off the trim and removed the baffle, but he dropped the screw that connected to a wing nut inside the can behind the light. I don't how to fix it or if I have to cut a hole in the ceiling to remove the housing? Please help!
Answer: Turn off the breaker to this circuit.
Near the bottom of the can light there are three screws. Remove them and the entire inner tin-can should pull down out of the ceiling. You can now rescue that screw and deal with whatever the problem is. This also provides you access to the junction box that is part of the lamp; where its connections are that you need to inspect.
A can light that seems to turn itself on and off either has too high of wattage bulb in it, causing the over-temp sensor to trip. Or the over temp switch has failed and needs to be replaced.
I am at a loss as to why one would burn out bulbs faster than others, unless it is somehow subject to more vibration. I'd check it against the others with a meter to make sure everything was kosher.
Comment: The lamp holder inside of the can might be defective which is causing the bulb to arc, blink, and eventually fail.


After installation of bumblebee: i386 OpenGL Apps stopped working

Question: I'm using Ubuntu 12.04 on my notebook (ASUS K53SV, i7-2670QM, Intel HD 3000, GeForce 540M).
In order to save energy i've installed "bumblebee", a solution for Nvidia Optimus Technology on Linux.
So far, so good.
Since then, the lifetime of my battery increased a lot.
But: If i try to open 32-Bit Apps like Wine and this Application uses OpenGL, it doesn't work. It just runs on my 540M, when I put "optirun" before the "wine" command.
But, for simple OpenGL Applications i don't need the power of my dedicated GPU.
I've used the offical bumblebee instalation guide, therefore i've installed, the Packages like "virtualgl-libs:i386, libgl1-mesa-glx:i386, libc6:i386" of course.
So, what can i do to get my OpenGL accerleration on 32-Bit Applications working again?
Thank you very much for your help!
- PhenomZ
BTW: My system sould by up to date. I'm always installing the recent updates.
(I'm also using the Xorg-Edgers PPA)
    phenom@notebook:~/Downloads/Test$ wine test.exe
err:module:load_builtin_dll failed to load .so lib for builtin L"OPENGL32.dll": libGL.so.1: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
err:module:import_dll Loading library OPENGL32.dll (which is needed by L"Z:\\home\\phenom\\Downloads\\Test\\test.exe") failed (error c000007a).
err:module:LdrInitializeThunk Main exe initialization for L"Z:\\home\\phenom\\Downloads\\Test\\test.exe" failed, status c0000135

Comment: Please attach the output of `update-alternatives --display i386-linux-gnu_gl_conf` to your question
Comment: Okay, here it is:

`i386-linux-gnu_gl_conf - manueller Modus

  Link verweist zur Zeit auf /usr/lib/nvidia-current/alt_ld.so.conf

/usr/lib/i386-linux-gnu/mesa/ld.so.conf - Priorität 500
  Slave i386-linux-gnu_xorg_extra_modules: /usr/lib/i386-linux-gnu/xorg/x11-extra-modules
/usr/lib/nvidia-current/alt_ld.so.conf - Priorität 9700
Gegenwärtig »beste« Version ist »/usr/lib/nvidia-current/alt_ld.so.conf«.`
Comment: Are you sure that you've installed libgl1-mesa-glx:i386? After doing so, try reinstalling Bumblebee.
Comment: Whoa, thank you very much!
After I reinstalled bumblebee... now it works perfectly.
Answer: I'll explain what happened. In Bumblebee version before 3.0-2~...ppa1, installing the bumblebee package also installs bumblebee-nvidia which on its turn installs nvidia-current.
The nvidia-current package installs both the 64-bit and 32-bit libraries on a 64-bit system. These OpenGL libraries conflict with the Mesa OpenGL library, package libgl1-mesa-glx. (read: breaks OpenGL capabilities on systems where the primary X server does not use the nvidia driver like an Optimus laptop)
The bumblebee-nvidia package tries to repair this by setting the default OpenGL library to the Mesa one for installed architectures. Initially, only libgl1-mesa-glx:amd64 is installed. So, unless libgl1-mesa-glx:i386 is installed before, OpenGL gets broken for 32-bit architectures.
The solution is to first install libgl1-mesa-glx:i386, and then install Bumblebee. virtualgl-libs:i386 can be installed at any time and will also be installed like bumblebee-nvidia in later versions. New installations will automatically pull in the drivers in the right order.
If you've already installed Bumblebee, simply install libgl1-mesa-glx:i386 and reinstall bumblebee-nvidia.


"Invalid OpenID transaction" when signing into Launchpad

Question: When I click on the "Log in / Register" link on the website https://launchpad.net, I always arrive on a blank page only displaying "Invalid OpenID transaction". This happens every time in Firefox, but never in Chromium nor in Epiphany.
Where does that come from and how do I fix it ?
Comment: Did you try to close your browser completely and then try again?
Comment: Yes : it happens always.
Answer: I had to accept cookies for the website, of course ...
My browser rejects them by default. I feel really dummy.
Comment: what do you mean accept cookies? This is no solution. Why would we change some default browser settings in order to make this work? I have not explicitly set anything to be blocked or rejected...


Seeing Intrinsic Curvature of a Surface

Question: Is there any issue with characterizing a surface as being intrinsically flat by saying "at no point does it either resemble a pringle (saddle) or a bullet (elliptic paraboloid)?" I'm trying to develop an eye for seeing the intrinsic curvature in a 2-dimensional surface.
Based on Gauss' initial definition of the intrinsic curvature of a surface at a point $p$ as the product of principal curvatures, $\kappa(p)=\kappa_{min}\kappa_{max}$, I think my characterization is reasonable if informal.
It also seems intuitively telling to take something intrinsically flat like a piece of paper or a placemat and give it some kind of intrinsic curvature only to have it resist by forming kinks and cusps.
Comment: the definition of the curvature as the product of the principal curvatures is _not_ intrinsic. See, e.g., https://math.stackexchange.com/questions/794327/which-of-principal-curvature-gaussian-curvature-and-mean-curvature-is-intrinsic
Comment: @user3257842 What you've stated is wrong. You have accounted for cylinders, but there are also cones and tangent developable surfaces.
Comment: You keep using the word intrinsic, but everything you talk about is extrinsic (i.e., depends on the embedding in $\Bbb R^3$). I would recommend you break this habit :) But if you don't have an elliptic point or a hyperbolic (saddle) point, then you have either a parabolic point or a planar point.
Comment: do you know the covariant derivative on $\mathbb R^3$?
Comment: @janmarqz It measures the part of the change in a vector field along a curve that's not due to the 'twisting' of the tangent plane?
Comment: @Thomas Maybe I should have said _Gaussian curvature_ instead of _intrinsic curvature_ to make clear that I wasn't claiming this to be an intrinsic definition, merely an _intrinsic quantity_. I just want to be able to look at a surface and say "that is intrinsically flat" or "that has intrinsic curvature" and I'm curious how other people apply their understanding of Gaussian curvature when looking at everyday objects.
Comment: $\kappa_{min}$ and $\kappa_{max}$ are the eigenvalues of the Weingarten's matrix of the surface.
Comment: It depends on the purpose of characterizing. If it's for your own intuition, then qualitatively _mostly yes_. It's necessary to say _mostly_ because, for example, a surface with one large principal curvature, like a thin tube, has wildly differing Gaussian curvature depending on the other (possibly visually indistinguishable from zero) principal curvature.
Comment: @TedShifrin I guess I need to get clear about the meaning of intrinsic vs. extrinsic, I thought that the "Egregious theorem" implied that even though the principle curvatures are extrinsic their product is describing something intrinsic (Gaussian curvature). Sort of like how a covariant and contravariant quantity can come together to describe an invariant quantity such as the trace.
I'm tickled that you responded to my post, thank you!
Comment: Sure, Gaussian curvature *is* intrinsic. But talking about saddle points and elliptic points is purely extrinsic!
Comment: Thank you jan, Andrew, and Ted for your replies.
Comment: My takeaways have been:
1) Be more judicious about what I call intrinsic, while Gaussian curvature is intrinsic, all the ways I was thinking about it (principal curvatures, pringles etc.) were extrinsic features of the surface.
2) The principle curvatures are the eigenvalues of the Weingarten matrix a.k.a. the matrix of the shape operator.*
3) Andrew made an interesting point about the limits of the "eyeballing" method of estimating Gaussian curvature due to the scale of one of the principal curvatures.
Comment: I think I finally understand the remark in Ted's book about how Gauss viewed $\kappa$ as the distortion of signed areas under the Gauss map. I didn't quite piece together how the principal directions being eigenvectors of the shape operator meant that a small curvilinear rectangle with sides given by the principal directions would be mapped to a dilated rectangle on the unit sphere.
Answer: Making this community wiki in the hopes of inviting others to collect and expand on the comments.
Extrinsic and intrinsic geometry Loosely, the "shape" of a smooth surface in Euclidean three-space is visually perceived by its principal curvatures. While these are individually extrinsic (not determined by the first fundamental form/induced metric of the surface), their product, the Gaussian curvature, turns out to be intrinsic (determined by the induced metric).
The shape operator, whose eigenvalues are the principal curvatures, is minus the differential of the Gauss map from the surface to the unit sphere. The determinant is the Jacobian of the Gauss map. In other words, the Gaussian curvature is the "local stretching factor" for how the Gauss map distorts area.
The limits of visualization Whether or not Gaussian curvature can be recognized visually depends on the circumstances. For example, a surface with one large principal curvature, like a thin tube, has wildly differing Gaussian curvature depending on the other (possibly visually indistinguishable from zero) principal curvature.

Specifically, take a point $p$ on a circle of radius greater than $1/r$ (possibly a line), draw a line $\ell$ in the plane of this circle, at distance $1/r^{2}$ from $p$ parallel to the tangent at $p$, and fix an arc $C$ lying to one side of $\ell$. If we revolve $C$ about $\ell$, we obtain a thin tube surface whose Gaussian curvature is between $-1/r$ and $1/r$ (a large interval for small positive $r$), but any two such surfaces are uniformly close (depending on the length of $C$), so visually difficult to distinguish.

Visual recognition requires care even for "surfaces with moderate principal curvatures." For example:

The "top" and "bottom" parallels of a circular torus are parabolic (one principal curvature is $0$).
The origin of a monkey saddle $z = x^{3} - 3xy^{2}$ is planar (both principal curvatures are $0$).
Answer: I try to describe a 2-D situation verbally, you can look up for descriptive  symbolic equations in a university library.
If you have a brittle egg/bullet  shaped dome $K>0$ and step on it making it flat there will occur radial cracks and gaps upto its disc edge.
On the other hand if you step on a flexible ( thin rubbery) pringle saddle shape $K<0$ and step on it, it becomes flat only after overlapping radial frills and wrinkles develop on the warped flattened disc.
The intrinsic curvature or Gauss curvature $K$ is visibly seen destroyed by forced flattening induced by forces normal to the shell surface.
Non-linear strains are described by pdes of von Kármán in his work on Buckling of doubly curved structures. The theory makes no distinction between radial tension or circumferential compression in creating a dome out of a flat disc. Vice-versa  it makes no distinction between radial compression and circumferential tension in creating a saddle out of a flat disc.
This also due to the fact that it is impossible to isometrically bring pringles and egg shells to a plane without tearing or overlapping by virtue of Gauss Egregium theorem in Surface Theory. Such a mapping is not possible. The curved grid lines will break or the net will fold up.
The theorem states that in pure Bending Gauss curvature $K$ is conserved ( btw as also other items derivable by the first fundamental form of Surface theory ).
So shells or surfaces of constant Gauss curvature will crack up or warp down on being forcibly flattened depending on whether initial Gauss curvature $K$ is positive or negative.

Seeing Intrinsic Curvature of a Surface


PHP Google Calendar API not returning error string

Question: I'm using a calendar which syncs both automatically and under request (if designated by user) with G!Calendar.
All works fine, except that I need to check if the calendar ID provided by the user exists.
For this I'm using:
<code>$cal = "GOOGLE CALENDAR ID";
$service = new Google_Service_Calendar($client);
$title = $service->calendars->get($cal);
</code>
If the ID exists, the script runs fine. If it doesn't, then the page craches.
How can I get the error JSON string it was supposed to return (as specified at the API resource page), so I can warn the user and block those errors from propagating?
Thanks in advance.
Answer: You should do a try catch the error will be caught and you can display the message to the user.
<code>function printCalendar($service, $fileId) {
  try {
    $calendar = $service->calendars->get($cal);
    print "Title: " . $file->getTitle();
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
}
</code>
Comment: Great! That did the job. Now I can "getCode()" it and personalize each exception and return it to the user. Thanks a lot.
Comment: Welcome to stack please remember to accept the answer if it helped you you will increase your own reputation


How to use normal Minecraft commands in a Minecraft Plugin?

Question: I want to program a Minecraft plugin and I want to use commands that are standard in Minecraft like the /worldboarder set command.
Specifically, I would like to program a plugin that set the worldboarder on 1000 blocks, and every hour it gets 50 blocks smaller. Is it possible to use the standard command in my plugin in a loop? Like the command /worldboarder set 1000 and how I use them in my plugin.
I would like to do something like this:
int distance = 1000;
while(distance > 100) {
    wait(3600000);
    // "/worldboarder set " + distance -50; // here how to run cmd ?
}

Comment: Hi, where are you stuck exactly ? Did you already write a plugin or something ? I understand what you want to do, but I want to know what is your begin, I will not make the plugin from 0, but I can give you the scheduler and all of what is in
Comment: In principle, I am still at zero. I have programmed a /heal command for practice to gain a little experience. So the plugin can also be activated in MC so far and now I want to include a command that controls the worldboarder, so to speak.
My approach would be approximately so:
'int distance = 1000;
while(distance > 100) {
wait(3600000);
"/worldboarder set " + distance -50;     //How do I add the /worldboarder set command in my code?'
Comment: Does this answer your question? [Dispatching a list of commands](https://stackoverflow.com/questions/25235479/dispatching-a-list-of-commands)
Answer: Firstly, you can't use wait function in the server, this will freeze the entiere server which is a big issue. You have to use Scheduler (see later).
Then, to run a simple comment, you have to use this:
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mycmd arg1 arg2");

So, you have to do something like that :
private int border = 1000; // actual border value
private BukkitTask task; // bukkit task to cancel it

@Override
public void onEnable() {
   task = getServer().getScheduler().runTaskTimer(this, () -> { // start lambda expression
      Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "worldboarder set " + border); // run cmd
      if(border == 100) { // no longer need to change world border.
         task.cancel(); // cancel actual task to never run it again
         return;
      }
      border -= 50; // reduce border amount for next time
   }, 20, 60 * 60 * 20);
}

Few additionnal informations :

The runTaskTimer method accept few arguments : the plugin, the runnable scheduler, the time before start (in tick) and the time between each call (in tick)
20 ticks = 1 second. Such as you want each hour: 60 * 60 = seconds per hour, so 60 * 60 * 20 = tick per hour
The time before start is 20 (so 1s) because spigot start plugin BEFORE fully load world. So it will not find worlds. And it will start to run scheduler after full server start (so after world). 1s is just to be sure, such as it doesn't change anything to gameplay to wait 1s at startup.
Don't need "/" in command. The / is the default character to say it's a command. Such as here we clearly say it's a command, we don't have to use it. Example

Documentation :

Lambda expression
Answer: In newer bukkit versions, you can use the bukkit.WorldBorder object (https://hub.spigotmc.org/javadocs/spigot/org/bukkit/WorldBorder.html)
You can modify the worldborder of a world by fisrt getting the world then getting its WorldBorder object
World world = Bukkit.getWorld("world"); // Most of the time the default world is named "world"
WorldBorder border = world.getWorldBorder();

Then you can do whatever you want with the worldborder
border.setSize(border.getSize() - 50); // Reduce the size of the border by 50 instantly

Hope this will be usefull if someone finds this post


What's the best way to promote in your jobs?

Question: I know I have to fulfill the given skills and be happy to have a chance to promote. But sometimes I can wait a week before any promotion happens. Even with the required skills filled and being fully restore from rest, food, blatter, etc.
Is it random or there is any other way to promote faster ?
Comment: Heh, and I was looking for a way to extend time to be promoted. While on the political career, keeping a good relation with the boss/coworkers, as well as working hard, helped me to reach level 10 within a week or two (sim days).
Answer: Jobs in The Sims 3 work a little differently than they have in past Sims Games. The core thing to keep in mind is that each job has different requirements for a fast promotion. On the "Jobs" subsection of your sim's profile, there is a bar. This is your performance bar, and whenever you max it, you get promoted (or a raise, if you're at max level).
For most jobs, Mood and Boss Relations are the biggest factors (and, again, a list of all factors can be found in the job panel).
If I'm remembering correctly, the Job Bar maxes at 100 'job points'. 'Job Points' are earned whenever your sim is at work and one of the job factors is listed as above "average" (the yellow, :| smilie) at +1 / hour, +2 / hour, or +3 / hour respectively. If the job factor is exceedingly poor, below the yellow "average, you can gain negative job points as well (again, -1 / hour, -2 / hour, and -3 / hour respectively).
Finally, there are a couple of factors independent from the 'job factors'. Sims with the Ambitious Trait or Multi-tasker Lifetime Happiness Reward get a free 1.5 / hour in work performance (they stack), as is the result of choosing to "work hard" from the work tone menu (at the result of massively increased Fun loss).
In some ways, this makes the higher promotions easier to get - you get more Job Factors (up to 4) at the higher ranks, which means while it is also easier to lose performance due to lack of skill / relations / other, once you get the relevant skill up into the positive effect, you promote earlier due to more cumulative bonus stacking.
Answer: If you look where your work hours are, then look where your mood is, then the bar next to that has to be filled to get a promotion.
Answer: Get the Workaholic, Ambitious and Schmoozer traits.
You can 'work hard' all day without stressing out, then you can go home and 'work from home' all night, and on your off days.
Throw a party (or just invite) and include your boss and all your co-workers to the party.
If you're promotion bar is 3/4 filled you can chat your boss into getting a promotion and/or raise.  Chat them up until they think you are being 'friendly/sociable' then 'discuss work' then hit them with the 'ask for promotion' and 'ask for raise'. Make sure you are at least good friends with your boss and that you have reached a friendly/sociable level of the conversation for it to work 100%.
If you just dont care anymore (and have a brave trait) you can 'demand a raise/promotion' while at work and from the options menu from the work bldg :)
Answer: use the karma power "lucky break" before they go to work and 70% of the time you'll get a promotion.
Comment: Is there a source for the `"70%"` part?


Flask, gunicorn, redis - Getting 500'd the 3rd route, but POST works in previous steps

Question: I'm trying to set up a local copy of web-dedupe working with the default setup, but it simply will not work for me after the third step. I'm able to upload the CSV, but after the fields are selected and the submit button is hit, I get an error:

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

Here is the code from app.py dealing with this route. The logs are also posted below. Any help would be much appreciated! Here is their working demo. Please let me know if additional info is needed!
@app.route('/select_fields/', methods=['GET', 'POST'])
def select_fields():
    status_code = 200
    error = None
    print flask_session.keys()
    if not flask_session.get('deduper'):
        return redirect(url_for('index'))
    else:
        inp = flask_session['deduper']['csv'].converted
        filename = flask_session['filename']
        flask_session['last_interaction'] = datetime.now()
        reader = csv.reader(StringIO(inp))
        fields = reader.next()
        del reader
        if request.method == 'POST':
            field_list = [r for r in request.form]
            if field_list:
                training = True
                field_defs = {}
                for field in field_list:
                    field_defs[field] = {'type': 'String'}
                data_d = readData(inp)
                flask_session['deduper']['data_d'] = data_d
                flask_session['deduper']['field_defs'] = copy.deepcopy(field_defs)
                start = time.time()
                deduper = dedupe.Dedupe(field_defs)
                deduper.sample(data_d, 150000)
                flask_session['deduper']['deduper'] = deduper
                end = time.time()
                send_ga_log(
                    'Dedupe initialization',
                    flask_session['ga_cid'],
                    label='Timing in seconds',
                    value=int(end-start)
                )
                return redirect(url_for('training_run'))
            else:
                error = 'You must select at least one field to compare on.'
                send_ga_log('Select Fields Error', flask_session['ga_cid'], label=error)
                status_code = 500
        return render_app_template('select_fields.html', error=error, fields=fields, filename=filename)

@app.route('/training_run/')
def training_run():
    if not flask_session.get('deduper'):
        return redirect(url_for('index'))
    else:
        filename = flask_session['filename']
        return render_app_template('training_run.html', filename=filename)

App error output:
Traceback (most recent call last):
  File "/home/jbutler/fuck2/dedupe-web-master/run_queue.py", line 4, in <module>
    queue_daemon(app)
  File "/home/jbutler/fuck2/dedupe-web-master/queue.py", line 43, in queue_daemon
    msg = redis.blpop(app.config['REDIS_QUEUE_KEY'])
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/redis/client.py", line 1146, in blpop
    return self.execute_command('BLPOP', *keys)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/redis/client.py", line 570, in execute_command
    connection.send_command(*args)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/redis/connection.py", line 556, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/redis/connection.py", line 532, in send_packed_command
    self.connect()
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/redis/connection.py", line 436, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.

gunicorn error log :
ERROR:app:Exception on /select_fields/ [POST]
Traceback (most recent call last):
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/jbutler/fuck2/dedupe-web-master/app.py", line 154, in select_fields
    deduper = dedupe.Dedupe(field_defs)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/dedupe/api.py", line 176, in __init__
    super(DedupeMatching, self).__init__(*args, **kwargs)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/dedupe/api.py", line 591, in __init__
    self.data_model = DataModel(variable_definition)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/dedupe/datamodel.py", line 29, in __init__
    field_model = typifyFields(fields)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/dedupe/datamodel.py", line 91, in typifyFields
    raise TypeError("Incorrect field specification: field "
TypeError: Incorrect field specification: field specifications are dictionaries that must include a type definition, ex. {'field' : 'Phone', type: 'String'}
ERROR:app:Exception on /select_fields/ [POST]
Traceback (most recent call last):
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/jbutler/fuck2/dedupe-web-master/app.py", line 154, in select_fields
    deduper = dedupe.Dedupe(field_defs)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/dedupe/api.py", line 176, in __init__
    super(DedupeMatching, self).__init__(*args, **kwargs)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/dedupe/api.py", line 591, in __init__
    self.data_model = DataModel(variable_definition)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/dedupe/datamodel.py", line 29, in __init__
    field_model = typifyFields(fields)
  File "/home/jbutler/fuck2/dedupe-web-master/deploy_scripts/build/venv/local/lib/python2.7/site-packages/dedupe/datamodel.py", line 91, in typifyFields
    raise TypeError("Incorrect field specification: field "
TypeError: Incorrect field specification: field specifications are dictionaries that must include a type definition, ex. {'field' : 'Phone', type: 'String'}

Comment: do you have redis installed? seems not looking at the big Error 111 connecting to localhost:6379. Connection refused. error
Comment: Yes, I used apt-get install redis-server. I'm able to connect just fine with redis-cli too to that exact IP/port. I also installed the pip redis. Thank you for your response!
Answer: I'm the guy who is mainly responsible for putting together that code and I think I figured out what's going on. The last time I touched that code was in between the 0.5 and the 0.6 release which means that only some of the API changes were incorporated. I just pushed up a commit last week (on the 27th) that should address the issue.
A couple things to note:
1) The error traceback that you were getting from the "run_queue" process is actually significant and means that, for whatever reason, that process was unable to connect to Redis. I realize that you are able to connect to redis via the command line (according to the comment above) but for whatever reason this app does not seem to be able to. From a Python shell, try something like
>>> from redis import Redis
>>> r = Redis()

That should attempt to connect to Redis on the default port and host (localhost, 6379).
2) Since you're running this locally, you might want to not have to deal with the limit that we set at 10,000 rows for an uploaded spreadsheet. Frankly, this is a rather arbitrary limit that we set for the version that is deployed at dedupe.datamade.us. If you want to remove that limit, you can comment out these lines: https://github.com/datamade/dedupe-web/blob/master/dedupe_utils.py#L57-L60
Let me know if you're still running into issues after pulling the new commit.


How to create a dict using Ansible inventory

Question: I need bit of help in creating a dict of host names and ip address out of a Ansible inventory.
Here is my inventory:
web:
  hosts:
    Webserver1:
      ansible_host: "10.10.10.10"
      Environment: "Dev"
      location: DC1
    Webserver2:
      ansible_host: "10.10.10.11"
      Environment: "Dev"
      location: DC1
    Webserver3:
      ansible_host: "10.11.10.10"
      Environment: "Dev"
      location: DC2

and I want to run a playbook on my local Ansible control machine to create a dict as follows
host_dict={Webserver1:10.10.10.10, Webserver2:10.10.10.11, Webserver3:10.11.10.10}

Any help is greatly appreciated.
Thanks
Answer: Here's a simple demo:
- name: a play that runs entirely on the ansible host
  hosts: localhost
  vars:
   host_dict:
    Webserver1: 10.10.10.10
    Webserver2: 10.10.10.11

  tasks:
    - debug: msg="{{ host_dict }}"

In YAML, if it does not start with a - then it is a dictionary key, otherwise it's a list. See more advanced examples here: https://docs.ansible.com/ansible/latest/plugins/lookup/dict.html
Comment: exactly I am going to use this dict in different places in my plabyook. Just a note I am not running my playbook against hostgroup "web" and running on local ansible control machine. IF
Comment: Thanks but I don't want to hard code the dict in my play, I want to read it from my inventory and create a dict.
Comment: So with "out of the inventory" you mean deriving a dictionary from the inventory for later usage in a playbook?


How can a Filtration be interpreted as Information / Filtration for repeated Coin toss

Question: Say we throw a coin three times. The sample space is then given by $\Omega=\{HHH, HHT, HTH, ..., THT, TTT\}$. The Filtration is given by:
$\mathbb{F}_0=\{\emptyset, \Omega\}$
$\mathbb{F}_1=\mathbb{F}_0 \cup \{\{HHH, HHT, HTH, HTT\},\{THH, THT, TTH, TTT\}\}$
$\mathbb{F}_2=\mathbb{F}_1 \cup \{\{HHH, HHT\}, \{HTH, HTT\},\{THH, THT\}, \{TTH, TTT\},\dots\}$
etc.
I understand the concept of a $\sigma$-algebra and also the formal definition of a Filtration. What I don't understand:
How exactly can this be interpreted to be information being released? As far as I can tell, the filtration is completely deterministic, how could it possibly contain information about past events? For example, whether the first toss is $H$ or $T$, the Filtration after the first throw is $\mathbb{F}_1$ regardless.
Comment: Are you sure that $\mathbb{F}_i\in\mathbb{F}_{i+1}$?  Shouldn't it rather be $\mathbb{F}_{i+1}=\mathbb{F}_i\cup\{...\}$ so that $\mathbb{F}_i\subseteq\mathbb{F}_{i+1}$?
Comment: @fweth makes sense, thank you
Answer: Sorry, I cannot post it as a comment. It seems to me that the core of your question is more how to interpret a sigma algebra as the information you can obtain from a random object.
I understand it in this way: $ \mathbb F_1$ is composed by the events you can distinguish after the first toss. You will be able to tell only which of those two events happened. As you go on in time you can divide your previous events into more events, which are more precise since are smaller. Note that you still have the information of how the first coin toss went, since $\mathbb F_1$ is in $\mathbb F_2$.
Another way to see it is  The sigma algebra tells you the information you have in the sense that tells you which functions ( or observables) you are able to determine the value of: those measurable with respect to the sigma lagebra
Comment: It doesn't contain the information in that sense, more like it contains all the events which can be decided upon at time $t$.  E.g. at time $2$, you can answer the question if the first two tosses showed the same side.  So the event that the the first two tosses showed the same side must be contained in $\mathbb{F}_2$.
Comment: The main source of my confusion is that textbooks like to say thinks like: 'the filtration contains information about [whatever] up to this point'. To me that sounds like I could look at the filtration and say what happened up to now (For example what side of the coin was thrown in the first toss). But by looking at $\mathbb{F}_1$ i cannot deduce any such thing.
Comment: I also add that the smaller  elements of $\mathbb F_2$, for example {HHH, HHT} can be interpreted as what happened until the second toss. Of course in continuous time the situation is more complicated
Answer: The filtration is an information flow in the sense that you can spot the sets which we can assign a measure to. It doesn't mean you know exactly what happened after every coin flip but you have more and more events which you can assign a probability to.
In your case (if $ \mathcal{A}_i := \{ \text{i on first toss} \}, i \in \{H,T\} $)

If $\; n=0$ we have no information about the outcomes, hence we can only assign probabilities to the empty set and the whole sample space.

If $\; n=1$ we only know if the first coin flip was H or T (we have a bit more information than in 1.). Hence we can assign probabilities to more sets. in particular $\emptyset, \Omega, \mathcal{A}_T, \mathcal{A}_H$

If $\; n=2$ we know the first two outcomes, hence we can assign probabilities to even more events (which include the events in 2. as well), which intuitively means we have more information about the complete outcome.

If $\; n=3$ the information is complete. We can assign probabilities to all possible events of $\Omega$, i.e. $\mathbb{F}_3 = 2^{\Omega}$ which consists of $256$ sets.