Very Slow Ubuntu 20.04 On Samsung Solid State Drive

I am trying to get Ubuntu 20.04 to run on my external Samsung SSD 860 on my Macbook Pro 2012. I am able to use Refind boot loader to go into the Ubuntu Linux filesystem but everything is extremely slow. Please see the output of sudo fdisk -lu | pastebinit here: https://paste.ubuntu.com/p/xssVHcZTBB/. All I did was used the default installation of Ubuntu on my SSD and I wiped my regular hard-drive that had Mac installed (I plan to mount that for extra storage). The only thing remaining from the Mac side of things is the default EFI boot loader that shows up when pressing the option key. Thank you!

c++ – Simple Boolean “Latch” with state

Sometimes you need to do things when a condition changes, here is a simple class to keep track of the state of the last call and execute callbacks when the state changes.


#include <functional>
#include <cassert>


/// latch is a class that contains of a test function and a couple of callbacks, when the return
/// value of the test function changes the approrpiate callback gets called, as long as the return
/// value of the test function stays the same no callbacks will be called. Callbacks may be nullptr
template<class...Args>
class Latch {
public:
    Latch(std::function<bool(Args ...)> shouldLatch, std::function<void(Args...)> onLatch = nullptr, std::function<void(Args...)> onUnlatch = nullptr) :
                m_shouldLatch(std::move(shouldLatch)),
                m_onLatch(std::move(onLatch)),
                m_onUnlatch(std::move(onUnlatch)) {}

    bool latched() const noexcept { return m_isLatched; }
    
    explicit operator bool() const noexcept { return m_isLatched; }

    void update(Args&& ... args)
    {
        if (m_shouldLatch && m_isLatched != m_shouldLatch(std::forward<Args>(args)... ))
        {
            m_isLatched = !m_isLatched;
            auto& call = (m_isLatched) ?  m_onLatch : m_onUnlatch;
            if (call) call(std::forward<Args>(args)...);
        }
    }


private:
    bool m_isLatched = false;
    std::function<bool(Args ...)> m_shouldLatch;
    std::function<void(Args ...)> m_onLatch;
    std::function<void(Args ...)> m_onUnlatch;
};

int main() 
{
    int onLatch = 0;
    int onUnlatch = 0;
    int latchVal = 1;


    Latch<int> l1((&latchVal)(auto val){return val == latchVal;},
                  (&onLatch)(auto val){++onLatch;},
                  (&onUnlatch)(auto val){++onUnlatch;});
    assert(!l1);
    l1.update(0);
    assert(!l1);
    assert(onLatch == 0 && onUnlatch == 0);
    l1.update(1);
    assert(l1.latched());   
    assert(onLatch == 1 && onUnlatch == 0);
    l1.update(1);
    assert(onLatch == 1 && onUnlatch == 0);
    l1.update(0);
    assert(onLatch == 1 && onUnlatch == 1);

    Latch l2 = l1;
}

This is also at https://www.godbolt.org/z/z4b934

Thanks for the input

javascript – Is it an antipattern to pass an object that stores the application state from one function to another?

The program is written in JavaScript. To give you a rough idea what I am thinking of:

function State() {
  return {
    color: 'green',
    size: 100,

    // ... there are other properties here
  }
}

function init() {
  const state = State()
  const otherObj = OtherObj()
  
  // ...something like an event fires `foo`
  foo(state, otherObj)
}

function foo(state, otherObj) {
  state.size = calcNewSize(state) // state changes
  state.color = pickNewColor(state, otherObj) // state changes
  // ...   
}

function pickNewColor(state, otherObj) {
  const someInformation = getSomeInformation(state)

  // ... do other stuff

  return newColor
}

const a1 = init()
const a2 = init()
const a3 = init()

Right now, I have 3 objects that I should pass from function to function, but I am wondering, if this would scale well.

I am also wondering, if is better to pass the entire object, instead of only the properties that are needed by these functions. Maybe it would be a good idea, to draw a line at 2-3 arguments, and if more is necessary, then pass the entire object.

Also, this could possibly be refactored into a single class, with methods (like pickNewColor, getSomeInformation) having access to the properties (like size, color), in which case there wouldn’t be any need to pass around objects. However, I was wondering, if the above approach of passing around objects could work well.

react native – Managing redux state of mutiple switch components

I have a react native native app and I am fetching the state of the toggle buttons from an API and then putting them into redux state. I do not like the way I have implemented it cause it seems very messy and was wondering if anyone would have any suggestions on how to refactor the code.

Below is screen that calls my redux state for each toggle switch.

