# Dank n Edgy

The dorkest, edgist forums known to puny hoomans

You are not logged in.

## Announcement

Welcome to DnE, the online psych facility. (Run by the inmates, for the inmates.)

## #376 2019-01-20 01:01:42

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

Pretty sure I have everything right but there's some floating point imprecision fuckup going on >:/

`````` // Take the janky ass CID thing and turn it into
// a fucking usable object >:|
function transformersRobotsInDisguise(cid){
let retObj = {};
for (let i = 0; i < cid.length; i++){
retObj[cid[i][0]] = cid[i][1];
}
return retObj;
}
function checkCashRegister(price, cash, cid) {
let cidRef = transformersRobotsInDisguise(cid);
let retObj = {};
let status = "";
let change = [];
let totalChangeDue = cash - price;
let totalCid = 0;
let countValues = [];
let cashValues = [100, 20, 10, 5, 1, .25, .10, .05, .01];
let names = ["ONE HUNDRED", "TWENTY", "TEN", "FIVE", "ONE", "QUARTER",
"DIME", "NICKEL", "PENNY"];
let counterObj = {
"ONE HUNDRED": 0, "TWENTY": 0, "TEN": 0,
"FIVE": 0, "ONE": 0, "QUARTER": 0,
"DIME": 0, "NICKEL": 0, "PENNY": 0
}
for (let i = 0; i < Object.keys(cid).length; i++){
totalCid += Object.values(cid)[i][1];
countValues.push(Object.values(cid)[i][1]);
}
countValues.reverse();
if (totalCid < totalChangeDue){
return {status: "INSUFFICIENT_FUNDS", change: []};
}
else if (totalCid == totalChangeDue){
return  {status: "CLOSED", change: cid};
}
let currChangeDue = totalChangeDue;
while(currChangeDue > 0){
for (let i = 0; i < cashValues.length; i++){
if ((cashValues[i] - currChangeDue) < 0){
if (cidRef[names[i]] > 0){
counterObj[names[i]] = counterObj[names[i]] + 1;
cidRef[names[i]] = cidRef[names[i]] - cashValues[i];
currChangeDue = currChangeDue - cashValues[i];
}
}
}
}
for (let i = 0; i < names.length; i++){
let store = counterObj[names[i]] * cashValues[i];
//console.log(JSON.stringify(counterObj));
if (store > 0){
let arr = [names[i], store];
change.push(arr);
}
}
retObj.status = "OPEN";
retObj.change = change;
return retObj;
}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]

//let obj = checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);

//let obj = checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

let obj = checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);// should return {status: "OPEN", change: [["QUARTER", 0.5]]};

console.log(JSON.stringify(obj));``````

REEEEEEEEEEEEEeeeeeeeeeeeeeeeeeeeeeeeeeeee

what the fuck is this

``````// Take the janky ass CID thing and turn it into
// a fucking usable object >:|
function transformersRobotsInDisguise(cid){
let retObj = {};
for (let i = 0; i < cid.length; i++){
retObj[cid[i][0]] = cid[i][1];
}
return retObj;
}
function checkCashRegister(price, cash, cid) {
let cidRef = transformersRobotsInDisguise(cid);
let retObj = {};
let status = "";
let change = [];
let totalChangeDue = cash - price;
let totalCid = 0;
let countValues = [];
let cashValues = [100, 20, 10, 5, 1, .25, .1, .05, .01];
let names = ["ONE HUNDRED", "TWENTY", "TEN", "FIVE", "ONE", "QUARTER",
"DIME", "NICKEL", "PENNY"];
let counterObj = {
"ONE HUNDRED": 0, "TWENTY": 0, "TEN": 0,
"FIVE": 0, "ONE": 0, "QUARTER": 0,
"DIME": 0, "NICKEL": 0, "PENNY": 0
}
for (let i = 0; i < Object.keys(cid).length; i++){
totalCid += Object.values(cid)[i][1];
countValues.push(Object.values(cid)[i][1]);
}
countValues.reverse();
if (totalCid < totalChangeDue){
return {status: "INSUFFICIENT_FUNDS", change: []};
}
else if (totalCid == totalChangeDue){
return  {status: "CLOSED", change: cid};
}
let currChangeDue = totalChangeDue;
while(currChangeDue > 0){
for (let i = 0; i < cashValues.length; i++){
// if bill amount - change due is negative
if ((cashValues[i] - currChangeDue) < 0){
// If we have enough of the given value in CID
if (cidRef[names[i]] > 0){
// increment number of a given bill / unit
counterObj[names[i]] = counterObj[names[i]] + 1;
let val = cidRef[names[i]] - cashValues[i];
cidRef[names[i]] = Math.round(val * 100) / 100;
let val2 = currChangeDue - cashValues[i];
currChangeDue = Math.round(val2 * 100) / 100;
console.log(currChangeDue);
}
}
}
}
for (let i = 0; i < names.length; i++){
let store = counterObj[names[i]] * cashValues[i];
//console.log(JSON.stringify(counterObj));
if (store > 0){
let arr = [names[i], store];
change.push(arr);
}
}
retObj.status = "OPEN";
retObj.change = change;
return retObj;
}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]

