Replace individual list elements in Haskell?

Typically, you modify elements of a list by splitting the list, replacing an element, and joining it back together. To split a list at an index, we have: splitAt :: Int -> [a] -> ([a], [a]) which you can use to break up a list, like so: > splitAt 2 [“Off”,”Off”,”Off”,”Off”] ([“Off”,”Off”],[“Off”,”Off”]) now you just … Read more

Detecting outgoing call and call hangup event in android

You should create a BroadcastReceiver: public class CallReciever extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals( TelephonyManager.EXTRA_STATE_RINGING)) { // Phone number String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); // Ringing state // This code will execute when the phone has an incoming call } else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals( TelephonyManager.EXTRA_STATE_IDLE) || intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals( TelephonyManager.EXTRA_STATE_OFFHOOK)) { // … Read more

Accessing parent state in child in React

The proper way of doing this would be by passing state as props to Docs component. However, because you are using React Router it can be accessed in a bit different way: this.props.route.param instead of default this.props.param So your code should look more or less like this: <Route path=”/docs” component={Docs} docs={this.state.docs} /> and {this.props.route.docs.map(function(study, key) … Read more

Vagrant up error in headless Ubuntu: The guest machine entered an invalid state while waiting for it to boot

According to mitchellh Can you start the machine manually (from the GUI)? This error message is usually indicative of VirtualBox issues. my solution I use vagrant under windows though, I solved this problem by simply kill all the VirtualBox process, and restart VirtualBox GUI, start the VM, then normally power off it. maybe useful links … Read more

Get the html of the javascript-rendered page (after interacting with it)

In Chrome (and apparently Firefox), there is a special copy() method that will copy the rendered content to the clipboard. Then you can do whatever you want by pasting it to your preferred text editor. https://developers.google.com/chrome-developer-tools/docs/commandline-api#copyobject Console Example: copy(document.body.innerHTML); Note: I noticed Chrome reports undefined after the method is run, however, it seems to execute … Read more

is useMemo required to manage state via the context API in reactjs?

There is a very simple theory to why you should use useMemo to memoize the values passed to the Context Provider. When you pass the value to Context Provider, either as an object or an array like: return <CountContext.Provider value={{state, setCount}} {…props} /> or return <CountContext.Provider value={[state, setCount]} {…props} /> What essentially happens is that … Read more

Android save state on orientation change

Add android:configChanges in the Manifest file <activity name= “.MainActivity” android:configChanges=”orientation|screenSize”/> By default, this does not work because changing the orientation causes the onCreate method to be called again and redraws the view. However, if this parameter is included, the framework will handle preserving the state of the screen or layout if the orientation is changed. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)