[-] [email protected] 4 points 5 months ago

you can become an artist! pick up a pencil/pen and a piece of paper, start drawing! it'll suck at first, but it'll get better with time. look up some tutorials, ask a friend to teach you or pay for a in-person tutor if you have someone like that near you. you've got this!

[-] [email protected] 3 points 5 months ago

why would you wanna kill the programming language commitees.

[-] [email protected] 4 points 7 months ago

i'm fine with any donation notifications, even on by default, if they can be disabled.

[-] [email protected] 2 points 9 months ago

i've switched to linux this year and kde's been a breeze to use! happy birthday and thanks for all the wonderful work!!

1
submitted 2 years ago by [email protected] to c/[email protected]

i made a type-safe GroupBy function.

/**
 * Groups array of objects by a given key
 * @param arr array of objects to group
 * @param key must be present on every object, and it's values must be string|number
 * @author telepresence
 * @license CC-BY-4.0
 */
function groupBy(arr: T[], key: keyof T, defaultAcc: Record = {}) {
    return arr.reduce((acc, val, i) => {
        const compValue = val[key];
        if (typeof compValue !== 'string' && typeof compValue !== 'number') {
            throw new Error(`key ${key.toString()} has values other than string/number. can only group by string/number values`);
        }
        if (!acc[compValue]) acc[compValue] = []
        acc[compValue].push(val);
        return acc;
    }, defaultAcc);
}
  • like lodash's groupBy, but by key and not function
    • group an array of objects which all have a key in common into an object with keys matching all the different possible values of your common key
  • type-safe, no unknown's no any's
  • does not copy arrays ([...array]), uses push
  • supports selecting by keys, where the key values are string / number (although you can easily add symbol support)
  • shared for free under the CC BY 4.0 license - only attribution is requred (link to this post is fine)
  • custom default accumulator support, if you already know the groups beforehand and would rather have an empty array than undefined.

example:

const data = [{
  "name": "jim",
  "color": "blue",
  "age": "22"
}, {
  "name": "Sam",
  "color": "blue",
  "age": "33"
}, {
  "name": "eddie",
  "color": "green",
  "age": "77"
}];

groupBy(data, 'color') 

would result into:

{
  "blue": [
    {
      "name": "jim",
      "color": "blue",
      "age": "22"
    },
    {
      "name": "Sam",
      "color": "blue",
      "age": "33"
    }
  ],
  "green": [
    {
      "name": "eddie",
      "color": "green",
      "age": "77"
    }
  ]
} 

TL;DR i've sucessfully wrote something using generics in typescript for the first time, and i think it's pretty epic.

[-] [email protected] 1 points 2 years ago

from the error it looks like you're importing an es module inside a common.js environment. but as @[email protected] said, there are several things that could cause this.

[-] [email protected] 8 points 2 years ago

these two tools apparently let you rip borrowed audiobooks from this service named libby. although i haven't tested them. https://github.com/ping/odmpy https://github.com/bookbonobo/libby-download-extension

also, have you checked the index? stuff like this is usually there.

[-] [email protected] 12 points 2 years ago

Check out some alternatives:
searXNG - open source & self-hosted meta-search engine (aggregates results from many others, like google, bing, qwant, duckduckgo - configurable which ones.) list of public instances just pick one that's close to you physically and has a good uptime.
duckduckgo - uses bing for most search results, but is way more private
brave search - uses their own index, has a privacy-respecting privacy policy and the results are pretty damn good

2
submitted 2 years ago* (last edited 2 years ago) by [email protected] to c/[email protected]

Banger i found randomly when checking the twitter of one of my favorite artists, @xyanaid. They made the album cover.

edit: Spotify link

telepresence

0 post score
0 comment score
joined 2 years ago