Agnes  Sauer

Agnes Sauer

1595745540

Laziness to the Rescue

“Laziness isn’t that bad….”

In the previous pose(link below), I highlighted how functional programming simplifies the abstract idea of exploring graphs. I demonstrated one of the salient features of Haskell (a FP language) that unburdens us from explicitly managing states while gradually discovering paths between nodes.

A holistic perspective into exploring graphs using functional programming

Before we start, let me ask you a question — when you encounter a complex problem, isn’t it tempting to start with…

medium.com

Here, I want to take this concept of “laziness” a bit further. Lazy evaluation or laziness as it is colloquially known is delayed evaluation of an expression until we really require its result. It’s like making a promise, fulfilling it only at the nick of time. It lets us define infinite data structures without explicit allocating memory to create and store them. Imagine you are given an infinite steam of large integers **I ( I :: Integer). **For some arcane reason, you want to sort them as they come in. How will you accomplish this? If you’re familiar with traditional sorting algorithms like QuickSort, Merge sort, you will jump and say use them. STOP! Both require data to be in memory. Your stream can look like this : 13,1,2,4,1,9,0,8,11,4,5,3,66,77,112,1091,99,11,2,3,4,5,6…

The only information you have is the bounds of this array, i.e., the lowest value and the highest one. A useful strategy in such a scenario is not to think about any comparison based sorting algorithms — they all have lower bound of Ω(n lg n) (note: unlike Big O, the Big Omega Ω denotes that our function is bounded below). Instead, if we could just ‘tag’ integers as they come by their respective keys which are just integers between lower and upper bound, we would be able to ‘almost’ solve this problem. It’s similar to counting the number of occurrences of each integer in incoming stream, tagging them as they come and accumulating the count of each element. Finally, in the last step we could just exapnd the respective count of each element in the stream to get the sorted array. Data.Array module in Haskell has accumArray function which takes a binary function, initial accumulator, and array to perform the above task.

accumArray :: Ix i = > (e → a → e) → e → (i, i) →[(i, a)] → Array i e

Here, Ix is the class of all **index **types(those that can be used as indices in arrays) — there must be a mapping of a value of type _a _to an offset in a linear array. (e → a →e) denotes the accumulating function, which in our case is simply (+) :: Num l=> l→ l→ l. It’s followed by initial entry at each index with type e (an Integer). (i,i) are bounds of the array. They must be indexable, i.e., have total order property. Finally, as the last argument, we have list of type [(i,a)], an association list of [(1, element1), (1, element2)…]. This is accomplished by zipping our list with 1’s — zip arr $ iterate id 1

accumArray f e (l,u) list creates an array with indices l…u, in time proportional to u-l, provided f can be computed in constant time. The result is an array whose size is determined by bounds, and whose values are denoted by separating all the values in the list according to their index, and then performing a left-fold operation, using f, on each collection, starting with the value e. You might be thinking that this can be readily used for creating a histogram or performing sorting using bins; well, you’re right.

#haskell #function

What is GEEK

Buddha Community

Laziness to the Rescue
Art  Lind

Art Lind

1601604000

How to enable SSH access and configure network in rescue mode

01/ Enable and Configure network in rescue mode

01- Show available network devices:

sh-4.2## ip link

1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno16777984:  mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
    link/ether 00:50:56:a3:5d:a3 brd ff:ff:ff:ff:ff:ff

02- Set the required network device UP:

sh-4.2## ip link set dev eno16777984 up

– Now use the below command to check the state of the device:

sh-4.2## ip link
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno16777984:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 00:50:56:a3:5d:a3 brd ff:ff:ff:ff:ff:ff

#linux #rescue mode centos #rescue mode enable ssh #rescue mode ssh

Andrew Rhodes

Andrew Rhodes

1578928162

A Super Simple Vue Image Lazy Loader for Vue

cube-vue-image-lazy

A super simple Vue image lazy loader for Vue.

Install

yarn add cube-vue-image-lazy

Warning: You’ll need to install the w3c Intersection Observer polyfill in case you’re targeting a browser which doesn’t support it.

Usage

You can register the component globally so it’s available in all your apps:

import Vue from 'vue'
import ImageLazy from 'cube-vue-image-lazy'

Vue.use(ImageLazy)

// Or you can override defaults
Vue.use(ImageLazy, {
  name: 'ImageLazyLoad',
  delay: 500,
  baseClass: 'image-lazy-load',
  deferredClass: 'image-lazy-load-deferred',
  loadingClass: 'image-lazy-load-loading',
  loadedClass: 'image-lazy-load-loaded'
})

Or use it locally in any of your components:

