Thursday, 3 October 2013

InvokeOnMainThread doesn't work with `method group`

InvokeOnMainThread doesn't work with `method group`

NOTE: I found a workaround to my problem even before asking the question,
but I'm still wondering why it behave like this.
I'm doing an usual xamarin.iOS application, using async/await, Mvvm, ...
nothing fancy on the technology side.
I found out that the following code (using a method group) wasn't working:
ViewModel.PropertyChanged += (sender, e) => {
if (e.PropertyName != "MyProperty")
return;
InvokeOnMainThread (tableViewController.TableView.ReloadData);
};
If I put a breakpoint on InvokeOnMainThread, I can see the exception:

But the same code with a lambda expression works just fine.
ViewModel.PropertyChanged += (sender, e) => {
if (e.PropertyName != "MyProperty")
return;
InvokeOnMainThread (() => tableViewController.TableView.ReloadData ());
};
A part of me is suspecting a bug, another part is already blaming my
ignorance. Anyone knows which part is right ?
Version details:
Xamarin Studio
Version 4.1.12 (build 6)
Installation UUID: [...]
Runtime:
Mono 3.2.3 ((no/8d3b4b7)
GTK+ 2.24.20 theme: Raleigh
GTK# (2.12.0.0)
Package version: 302030000
Apple Developer Tools
Xcode 5.0 (3332.22)
Build 5A1412
Xamarin.iOS
Version: 7.0.1.4 (Business Edition)
Hash: [...]
Branch:
Build date: 2013-20-09 23:14:32-0400
Build Information
Release ID: 401120006
Git revision: a9ae69a4bf37955e4ab4df0cec7804f574c51f72
Build date: 2013-09-25 16:59:37+0000
Xamarin addins: 761ae26f220068dda0b62f0dd2253f617589a8c6
Operating System
Mac OS X 10.8.5
Darwin Stephanes-MacBook-Air.local 12.5.0 Darwin Kernel Version 12.5.0
Mon Jul 29 16:33:49 PDT 2013
root:xnu-2050.48.11~1/RELEASE_X86_64 x86_64

Wednesday, 2 October 2013

NSJSONSerialization - What is the proper value to specify no NSJSONWritingOptions for dataWithJSONObject:options:error:?

NSJSONSerialization - What is the proper value to specify no
NSJSONWritingOptions for dataWithJSONObject:options:error:?

Apple's documentation has the NSJSONWritingOptions enum with one constant
defined: NSJSONWritingPrettyPrinted, and says that "If this option is not
set, the most compact possible JSON representation is generated."
I definitely want the most compact JSON representation.
My question is: what is the proper value to pass the
dataWithJSONObject:options:error: function if I don't want pretty printed,
and why?
The NSJSONWritingOptions enum is defined as
enum { NSJSONWritingPrettyPrinted = (1UL << 0) }; typedef NSUInteger
NSJSONWritingOptions;
I have read in a different post that 0 should be passed, but with no
further explanation as to why it shouldn't be nil.

Why content_for method undefined in rails view?

Why content_for method undefined in rails view?

I have a rails project.
In the application.html.slim I have:
doctype html
html
head
title RailsMongoidPj
= stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= csrf_meta_tags
meta content="width=device-width, initial-scale=1.0" name="viewport"
= yield(:html_head)
body
= yield
In a controller SearchController, which has a method:
def javascript(*files)
content_for(:html_head) do
javascript_include_tag(*files)
end
end
helper_method :javascript
Also this controller has a method new with a corresponding view, which
content is:
= javascript('/vendor/assets/javascript/handelbars.runtime.js')
- content_for :html_head do
script#entry-template type="text/x-handlebars-template"
| template content
But I have an error:
undefined method `content_for' for #<SearchFlickrController:0x007f8e4f2bae78>
Extracted source (around line #3):
1 / search flickr api page
2
3 = javascript('/vendor/assets/javascript/handelbars.runtime.js')
4
5 - content_for :html_head do
6 script#entry-template type="text/x-handlebars-template"
Why the method is content_for undefined? Isn't it an standard rails method?

When overriding the registration controller from devise, is it possible to access the newly created user on the create action?

When overriding the registration controller from devise, is it possible to
access the newly created user on the create action?

I'm trying to create a folder right after a user registers, so I override
the create action on the registration controller (devise) but I don't know
how to access the newly created user in order to create the folder with
it's name to upload files later.
So far I've got this:
class RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
create_folder
end
def update
super
end
def create_folder
path = Pathname.new(':rails_root/tmp/')
directory_name = ":current_user"
Dir.mkdir(path, directory_name) unless File.exists?(directory_name)
end
end
routes.rb
devise_for :users, :controllers => {:registrations => "registrations"}
I followed this to override the registration controller.
Should I leave it there or move it to the create action? Instead of using
a method
is that the right way to access the current user?
Maybe instead of registration it's better to do it on sign in?
I'd appreciate any help I can get.

LINQ to SQL, not null, use default value

LINQ to SQL, not null, use default value

I'm using EF with DB First. My table looks like this:
CREATE TABLE [dbo].[Person](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) NOT NULL,
[dob] [datetime] NOT NULL
CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED )
GO
ALTER TABLE [dbo].[Person]
ADD CONSTRAINT [DF_Person_dob] DEFAULT ('12.12.3000') FOR [dob]
After using DB First I get the following partial Person class:
using System;
public partial class Person
{
public int id { get; set; }
public string name { get; set; }
public System.DateTime dob { get; set; }
}
The problem I have is that when I want to use the DB generated default
value for 'dob' field I get an exception because nulls are not allowed.
I'm trying to do this:
using (var db = new NullTestEntities())
{
var person = db.Person.Create();
person.name = "John Doe";
db.Person.Add(person);
db.SaveChanges();
}
I've tried adding
Column(IsDataBaseGenerated=true)
but I can't compile because I get an error:
'System.ComponentModel.DataAnnotations.Schema.ColumnAttribute' does not
contain a
definition for 'IsDatabaseGenerated'
What do I need to do in order to not define the dob attribute in C# code
and let the database generate the default value?

Tuesday, 1 October 2013

Menu images dropping down a little to low?

Menu images dropping down a little to low?

You can view the page in question here: http://portal.envisionlocal.com
Basically the image menu-sep.png which acts as a line break between the
different menus in my header is dropping down just a fraction below the
navigation bar and I can't figure out what to do to fix that. I'd prefer
to fix it inline instead of in a CSS file because the only solution to
fixing in the CSS file that I've found is editing line 52 of flex.css:
I changed
font: 13px/1.6em "Open Sans",Arial,sans-serif;
to
font: 11px/1.6em "Open Sans",Arial,sans-serif;
and it fixed the problem but also made all of the other text on the page
way too small - it didn't change the text size in the header but did fix
the problem for some reason...
Any help would be appreciated! Thanks!

Which is most cache friendly?

Which is most cache friendly?

I am trying to get a good grip on data oriented design and how to program
best with the cache in mind. There's basically two scenarios that I cannot
quite decide which is better and why - is it better to have a vector of
objects, or several vectors with the objects atomic data?
A) Vector of objects example
struct A
{
GLsizei mIndices;
GLuint mVBO;
GLuint mIndexBuffer;
GLuint mVAO;
size_t vertexDataSize;
size_t normalDataSize;
};
std::vector<A> gMeshes;
for_each(gMeshes as mesh)
{
glBindVertexArray(mesh.mVAO);
glDrawElements(GL_TRIANGLES, mesh.mIndices, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
....
}
B) Vectors with the atomic data
std::vector<GLsizei> gIndices;
std::vector<GLuint> gVBOs;
std::vector<GLuint> gIndexBuffers;
std::vector<GLuint> gVAOs;
std::vector<size_t> gVertexDataSizes;
std::vector<size_t> gNormalDataSizes;
size_t numMeshes = ...;
for (index = 0; index++; index < numMeshes)
{
glBindVertexArray(gVAOs[index]);
glDrawElements(GL_TRIANGLES, gIndices[index], GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
....
}
Which one is more memory efficient and cache friendly resulting in less
cache misses and better performance, and why?