Returns the n minimum elements from the provided list.
If n is greater than or equal to the provided list’s length, then return the original list (sorted in ascending order).

Use sorted() to sort the list,[:n]to get the specified number of elements. Omit the second argument,n`, to get a one-element list.

继续阅读 30秒学会 Python 片段 – min_n

Displays a hamburger menu which transitions to a cross on hover.

  • Use a .hamburger-menu container div which contains the top, bottom, and middle bars.
  • The container is set to be a flex container (display: flex) with flex-direction to be column and flex-wrap to be wrap (alternatively, you can set both properties by a shorthand flex-flow: column wrap).
  • Add distance between the bars using justify-content: space-between.
  • The animation has 3 parts: top and bottom bars transforming to 45 degree angles (rotate(45deg)), and the middle bar fading away by setting opacity: 0.
  • The transform-origin is set to left so the bars rotate around the left point.
  • Set transition all 0.5s so that both transform and opacity properties are animated for half a second.

继续阅读 30秒学会 CSS 片段 – Hamburger Button

Returns the highest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function.

Check if the array is sorted in descending order (loosely).
Use to apply the iterator function to all elements of the array.
Use Array.prototype.reverse() and Array.prototype.findIndex() to find the appropriate last index where the element should be inserted, based on the provided iterator function.

继续阅读 30秒学会 JavaScript 片段 – sortedLastIndexBy

Mutates the original array to filter out the values specified. Returns the removed elements.

Use Array.prototype.filter() and Array.prototype.includes() to pull out the values that are not needed.
Use Array.prototype.length = 0 to mutate the passed in an array by resetting it’s length to zero and Array.prototype.push() to re-populate it with only the pulled values.
Use Array.prototype.push() to keep track of pulled values

继续阅读 30秒学会 JavaScript 片段 – pullAtValue

Creates a collection of elements, grouped based on the position in the original collections.

Use range to iterate over the params, reflect.ValueOf() and Value.Len() to find the longest collection.
Use make() to create a 2D interface{} slice of length equal to the longest collection.
Use make() to create a slice for each element in the result, range to iterate over params.
Use reflect.ValueOf(), Value.Len(), append(), Value.Index() and Value.Interface() to add values to the result.

继续阅读 30秒学会 Golang 片段 – Zip

Given a predicate function and a prop string, this curried function will then take an object to inspect by calling the property and passing it to the predicate.

Summon prop on obj, pass it to a provided predicate function and return a masked boolean.

继续阅读 30秒学会 JavaScript 片段 – checkProp

A hover effect where the gradient follows the mouse cursor.

  • --x and --y are used to track the position of the mouse on the button.
  • --size is used to keep modify of the gradient’s dimensions.
  • background: radial-gradient(circle closest-side, pink, transparent); creates the gradient at the correct postion.

继续阅读 30秒学会 CSS 片段 – Mouse cursor gradient tracking