//let obj = checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);

//let obj = checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

let obj = checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);// should return {status: "OPEN", change: [["QUARTER", 0.5]]};

console.log(JSON.stringify(obj));``````

Fucc

Offline

## #377 2019-01-23 01:19:33

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

Fucking finally

`````` // Take the janky ass CID thing and turn it into
// a fucking usable object >:|
function transformersRobotsInDisguise(cid){
let retObj = {};
for (let i = 0; i < cid.length; i++){
retObj[cid[i][0]] = cid[i][1];
}
return retObj;
}
function checkCashRegister(price, cash, cid) {
let cidRef = transformersRobotsInDisguise(cid);
let retObj = {};
let status = "";
let change = [];
let totalChangeDue = cash - price;
let totalCid = 0;
let countValues = [];
let cashValues = [100, 20, 10, 5, 1, .25, .10, .05, .01];
let names = ["ONE HUNDRED", "TWENTY", "TEN", "FIVE", "ONE", "QUARTER",
"DIME", "NICKEL", "PENNY"];
let counterObj = {
"ONE HUNDRED": 0, "TWENTY": 0, "TEN": 0,
"FIVE": 0, "ONE": 0, "QUARTER": 0,
"DIME": 0, "NICKEL": 0, "PENNY": 0
}
for (let i = 0; i < Object.keys(cid).length; i++){
totalCid += (Object.values(cid)[i][1]);
countValues.push(Object.values(cid)[i][1]);
}
totalCid = Math.round(totalCid * 100) / 100;
countValues.reverse();

if (totalCid < totalChangeDue){
return {status: "INSUFFICIENT_FUNDS", change: []};
}
else if (totalCid == totalChangeDue){
return  {status: "CLOSED", change: cid};
}
let currChangeDue = totalChangeDue;
for (let i = 0; i < cashValues.length; i++){
while(cidRef[names[i]] > 0 && cashValues[i] <= currChangeDue){
counterObj[names[i]] += 1;
cidRef[names[i]] = Math.round((cidRef[names[i]] - cashValues[i]) * 100) / 100;
currChangeDue = Math.round((currChangeDue - cashValues[i]) * 100) / 100;
}
}
console.log(JSON.stringify(counterObj));
for (let i = 0; i < names.length; i++){
let store = counterObj[names[i]] * cashValues[i];
if (store > 0){
let arr = [names[i], store];
change.push(arr);
}
}

if (change[0][1] < currChangeDue){
return {status: "INSUFFICIENT_FUNDS", change: []};
};
retObj.status = "OPEN";
retObj.change = change;
return retObj;
}

//let obj = checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);

//let obj = checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

//let obj = checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);// should return {status: "OPEN", change: [["QUARTER", 0.5]]};

let obj = checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);

console.log(JSON.stringify(obj));``````

Although I kinda cheated for the last bit here:

if (change[0][1] < currChangeDue){
return {status: "INSUFFICIENT_FUNDS", change: []};
};

I'm so sick of this fucking challenge though so fuck it.

Fucc

Offline

## #378 2019-01-24 21:27:44

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

Blew through the entire bootstrap and jQuery sections of FCC in like a few hours.
I feel like I can't have even scratched the surface, which is concerning.

Bleh. I can certainly use them to build shit right now if I want but... Can it really be that easy?

Also blew through SCSS. Starting React now.

Fucc

Offline

## #379 2019-01-27 14:36:23

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

Just ordered a 8GB stick for my t420 boiii

can't wait, fuck this 4gb ass bullshit

Fucc

Offline

## #380 2019-01-27 14:41:57

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

It always strikes me that the basic terms in programming languages which are supposed to be super fundamental are actually very fuzzy and not well defined across languages. Things like inheritance, abstraction, basically any OOP principles... It's vague and differs from lang to lang which is annoying, and even in say Java, they have fuzzy definitions.

Fucc

Offline

## #381 2019-01-27 14:43:56

sloth
WITNESS ME
From: Spurdoland
Registered: 2012-06-17
Posts: 7,807

### Re: Absent's Code Thread / Tech Blog

That reminds me, I have to buy a laptop that is certified by Qubes. A cheap one, but with i7 and 8GB RAM?
Doesn't have to be a laptop. Small form factor would be good also?

