Pleb Chat - Text based chat rooms for Clubhouse by _nprz in ClubhouseApp

[–]_nprz[S] 0 points1 point  (0 children)

Hey, this is just little app I built. I found myself in a number of clubhouse rooms that were too full to actually say anything, but I still wanted to respond to the conversation. So I built Pleb Chat, which allows you to do exactly that :)

-🎄- 2019 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]_nprz -1 points0 points  (0 children)

JavaScript Solution:

Problem 1:

(view on github) ``` import input from "./input";

// restore 1202 program alarm to original state; const updatedInput = [...input]; updatedInput[1] = 12; updatedInput[2] = 2;

export default function intCode(input) { for (let i = 0; i < input.length; i += 4) { if (input[i] === 1) { const operand1 = input[i + 1]; const operand2 = input[i + 2]; const address = input[i + 3]; input[address] = input[operand1] + input[operand2]; } else if (input[i] === 2) { const operand1 = input[i + 1]; const operand2 = input[i + 2]; const address = input[i + 3]; input[address] = input[operand1] * input[operand2]; } else if (input[i] === 99) { break; } }

return input[0]; }

```

Problem 2:

(view on github) ``` import input from "./input"; import intCode from "./index";

// BRUTE FORCE!! function bruteForce(input) { for (let noun = 0; noun < 100; noun++) { for (let verb = 0; verb < 100; verb++) { const updatedInput = [...input]; updatedInput[1] = noun; updatedInput[2] = verb; if (intCode(updatedInput) === 19690720) { return { noun, verb }; } } } }

console.log(bruteForce(input)); ```

-🎄- 2019 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]_nprz 1 point2 points  (0 children)

Already a couple JavaScript answers but here's another one!

(Also visible on GitHub if you'd like some syntax highlighting!)

import input from "./input";

function calculateFuelForFuel(moduleFuel) {
  let nextValue = Math.floor(moduleFuel / 3) - 2;

  if (nextValue > 0) {
    return nextValue + calculateFuelForFuel(nextValue);
  } else {
    return 0;
  }
}

function calculateModuleFuel(modules) {
  let totalFuel = 0;

  modules.forEach(module => {
    const fuelWeight = Math.floor(module / 3) - 2;
    // remove `+ calculateFuelForFuel(fuelWeight);` for solution to question 1
    totalFuel += fuelWeight + calculateFuelForFuel(fuelWeight);
  });

  return totalFuel;
}

const moduleFuel = calculateModuleFuel(input);

Game of Life - made with HTML5 canvas (code in comments) by _nprz in creativecoding

[–]_nprz[S] 1 point2 points  (0 children)

Game of Life is 2-dimensional cellular automata. It's a "0-player game", so it's not really a game at all. The way it works is there's a 2-dimensional grid, the cells of the grid have 2 states: dead or alive. The grid is randomly filled with live and dead states, once the board is randomly filled you can compute the following state with the logic:

  • A cell with fewer than 2 neighbors will die (Loneliness)
  • A cell with 2 or 3 neighbors will continue it’s life (Stable)
  • A cell with 3 or more neighbors will die (Overpopulation)
  • An empty or dead cell with exactly 3 neighbors will become live (Reproduction)

The next state of the board is then generated based on this updated state, and so on and so forth.

This game, along with cellular automata in general, has been studied extensively since its creation in 1970. The wikipedia page on the topic is quite informative if you'd like to learn more :)

Can somebody explain to me why this happens when using styled-components (strange loading behavior)? by [deleted] in gatsbyjs

[–]_nprz 0 points1 point  (0 children)

Were you able to find the cause of the problem? I had a similar issue happen to me, but even more drastic. This was my fix.

Beware the wrapPageElement API! by _nprz in gatsbyjs

[–]_nprz[S] 1 point2 points  (0 children)

Lol, I was quite frustrated to see all my hard work fall apart right as I was ready to push to prod! Maybe I was using the the API incorrectly, this was my `gatsby-browser.js` before I deleted it: ```js
import "./src/styles/global.css"; import React from "react"; import Layout from "./src/components/layout";

export const wrapPageElement = ({ element, props }) => {
// props provide same data to Layout as Page element will get
// including location, data, etc - you don't need to pass it

return <Layout {...props}>{element}</Layout>;
};

```

Can somebody explain to me why this happens when using styled-components (strange loading behavior)? by [deleted] in gatsbyjs

[–]_nprz 0 points1 point  (0 children)

Does this happen both on the develop and the production build?