const SiteSettingsDashboard = (props) => {
  const dispatch = useDispatch();

  const alarmNotificationsToggle = useSelector(
    (state) => state.registration.alarmNotifications
  );
  const armingNotificationToggle = useSelector(
    (state) => state.registration.armingNotifications
  );

  const faultsNotificationToggle = useSelector(
    (state) => state.registration.faultsNotifications
  );

  const engineerNotificationToggle = useSelector(
    (state) => state.registration.engineerNotifications
  );

  const techZoneNotificationToggle = useSelector(
    (state) => state.registration.techZoneNotifications
  );

  const eventTimerNotificationToggle = useSelector(
    (state) => state.registration.eventTimerNotifications
  );

  const noCommsNotificationToggle = useSelector(
    (state) => state.registration.noCommsNotifications
  );

  const ToggleSwitchInput = (value) => {
    dispatch(registrationActions.toggleNotificationInput(value));
  };

  return (
    <View>
        <View style={{ flexDirection: "row" }}>
          <Text>{IMLocalized("Arming")}</Text>
          <Switch
            style={styles.right}
            trackColor={{ false: "#FF0000", true: "#008000" }}
            thumbColor={armingNotificationToggle ? "#008000" : "#FF0000"}
            ios_backgroundColor="#3e3e3e"
            onValueChange={() => ToggleSwitchInput("arming")}
            value={armingNotificationToggle}
          />
        </View>
        <Card.Divider />
        <View style={{ flexDirection: "row" }}>
          <Text>{IMLocalized("Faults")}</Text>
          <Switch
            style={styles.right}
            trackColor={{ false: "#FF0000", true: "#008000" }}
            thumbColor={faultsNotificationToggle ? "#008000" : "#FF0000"}
            ios_backgroundColor="#3e3e3e"
            onValueChange={() => ToggleSwitchInput("faults")}
            value={faultsNotificationToggle}
          />
        </View>
        <Card.Divider />
        <View style={{ flexDirection: "row" }}>
          <Text>{IMLocalized("Engineer")}</Text>
          <Switch
            style={styles.right}
            trackColor={{ false: "#FF0000", true: "#008000" }}
            thumbColor={engineerNotificationToggle ? "#008000" : "#FF0000"}
            ios_backgroundColor="#3e3e3e"
            onValueChange={() => ToggleSwitchInput("engineer")}
            value={engineerNotificationToggle}
          />
        </View>
        <Card.Divider />
        <View style={{ flexDirection: "row" }}>
          <Text>{IMLocalized("TechZone")}</Text>
          <Switch
            style={styles.right}
            trackColor={{ false: "#FF0000", true: "#008000" }}
            thumbColor={techZoneNotificationToggle ? "#008000" : "#FF0000"}
            ios_backgroundColor="#3e3e3e"
            onValueChange={() => ToggleSwitchInput("techZone")}
            value={techZoneNotificationToggle}
          />
        </View>
        <Card.Divider />
        <View style={{ flexDirection: "row" }}>
          <Text>{IMLocalized("EventTimers")}</Text>
          <Switch
            style={styles.right}
            trackColor={{ false: "#FF0000", true: "#008000" }}
            thumbColor={eventTimerNotificationToggle ? "#008000" : "#FF0000"}
            ios_backgroundColor="#3e3e3e"
            onValueChange={() => ToggleSwitchInput("eventTimer")}
            value={eventTimerNotificationToggle}
          />
        </View>
        <Card.Divider />
        <View style={{ flexDirection: "row" }}>
          <Text>{IMLocalized("NoComms")}</Text>
          <Switch
            style={styles.right}
            trackColor={{ false: "#FF0000", true: "#008000" }}
            thumbColor={noCommsNotificationToggle ? "#008000" : "#FF0000"}
            ios_backgroundColor="#3e3e3e"
            onValueChange={() => ToggleSwitchInput("noComms")}
            value={noCommsNotificationToggle}
          />
        </View>
        <Card.Divider />
      </Card>
    </View>
  );
};

const styles = StyleSheet.create({
  errorText: {
    color: "red",
  },
  right: {
    flex: 1,
  },
});

export default SiteSettingsDashboard; 

I have the state of each of the buttons declared in redux and this does not change.

export const types = Object.freeze({
  ToggleAlarmNotification: "TOGGLE_ALARM_NOTIFICATION",
  ToggleArmingNotification: "TOGGLE_ARMING_NOTIFICATION",
  ToggleFaultsNotification: "TOGGLE_FAULTS_NOTIFICATION",
  ToggleEngineerNotification: "TOGGLE_Engineer_NOTIFICATION",
  ToggleTechZoneNotification: "TOGGLE_TECH_ZONE_NOTIFICATION",
  ToggleEventTimerNotification: "TOGGLE_EVENT_TIMER_NOTIFICATION",
  ToggleNoCommsNotification: "TOGGLE_NO_COMMS_NOTIFICATION",
});


const initialState = {
  isRequestingLogoImage: false,
  alarmNotifications: false,
  armingNotifications: false,
  faultsNotifications: false,
  engineerNotifications: false,
  techZoneNotifications: false,
  eventTimerNotifications: false,
  noCommsNotifications: false,
};

And here is my reducer file. I do this for all of the toggle buttons.

case types.ToggleNoCommsNotification:
      return {
        ...state,
        noCommsNotifications: !state.noCommsNotifications,
      };

How does one prove one’s residency to a given US state when flying to Costa Rica?

I read on :

https://www.iatatravelcentre.com/world.php (-> Costa Rica):

