findFirst method in Realm? - cocoa

I'm switching from Core Data ( Magical Record ) to Realm and I was wondering if there was an equivalent of MR_findFirst ?
For now, I'm doing :
if ([myRlmObject allObjects].count > 0) {
myRlmObject *myFirstObject = [myRlmObject allObjects][0];
}
Thanks in advance !

You can simplify that and just do:
[myRlmObject allObjects].firstObject

Related

Matlab Transform old school min find into fminsearch

My code is the following. I was told fminsearch would solve this faster. I checked the docs and tutorials but I'm still in the dark. How would you implement fminsearch here? Thanks in advance.
MIN=1e10;
up_vec= u_min1+ ku*lambda;
vp_vec= v_min1+ kv*lambda;
wp_vec= w_min1+ kw*lambda;
%%the loop
for i_up=1:length(up_vec)
for i_vp=1:length(vp_vec)
for i_wp=1:length(wp_vec)
Jp(i_up,i_vp,i_wp)=norm(p- (A\[up_vec(i_up);vp_vec(i_vp);wp_vec(i_wp)]).* ...
[exp(-1i*2*pi/lambda*up_vec(i_up));...
exp(-1i*2*pi/lambda*vp_vec(i_vp));...
exp(-1i*2*pi/lambda*wp_vec(i_wp))]);
if Jp(i_up,i_vp,i_wp) < MIN
MIN=Jp(i_up,i_vp,i_wp);
ind_umin = i_up;
ind_vmin = i_vp;
ind_wmin = i_wp;
up_vec_min=up_vec;
vp_vec_min=vp_vec;
wp_vec_min=wp_vec;
pp_min=pp;
end
end
end
end
You need to define your objective function and then use fminsearch. for instance:
funJp = #(u,v,w)(norm(p- (A\[u;v;w]).* ...
[exp(-1i*2*pi/lambda*u);...
exp(-1i*2*pi/lambda*v);...
exp(-1i*2*pi/lambda*w)]));
x = fminsearch(funJp,[umin_1,vmin_1,wmin_1]);

How to use onFrameUpdate in lua?

I want to do something with event listener in lua, this is for example :
function onTouch(event)
if(event.target.frame == 2) then
event.target:setFrame(1)
elseif(event.target.frame == 3) then
bar:setFrame(bar.frame + 1)
event.target:setFrame(1)
event.target:play()
end
end
those if-end will work when object is in touch, but how I want that thing work when frame change ? I try onFrameChange but there's nothing happened.
Thanks before, im newbie :D
You need the enterFrame listener
function printTimeSinceStart( event )
if(object.frame == 2) then
object:setFrame(1)
elseif(object.frame == 3) then
bar:setFrame(bar.frame + 1)
object:setFrame(1)
object:play()
end
end
Runtime:addEventListener("enterFrame", onEnterFrame)

How to generate tuple in ? operator of pig

My code is as follows
temp = foreach requiredData generate (recordType == 3 ? controllingCalledNum : callingPtyNum)as ServiceNumber, (recordType == 3 ? callingPtyNum : controllingCalledNum)as DestinationNumber;
Here my code is reduntant..
Can I generate tuple inside '?' operator and do something like this which I can further FLATTERN
temp = foreach requiredData generate (recordType == 3 ? (controllingCalledNum,callingPtyNum) : (callingPtyNum,controllingCalledNum))as (ServiceNumber,DestinationNumber);
I am getting error if I try to do like this
Please help me.
Use the built-in TOTUPLE UDF:
temp = foreach requiredData generate FLATTEN(recordType == 3 ? TOTUPLE(controllingCalledNum,callingPtyNum) : TOTUPLE(callingPtyNum,controllingCalledNum))as (ServiceNumber,DestinationNumber);

conditional statements not working in expression editor

I want to check current month to many condition as below.
so I take TextField ,edit its pattern to MM & in expression editor edit below code
new java.util.Date()>=4 && new java.util.Date() <= 7 ? "Q1" :
new java.util.Date()>=8 && new java.util.Date() <=11 ? "Q2" : "Q3"
but it gives error
Error filling print... Error evaluating expression :      Source text : new java.util.Date()>=4 && new java.util.Date() <= 7 ? "Q1" : new java.util.Date()>=8 && new java.util.Date() <=11  ? "Q2" : "Q3"
Setting up the file resolver..
but when I give expression like
new java.util.Date()== 4 ? "Q1" : "Q2"
It works fine.
Does iReport not able to resolve multiple conditions ? or should I give different TextField with single condition ?
are you sure new java.util.Date() is just give you the month.
try this it will give you the moth
(new SimpleDateFormat("M")).format(new java.util.Date())
also you can use yyyy(year) or d(date) to check
and Integer.parse(...month...) or Date.parse(...month...) maybe needed, if you don't have your Qs as integer or date.
Try using calendar instead.
(Calendar.getInstance()).get(Calendar.MONTH)>=3 && (Calendar.getInstance()).get(Calendar.MONTH)>=6 ? "Q1" :
(Calendar.getInstance()).get(Calendar.MONTH)>=7 && (Calendar.getInstance()).get(Calendar.MONTH)>=10 ? "Q2" : "Q3"
can you please try putting the expression in brackets like
(new java.util.Date()>=4 && new java.util.Date() <= 7 )? "Q1" : (
(new java.util.Date()>=8 && new java.util.Date() <=11 ) ? "Q2" : "Q3")
You can use multiple condition like this
new java.util.Date() >= 4 ?
"Q1" :
new java.util.Date() <= 7 ?
"Q2" :
new java.util.Date() >= 8 ?
"Q3" :
"Q4"

Why DIA SDK get_libraryName symbol returns NULL for IDiaSymbol?

I need to find the correct .dll/.exe from where the function enumerated. For this I am using get_libraryName which to me should return file Name(.dll/.exe) in which the function was originally defined.
But It returns every time NULL(BadPtr=0x00000)..
Is there any way out to retrieve the exact file Name from where the function was being defined and used ?
Regards
Hassan
IDiaSession mSession;
DiaSourceClass mSourceClass;
IDiaSymbol mGlobalScope;
string pdbFileName = #"c:\test.pdb";
mSourceClass = new DiaSourceClass();
mSourceClass.loadDataFromPdb(pdbFileName);
mSourceClass.openSession(out mSession);
mSession.loadAddress = loadAddress;
mGlobalScope = mSession.globalScope;
IDiaEnumSymbols methodSymbols;
mGlobalScope.findChildren(SymTagEnum.SymTagFunction, null, 0, out methodSymbols);
foreach (IDiaSymbol methodSymbol in methodSymbols)
{
string projectName = functionSymbol.lexicalParent.name;
}
Hope this helps !

Resources