<template>
  <div id="App">
    <ImageLazy
      class="photo"
      src="https://source.unsplash.com/random/200x200"
      srcset="https://source.unsplash.com/random/400x400 2x"
      baseClass="image-lazy"
      deferredClass="image-lazy-deferred"
      loadingClass="image-lazy-loading"
      loadedClass="image-lazy-loaded"
      :delay="500"
      @loading="loading = true"
      @load="loaded = true"
    />
  </div>
</template>

<script>
import ImageLazy from 'cube-vue-image-lazy'

export default {
  components: {
    ImageLazy
  },
  data () {
    return {
      loading: false,
      loaded: false
    }
  }
}
</script>

<style>
.image-lazy {
  opacity: 0;
}
.image-lazy-loading {
  transform: translateX(100vh);
}
.image-lazy-loaded {
  transition: opacity 1s ease;
  opacity: 1;
}
</style>

Props

Name Required Type Default Description
delay false Number 0 The delay before loading the image when it appears in the viewport.
baseClass false String ‘image-lazy’ The name of the class always added to the image.
deferredClass false String ‘image-lazy-deferred’ The name of the class added while the loading of the image is deferred.
loadingClass false String ‘image-lazy-loading’ The name of the class added while the image is loading.
loadedClass false String ‘image-lazy-loaded’ The name of the class added when the image is loaded.

Events

Name Description
loading The image is loading.
load The image is loaded.

Development Setup

# Project setup
yarn install

# Compiles and hot-reloads for development – Run the demo
yarn serve

# Compiles and minifies for production
yarn build

# Builds the npm ready packages
yarn bundle

# Watches for file changes and builds the npm ready packages accordingly
yarn watch

# Lints and fixes files
yarn lint

# Run the unit tests
yarn test:unit

Demo

Download

#lazy-loader #vue-image-loading #vue-js #image-lazy-loader

Spring Boot 2.2 Lazy initialization | Spring Eager Vs Lazy Loading

You will learn what is the difference between spring eager vs lazy loading and spring boot 2.2 lazy initialization

#spring boot #spring eager #lazy

Agnes  Sauer

Agnes Sauer

1595745540

Laziness to the Rescue

“Laziness isn’t that bad….”

In the previous pose(link below), I highlighted how functional programming simplifies the abstract idea of exploring graphs. I demonstrated one of the salient features of Haskell (a FP language) that unburdens us from explicitly managing states while gradually discovering paths between nodes.

A holistic perspective into exploring graphs using functional programming

Before we start, let me ask you a question — when you encounter a complex problem, isn’t it tempting to start with…

medium.com

Here, I want to take this concept of “laziness” a bit further. Lazy evaluation or laziness as it is colloquially known is delayed evaluation of an expression until we really require its result. It’s like making a promise, fulfilling it only at the nick of time. It lets us define infinite data structures without explicit allocating memory to create and store them. Imagine you are given an infinite steam of large integers **I ( I :: Integer). **For some arcane reason, you want to sort them as they come in. How will you accomplish this? If you’re familiar with traditional sorting algorithms like QuickSort, Merge sort, you will jump and say use them. STOP! Both require data to be in memory. Your stream can look like this : 13,1,2,4,1,9,0,8,11,4,5,3,66,77,112,1091,99,11,2,3,4,5,6…

The only information you have is the bounds of this array, i.e., the lowest value and the highest one. A useful strategy in such a scenario is not to think about any comparison based sorting algorithms — they all have lower bound of Ω(n lg n) (note: unlike Big O, the Big Omega Ω denotes that our function is bounded below). Instead, if we could just ‘tag’ integers as they come by their respective keys which are just integers between lower and upper bound, we would be able to ‘almost’ solve this problem. It’s similar to counting the number of occurrences of each integer in incoming stream, tagging them as they come and accumulating the count of each element. Finally, in the last step we could just exapnd the respective count of each element in the stream to get the sorted array. Data.Array module in Haskell has accumArray function which takes a binary function, initial accumulator, and array to perform the above task.

accumArray :: Ix i = > (e → a → e) → e → (i, i) →[(i, a)] → Array i e

Here, Ix is the class of all **index **types(those that can be used as indices in arrays) — there must be a mapping of a value of type _a _to an offset in a linear array. (e → a →e) denotes the accumulating function, which in our case is simply (+) :: Num l=> l→ l→ l. It’s followed by initial entry at each index with type e (an Integer). (i,i) are bounds of the array. They must be indexable, i.e., have total order property. Finally, as the last argument, we have list of type [(i,a)], an association list of [(1, element1), (1, element2)…]. This is accomplished by zipping our list with 1’s — zip arr $ iterate id 1

accumArray f e (l,u) list creates an array with indices l…u, in time proportional to u-l, provided f can be computed in constant time. The result is an array whose size is determined by bounds, and whose values are denoted by separating all the values in the list according to their index, and then performing a left-fold operation, using f, on each collection, starting with the value e. You might be thinking that this can be readily used for creating a histogram or performing sorting using bins; well, you’re right.

#haskell #function