C# Condensing Multiple single if statements

I have this piece of code in my service layer and registers and student for a course.
As you can see if have alot of if statements and i was wondering if any could suggest a nicer way of writing this code?

    public async Task<bool> RegisterStudentForCourseAsync(RegisterStudentForCourseRequest registerStudent)
    {
        var student = await _studentRepository.GetStudentInformationAsync(registerStudent.StudentId);

        if (student == null)
        {
            throw new StudentCourseRegistrationException("Student Not Found");
        }
       
        var alreadyRegistered = student.Enrollments.Any(x => x.CourseId == registerStudent.CourseId);

        if (alreadyRegistered)
        {
            throw new StudentCourseRegistrationException("Student is Already Registered for Course");
        }
       
        //change this to a config setting
        if (student.SubjectCount >= 5)
        {
            throw new StudentCourseRegistrationException("Cannot Register Amount of Courses");
        }

        var course = _courseRepository.GetCourseInformation(registerStudent.CourseId);

        if(course == null)
        {
            throw new StudentCourseRegistrationException("Course Not Found");
        }
        
        if(course.Enrolled >= course.Capacity)
        {
            throw new StudentCourseRegistrationException("Course is fully Booked");
        }

        return await _courseRepository.SaveRegisterationOfStudentForCourse(course, registerStudent, student);
    }
}

seo – Is double 302 redirect worse than a single one?

There’re old and new websites. Due to some constraints, an old website can’t redirect users directly to a new website. There’re thousands of old URLs on an old website and all of them will have to redirect a user to a new URL on a new site. The parts of a domain on the old and new domains may be different.

It’ll work this way:

old_website.com/old_url1 --> redirector.com/old_url1 --> new_website.net/new_url1

Main question: how much, if any, double redirect like this be worse than a single direct one in terms of SEO? Only compared to a single/direct redirect if it was possible.

Should boths parts be redirected with 301 or 302 codes?

webserver – Securing application server for a single user

I’m building some simple dashboard app for myself, but I want to have them on multiple devices – hence the server and front end. As I will be the only user who will access the application server, what security should I implement.

Stack:
Postgres
Ktor (Kotlin) server, HTTPS, only REST API
Front end

I’ll run AWS Lightsail instance since I don’t need anything heavy. Postgres and application server will be there, with only ports 443 and 22 open. Front end will be on S3 with CloudFront.

I’m doing this because it’s easier for me to make a browser “app”, than to make an Android app + something for desktop and keep them in sync.

I’ll be using the app from multiple networks. At home (where I don’t have a static IP, which would solve some of the problems), from mobile network, from work, when traveling to other countries, etc.

For background, I’ve been working on server for almost 3 years, Spring + Hibernate, Postgres. I have a fair knowledge of linux, hosting a server on it, some of AWS services and basic knowledge of database administration. I’ve done a bit of front end, but I’ll have to get back to that soon. I have almost no knowledge of security beyond basic JWT and SSH.

plotting – Two functions with single Manuipulate[]

I have code which works exactly I want it to work:

f[x_] := Sqrt[25 - x^2]
Manipulate[
 Plot[f[x], {x, from, to}, AspectRatio -> Automatic, 
  PlotRange -> {{-20, 20}, {-20, 20}}], {{from, -10, "x"}, -10, 10, 
  Appearance -> "Labeled"}, {{to, 10, "y"}, -10, 10, 
  Appearance -> "Labeled"}]

output:

enter image description here

Now instead of one function, I want to use two function in Manipulate[] and manipulate their x and y values:

f1[x1_] := Sqrt[25 - x^2]
f2[x2_] := -Sqrt[25 - x^2]

I tried to modify code above but without any luck. How to modify code above to use two functions in Manipulate[] and manipulate their x and y values?

cpu – Linux keeps all cores at the (roughly) same frequency during single threaded load

I am using TLP with powersave governor and intel_pstate driver with Intel Sidestep enabled.