Might start doing code analysis on your FCC code, it would be a good exercise. Btw, I hate java.

Hindsight is always 20/20.

God wrote:

A surprising amount of insight can be gleamed from sitting on the toilet. More concerning, however, is the amount of nostalgia.

When in doubt, move north. God bless suomi.

Offline

## #382 2019-01-27 15:12:24

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

So I guess the big difference between ES6 clsases and Java classes is that ES6 "classes" are objects themselves, and a class in java is an actual class that is nonfunctional, it's just the blueprint. You don't get class taxonomies in javascript like you do in java. A Javascript class is just an object itself with a constructor? (Which inherits from a "master" prototype object with some built in shit like toString, get, set, etc)

I guess it doesn't matter THAT much as you don't want to get too deep into class inheritance anyway, since it ends up breaking down at some point. Apparently object composition is better.

Fucc

Offline

## #383 2019-01-27 18:59:42

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

With 4GB of memory, an infinite loop in the browser is a 15 minute fucking setback >:/

Idk if it's bad handling of processes by firefox or windows, or both, but what in the fuck mang.

Fucc

Offline

## #384 2019-01-28 02:58:15

sloth
WITNESS ME
From: Spurdoland
Registered: 2012-06-17
Posts: 7,807

### Re: Absent's Code Thread / Tech Blog

absentinsomniac wrote:

With 4GB of memory, an infinite loop in the browser is a 15 minute fucking setback >:/

Idk if it's bad handling of processes by firefox or windows, or both, but what in the fuck mang.

KEK. Dude, it's 2019, get some more RAM.

Also the post before that described all that is wrong with programming: Too many different concepts doing things differently.

Hindsight is always 20/20.

God wrote:

A surprising amount of insight can be gleamed from sitting on the toilet. More concerning, however, is the amount of nostalgia.

When in doubt, move north. God bless suomi.

Offline

## #385 2019-01-31 21:00:01

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

Got me RAM. Glad I did, this is way faster. 4GB of RAM, 2x2GB, was ass. I could max it out with 8 more on the internal slot but I don't really need to rn, 10 is doing fine.

Fucc

Offline

## #386 2019-01-31 21:23:26

loon_attic
Banned
Registered: 2012-06-08
Posts: 10,259

### Re: Absent's Code Thread / Tech Blog

lol i just have the 4gb (probably 2x2) and it's been ok for now. I might be able to transplant the 8gb(4x2?) ram from my other thinkpad...

sloth wrote:

Comfy does not provide challenge, challenge provides success, success provides happiness. Our world is not comfy, although we tried to make it so. Slaves of our own inventions, yada, yada. Not only on a technological level, also on a social and political level. Nothing more but apes. Apes with psychosomatic disorders.

Offline

## #387 2019-01-31 23:23:13

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

4gb was great with slackware, this has wind00 on it because fl studio and I'm not gonna replace it. I'll fix my other laptop for slackware soonish, should get back to PA and restart my server soon so I can sync my pw manager files though and get backups going again etc

Fucc

Offline

## #388 2019-02-05 21:21:03

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

While learning react and redux and bullshit, I wanna stay on top of algorithms. Signed up for leetcode, which seems like the best place to practice this sort of thing. Apparently everyone uses it for interviews at google and bullshit.

Anyway, first leetcode challenge:

``````var twoSum = function(nums, target) {
let i = 0;
let count = nums.length;
while(i < count){
for(let j = i+1; j < count; j++){
if (nums[i] + nums[j] == target){
return [i, j];
}
}
i++;
}
return [];
};``````

Not great but okay.

Fucc

Offline

## #389 2019-02-07 13:13:33

sloth
WITNESS ME
From: Spurdoland
Registered: 2012-06-17
Posts: 7,807

### Re: Absent's Code Thread / Tech Blog

It's supposed to do add together two sums until it reaches the target?

Hindsight is always 20/20.

God wrote:

A surprising amount of insight can be gleamed from sitting on the toilet. More concerning, however, is the amount of nostalgia.

When in doubt, move north. God bless suomi.

Offline

## #390 2019-02-07 16:19:43

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

You give it an array of numbers and a value, it spits out the first two numbers that add to the value, except like, it iterates over the array so if the first and last or first and n number == target, it'll return those.

Except it returns the actual array index of them not the actual num itself. That was a terrible explanation.

Fucc

Offline

## #391 2019-02-07 17:23:42

sloth
WITNESS ME
From: Spurdoland
Registered: 2012-06-17
Posts: 7,807

### Re: Absent's Code Thread / Tech Blog

Ah I'd get it if I weren't so tired. Then it makes more sense.

Hindsight is always 20/20.

God wrote:

A surprising amount of insight can be gleamed from sitting on the toilet. More concerning, however, is the amount of nostalgia.