Costa Rica. > Published 15.10.2020.

  1. Passengers are not allowed to enter.
  • This does not apply to:

    (…)

  • residents of the following states of the United States: Arizona, California, Colorado, Connecticut, Florida, Georgia, Maine, Maryland,
    Massachusetts, Michigan, New Hampshire, New Jersey, New Mexico, New
    York, Ohio, Oregon, Pennsylvania, Rhode Island, Texas, Vermont,
    Virginia, Washington, Washington D.C. and Wyoming;

How does one prove one’s residency to a given US state when flying to Costa Rica?

8 – How State is specific to the specific environment, when its actually pushed to all environments with DB sync?

When you copy your development/testing database to your production
database, you’re effectively replacing your production site’s state
with your development site’s state. Therefore if you put your
production site in maintenance mode, then import a database that says
the site is not in maintenance mode, then your site will stop being in
maintenance mode.

Conceptually, state is specific to an environment, so long as you
aren’t copying your database when you push changes from development to
production.

Your solution may be to avoid doing these database imports altogether.
If you are just making configuration changes on your local development
site and just need to push those, you can export the site’s
configuration to code, commit it to version control, push that config
to production and then import it. (See
https://www.drupal.org/docs/configuration-management for info.)

If you are creating content in the local development environment that
you need to push to production, then you may want to look at using the
Migrate API.

If you absolutely must push these database updates but want the
production site to remain in maintenance mode when you do it, then
you’ll need to put your development site into maintenance mode before
copying its database to production.

rest – HTTPSession for session state in web APIs?

When people talk about a “stateless API”, they don’t mean that requests can’t have any effect on the state of the server – the “S” in “REST” stands for “state”, after all – but that the meaning of a request doesn’t change based on state. This is achieved by making each stateful object an explicit part of the API.

So, a stateful API might have a verb “add item to my shopping basket”, with a meaning entirely dependent on matching the request to a previous “create basket” request. In a stateless API, you might instead say “add item to basket 42”, with the identifier “42” having been remembered by the client from the “create basket” response.

REST takes this further, and says that the objects should be the central concept, rather than actions with side-effects on those objects. So GET /basket/42 might return the current contents of that basket, POST /basket/42/items might add a product to it, and DELETE /basket/42/items/13 remove a product.

The reason this is useful is that it gives the client more flexibility in how to use the API, and the API more flexibility in the features it offers. For instance, a client might want to maintain two separate baskets, but based on one set of search results; or the API might offer the ability to clone a basket, or merge two baskets to pay for them at once.

So rather than moving further towards using a transparent “session” handled by the server software, I suggest you start thinking about what stateful objects each service’s session identifier represents.

Even if you don’t redesign the services to make those objects explicit, you can reframe your architectural decisions:

  • What is the appropriate lifetime for this object?
  • How often is this object read vs written?
  • What would be the consequences if this object was lost due to a server failure?
  • Do you need central observability of this object?

All of these need asking anyway if you use HTTPSession, since you need to configure where it stores its data, how long it stores it for, and so on. The main thing that would automate is the least relevant for an API: how to make a stateless web browser act like a stateful client without custom client code.

reactjs – What am I doing wrong lifting up the state from my AdressBar component to my MapContainer?

I create and bind a methond (reCenter) in the parent class and then I pass down this method (reCenter) from the parent to the child as a prop (onCenterChange). When I call the method in the child class by calling onCenterChange when the onSelect triggers it, nothing happens though.
Maybe it’s impossible to have a local state in the child class as well as props passed down from the parent class?
Am I missing something like a “bind” that prevents the method from being executed? I

export class MapContainer extends Component {
  constructor() {
    super();
    this.state = {
      customZoom: 2,
      },
    };
    this.customZoomIn = this.customZoomIn.bind(this);
    this.customZoomOut = this.customZoomOut.bind(this);
    this.reCenter = this.reCenter.bind(this)
  }

  // function that re-centers based on user input
  reCenter() {
    this.setState({newCenter: 10});
  }

  render() {
    return (
      <Fragment>
        <Map
          google={this.props.google}
          zoom={this.state.customZoom}
          style={mapStyles}
          disableDefaultUI={true}
          initialCenter={{
            lat: 47.376888,
            lng: 8.541694,
          }}
        />
        <nav className="backButton">
          <ul className="backButtonUL">
            <Link to="/">
              <li className="backButtonLI">Home</li>
            </Link>
          </ul>
        </nav>

        <AddressSearch onCenterChange={this.reCenter} />```



class AddressSearch extends Component {
  constructor(props) {
    super(props);
    this.state = { address: "" };
  }

  handleChange = (address) => {
    this.setState({ address });
  };

  handleSelect = (address) => {
    geocodeByAddress(address)
      .then((results) => getLatLng(results(0)))
      .then((latLng) => console.log("Success", latLng))
      .catch((error) => console.error("Error", error));
  };

  render() {
    console.log("hello", this.props.newCenter);
    return (
      <PlacesAutocomplete
        value={this.state.address}
        onChange={this.handleChange}
        onSelect={this.props.onCenterChange}
        highlightFirstSuggestion={true}