I noticed that the powersave governor does its job, the cores when idle sit at 800Mhz, BUT when any kind of load is introduced ALL the cores clock up. They for all intents and purposes remain at roughly the same clock speed no matter the load. I fired up a single threaded workload, even tried limiting its core affinity to core 0 and yet they all hit their max at 1.5GHZ.

Its my understanding that it should be capable to only clock up the cores that need it to save power? Am i mistaken?

Its also worth mentioning that i am not able to set per core frequency with cpupower (It just always effects all the cores)

Should it function as i thought? If so whats wrong?

ls /sys/devices/system/cpu/cpu0/cpufreq/
affected_cpus   cpuinfo_max_freq  cpuinfo_transition_latency            energy_performance_preference  scaling_available_governors  scaling_driver    scaling_max_freq  scaling_setspeed
base_frequency  cpuinfo_min_freq  energy_performance_available_preferences  related_cpus           scaling_cur_freq     scaling_governor  scaling_min_freq
/sys/devices/system/cpu/cpu9/cpufreq/scaling_driver    = intel_pstate
/sys/devices/system/cpu/cpu9/cpufreq/scaling_governor  = powersave
/sys/devices/system/cpu/cpu9/cpufreq/scaling_available_governors = performance powersave
/sys/devices/system/cpu/cpu9/cpufreq/scaling_min_freq  =   800000 (kHz)
/sys/devices/system/cpu/cpu9/cpufreq/scaling_max_freq  =  2300000 (kHz)
/sys/devices/system/cpu/cpu9/cpufreq/energy_performance_preference = power (HWP.EPP)
/sys/devices/system/cpu/cpu9/cpufreq/energy_performance_available_preferences = default performance balance_performance balance_power power

/sys/devices/system/cpu/intel_pstate/min_perf_pct      =  16 (%)
/sys/devices/system/cpu/intel_pstate/max_perf_pct      =  30 (%)
/sys/devices/system/cpu/intel_pstate/no_turbo          =   1
/sys/devices/system/cpu/intel_pstate/turbo_pct         =  62 (%)
/sys/devices/system/cpu/intel_pstate/num_pstates       =  41

/sys/module/workqueue/parameters/power_efficient       = Y
/proc/sys/kernel/nmi_watchdog                          = 0
processor   : 15
vendor_id   : GenuineIntel
cpu family  : 6
model       : 158
model name  : Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
stepping    : 13
microcode   : 0xca
cpu MHz     : 800.069
cache size  : 16384 KB
physical id : 0
siblings    : 16
core id     : 7
cpu cores   : 8
apicid      : 15
initial apicid  : 15
fpu     : yes
fpu_exception   : yes
cpuid level : 22
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
vmx flags   : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple shadow_vmcs pml ept_mode_based_exec
bugs        : spectre_v1 spectre_v2 spec_store_bypass swapgs taa itlb_multihit
bogomips    : 4601.60
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

Get sum of values of a single cell accross many sheets

I have 10 sheets from the same template with True/False values.
I want to count the number of True values in a certain cell across all sheets. I tried the following but it doesn’t work.

=COUNTIf(('1'!B3,'2'!B3,'3'!B3,'4'!B3, ..., '10'!B3),"=True")

Update
I figured this works but is there any more convenient way?

=sum(N('1'!B3),N('2'!B3),N('3'!B3),N('4'!B3))

Suggestion on Single Level Of Abstraction per Function – Java

I followed the SLAP principle in the below code.

But with “Mixing Level Of Abstraction” (refer below code) I can avoid the single line methods.

My question is – is it good to avoid the single line method in this case? But I believe the code with “SLAP Principle” has better readability than the other one. Please share your suggestions.

SLAP Principle:

public class TestAccount {
    private static final String DEFAULT_VALUE = "test_default";

    public void modify(Creditor creditor) {
        PartyDetails partyDetails = generatePartyDetails();
        assignPartyDetails(creditor, partyDetails);
    }

    private PartyDetails generatePartyDetails() {
        PartyDetails partyDetails = new PartyDetails();
        OrganisationIdentification orgId = generateOrgIdDetails();
        assignOrgIdValueToId(orgId, party6Choice);
        return partyDetails;
    }

