How can I conditionally provide a default reference without performing unnecessary computation when it isn’t used?

You don’t have to create the default vector if you don’t use it. You just have to ensure the declaration is done outside the if block. fn accept(input: &Vec<String>) { let def; let vec = if input.is_empty() { def = vec![“empty”.to_string()]; &def } else { input }; // … do something with `vec` } Note … Read more

Pandas: Join dataframe with condition

Try the following: # Transform data in first dataframe df1 = pd.DataFrame(data) # Save the data in another datframe df2 = pd.DataFrame(data) # Rename column names of second dataframe df2.rename(index=str, columns={‘Reader_ID1’: ‘Reader_ID1_x’, ‘SITE_ID1’: ‘SITE_ID1_x’, ‘EVENT_TS1’: ‘EVENT_TS1_x’}, inplace=True) # Merge the dataframes into another dataframe based on PERSONID and Badge_ID df3 = pd.merge(df1, df2, how=’outer’, on=[‘PERSONID’, … Read more

Conditional Logic in ASP.net page

I suggest wrapping each key/value pair into custom control with 2 properties. This control will display itself only if value is not empty: <%@ Control Language=”C#” AutoEventWireup=”true” CodeBehind=”ShowPair.ascx.cs” Inherits=”MyWA.ShowPair” %> <% if (!string.IsNullOrEmpty(Value)) { %> <%=Key %> : <%=Value %> <% } %> And then put controls into repeater template: <asp:Repeater runat=”server” ID=”repeater1″> <ItemTemplate> <cst:ShowPair … Read more

What is the difference between if (NULL == pointer) vs if (pointer == NULL)?

There is no difference. What your professor prefers is called Yoda conditions also see “Yoda Conditions”, “Pokémon Exception Handling” and other programming classics. It is supposed to prevent the usage of assignment(=) by mistake over equality(==) in a comparison, but modern compilers should warn about this now, so this type of defensive programming should not … Read more

How do I use NSConditionLock? Or NSCondition

EDIT: as @Bonshington commented, this answer refers to NSCondition (as opposed to NSConditionLock): – (void) method1 { [myCondition lock]; while (!someCheckIsTrue) [myCondition wait]; // Do something. [myCondition unlock]; } – (void) method2 { [myCondition lock]; // Do something. someCheckIsTrue = YES; [myCondition signal]; [myCondition unlock]; } The someCheckIsTrue can be anything, it could be a … Read more