When in doubt, move north. God bless suomi.

Offline

## #392 2019-02-07 19:08:23

loon_attic
Banned
Registered: 2012-06-08
Posts: 10,259

### Re: Absent's Code Thread / Tech Blog

i can't think of a better explanatio

sloth wrote:

Comfy does not provide challenge, challenge provides success, success provides happiness. Our world is not comfy, although we tried to make it so. Slaves of our own inventions, yada, yada. Not only on a technological level, also on a social and political level. Nothing more but apes. Apes with psychosomatic disorders.

Offline

## #393 2019-02-07 22:48:27

sloth
WITNESS ME
From: Spurdoland
Registered: 2012-06-17
Posts: 7,807

### Re: Absent's Code Thread / Tech Blog

Yeah got it after some sleep. Pretty nice.

Hindsight is always 20/20.

God wrote:

A surprising amount of insight can be gleamed from sitting on the toilet. More concerning, however, is the amount of nostalgia.

When in doubt, move north. God bless suomi.

Offline

## #394 2019-02-10 17:10:15

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

Been trying to learn react via FCC. I don't get it at all. It's just not "clicking". I'm signing up for this course: roadtoreact.com

50 dollar coder package. Not too steep, and hopefully more explanatory and less "here's random challenges without adequately explaining context". Not really getting the why when it comes to react on FCC and how state is working behind the scenes, and the whole setup of the stack, etc. It's just not clicking. Will likely get back to FCC after this course.

Fucc

Offline

## #395 2019-02-10 19:46:40

loon_attic
Banned
Registered: 2012-06-08
Posts: 10,259

### Re: Absent's Code Thread / Tech Blog

i had to keep looking at the docs..

sloth wrote:

Comfy does not provide challenge, challenge provides success, success provides happiness. Our world is not comfy, although we tried to make it so. Slaves of our own inventions, yada, yada. Not only on a technological level, also on a social and political level. Nothing more but apes. Apes with psychosomatic disorders.

Offline

## #396 2019-02-10 20:30:11

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

Yeah I kept having to read guides and articles and shit. It seems like an annoying way to learn, for me. A structured course where I don't have to dig through a ton of shit not relevant to what I'm trying to figure out before finally stumbling upon it seems best. I know it's not great in terms of learning *everything* I'll need in terms of web dev, but I just need enough to land an entry level job, which means I just need to get good enough to start building some apps and shit to showcase.

At some point I will quit my job and move home and spend all day trying to find a job, but until I'm ready with an okay portfolio I can build on, I can't risk being unemployed and in as much debt as I'm in. First things first, get my portfolio started, get used to building basic SPA's, and then I can move. By then my ex will likely have found someone if she hasn't already, my friends will have had a lot of experiences without me, etc, but hey, if it means I can land a job 60k+ / year, I think that's fine. I can't keep working for ~15-30k / year like I have been for the past 7 years, it's just a shitty existence and I have no motivation to get girls or join clubs while barely covering rent and food and shit.

Fucc

Offline

## #397 2019-02-10 20:33:00

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

Also I think next weekend I'll take a drive up to PA to hang out with my friend who just got out of jail and while I'm there I'll get the backup server going again.

I'm all set up with visual studio, NPM, Node, and react, react-dom, and all that shit. Environment is good to go, easier than expected. Probably a little harder on a production server but not bad at all with create-react-app

Also got SumatraPDF on wind00 set up with a god color scheme so I don't have to keep finding my page again in FF's built in PDF setup.

Good thing I got ramm, I'm nearing 6GB with firefox taking most of it, along with visual studio taking a little bit (it's pretty light weight for what it is), and other things I'm running.

Fucc

Offline

## #398 2019-02-10 20:55:05

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

[video]https://www.youtube.com/watch?v=x7cQ3mrcKaY[/video]

On why they decided to mix markup and display logic in react

Fucc

Offline

## #399 2019-02-11 23:19:40

absentinsomniac
Administrator
Registered: 2012-06-09
Posts: 16,751

### Re: Absent's Code Thread / Tech Blog

For whatever reason you have to add:

``````if (module.hot){
module.hot.accept();
}``````

So it reloads the application instead o refreshing after making changes.

Fucc

Offline

## #400 2019-02-12 07:25:56

sloth
WITNESS ME
From: Spurdoland
Registered: 2012-06-17
Posts: 7,807

### Re: Absent's Code Thread / Tech Blog

Best practice: Don't use JS.

Hindsight is always 20/20.

God wrote:

A surprising amount of insight can be gleamed from sitting on the toilet. More concerning, however, is the amount of nostalgia.

When in doubt, move north. God bless suomi.

Offline

## Board footer

Powered by FluxBB