    private OrganisationIdentification generateOrgIdDetails() {
        OrganisationIdentification orgId = new OrganisationIdentification();
        OtherIssueDetails otherIssuerDetails = generateIssuerDetails();
        assignOtherIssuerDetailsToOrgIdList(otherIssuerDetails, orgId);
        return orgId;
    }

    private OtherIssuerDetails generateIssuerDetails() {
        OtherIssuerDetails otherIssuerDetails =
                new OtherIssuerDetails();
        otherIssuerDetails.setIssr(DEFAULT_VALUE);
        return otherIssuerDetails;
    }

    private void assignOtherIssuerDetailsToOrgIdList(OtherIssuerDetails
                                                             otherIssuerDetails,
                                                     OrganisationIdentification
                                                             orgId) {
        orgId.getOthr().add(otherIssuerDetails);
    }

    private void assignOrgIdValueToId(OrganisationIdentification orgId,
                                      PartyDetails id) {
        id.setOrgId(orgId);
    }

    private void assignPartyDetails(Creditor creditor,
                                    PartyDetails partyDetails) {
        creditor.setId(partyDetails);
    }
}

Mixed Level Of Abstraction:

public class TestAccount {
    private static final String DEFAULT_VALUE = "test_default";

    public void modify(final Creditor creditor) {
        PartyDetails partyDetails = generatePartyDetails();
        creditor.setId(partyDetails);
    }

    private PartyDetails generatePartyDetails() {
        PartyDetails partyDetails = new PartyDetails();
        OrganisationIdentification orgId = generateOrgIdDetails();
        id.setOrgId(orgId);
        return partyDetails;
    }

    private OrganisationIdentification generateOrgIdDetails() {
        OrganisationIdentification orgId = new OrganisationIdentification();
        OtherIssuerDetails otherIssuerDetails = generateIssuerDetails();
        orgId.getOthr().add(otherIssuerDetails);
        return orgId;
    }

private OtherIssuerDetails generateIssuerDetails() {
        OtherIssuerDetails otherIssuerDetails =
                new OtherIssuerDetails();
        otherIssuerDetails.setIssr(DEFAULT_VALUE);
        return otherIssuerDetails;
    }    
}

sql – How can data studio read a repeatable column as values of a single record?

I’m moving a Mongo collection into BigQuery to do analysis and visualizations in Google Data Studio. I’m specifically trying to map all results of a locations collection, which has multiple records, one for each location. Each record stores the lat long as an array of 2 numbers.

In Data Studio, when i try to map the locations.coordinates value, it croaks, because it only pulls in the first value of the array. If instead of mapping it, I output the result as a table, I see 2 rows for each record, with the _id being the same and locations.coordinates being different between a row that has the latitude (locations.coordinates(0)) and another row for the longitude (locations.coordinates(1)).

I think I have to do this as a scheduled query in bigquery, that runs after every sync of data. But, I’m hoping there is a way to do this as a calculated field or a blended data set, in Google Data Studio.

Data as it exists in mongo

Data as it exists in bigquery

Data as it exists in data studio

unity – Having multiple different friction values on a single piece of track?

I am trying to figure out a good/performant way to give a piece of track multiple values of dynamic friction. A track piece is 10×10 units in Unity and the idea is to puzzle them together to a big track like the tracks in Trackmania. The game itself features no acceleration, except from gravity. To make things more interesting I want to give each track piece at the start of the scene multiple random friction values within a given range.

Currently I achieve this by making each piece of track consisting of 100 little tiles which are 1×1 units and they get a random friction values assigned. This approach works somewhat fine as long as there are less than 30 to 40 track pieces(3000-4000 tiles) but with more than that the fps are dropping really low. As it is a racing type of game I had to set the “Fixed Timestep” in the project settings to 0.001 to get accurate time measurments and this is hurting the performance as well. With a lower timestep the collision detection with all the little tiles is really bad too.

Is there a more elegant and/or performant way to achieve this in within the unity physics system?