Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "parseint"
-
Basically,
1+infinity = 1
But
infinity + 1 = NaN
My entire maths fundamental shuttered by the beautiful JS language....26 -
parseInt("220125152409071002")
220125152409071000
Looks good... looks good... looks good... wait wtf?!? where the hell is the 2?!?!18 -
Do things in JS they said, it'll be easier they said...
(After a few WTF's i found the problem, arr.map passes more parameters to parseInt than just the strings. It also passes an array index that gets interpreted as radix)18 -
Why would you ask me the diferrence between parseInt and parseFloat? When you were the first person who was unable to fix the decimal to two using parseFloat? 😝
-
!multirant
1. MonoDevelop
Installed Unity for a game I'm working on. Realized I didn't reinstall VS when my SSD got corrupted. Didn't install VS plugin w/ Unity.
So now I have MonoDevelop. It's not a bad editor, but PLEASE. IF YOU ARE GOING TO HIGHLIGHT A FUNCTION WITH RED BECAUSE IT DOESNT EXIST IN THE CLASS, THEN TELL ME, WHAT THE FUCK EXISTS IN THE CLASS!
2. UnityJS
Unity's JS implementation is terrible.
First, let's throw basic syntax shit out on the window. string.toUpperCase? Nah, let's make it string.ToUpperCase to annoy the shit out of devs.
AND SOME OF THE STANDARD FUNCTIONS ARENT EVEN FUCKING WORKING!
Need to use parseInt(string, 2)? WELL GO FUCK YOURSELF, BECAUSE WE DIDNT IMPLEMENT THAT SHIT.
...or use C# I guess...
FUCK UNITY.
🖕🖕🖕15 -
You know what really grinds my gears? When people criticize a programming language but uses edge cases and stuff that can be avoided by using the tried and true "don't be an idiot". Take for instance JavaScript, a language I like and a language that has a lot you can criticize. But I feel like a lot of peoples criticism isn't warranted.
What's that? No ints? Use parseInt or Math.floor.
What are you saying? == works in strange ways? Yes, that's what we have === for.
Type coercion is wonky? Think it's weird how string + int works differently than string - int? Wanna string with number + - + - - + - - etc? Don't! Don't add strings and ints, don't subtract strings and ints. You can't in statically typed languages and you aren't supposed to in dynamically typed
Adding arrays and objects, arrays and arrays, objects and objects etc. is inconsistent? Why are you trying to do that?
Adding floats together gives odd results? Now we're getting somewhere! And Mozilla responded to that with a method called toFixed.
Declaring variables with var doesn't always work that well? Use let and const
Then there's this weird attitude that some people I've met have, where they will complain about the module system and how "well you rely on the community for those packages" as if it's a bad thing. And then coming with the "well you don't know what the (open source) packages do internally" as if I (for the most part) give a shit. Then they'll swear by companies like Zend or Microsoft as if they can't just stop supporting the languages they use. Maybe it's just because I like community content more because of video game mods.
Wanna criticize JS, then there's plenty to talk about. Like the built in date object is basically shit. Or how in NodeJS you can have node_modules in your node_modules. Or how classes don't really have the best syntax. Left-Pad. And so on (it's too late for me to be able to remember much more).1 -
function getUnstuck(){
var methods = [
"getting on devRant for a bit",
"adding new functionality to your program",
"refactoring a function or two",
"working on a personal project for a bit",
"zoning out on some music to clear your thoughts",
"getting up from your desk and going to talk to someone",
"getting more coffee",
"taking a \"lunch\" break at the bar",
"just fucking leaving for the day"
];
return "try " + methods[parseInt(Math.random() * methods.length)];
} -
I'll just put it here and let the internet judge.
parseInt(((height - 81 - 20 - 20 - 50 - 7 - 30 - 240) / 6), 10);5 -
You know that feel as a developer when you add a feature to someone's existing project and you see a shitty code. well this has to be one of the shittiest code I have seen.
select_patient:function(patient)
{
console.log(patient)
this.select_patient_index = 0;
var pending = patient.Pending;
var USER_ID_Patient = patient.ID;
var prescription_ID = patient.Prescription_ID;
if(prescription_ID == null) prescription_ID = 0;
patient.Pending = pending = parseInt(pending);
patient.Prescription_ID = prescription_ID = parseInt(prescription_ID);
patient.USER_ID_Patient = USER_ID_Patient = parseInt(USER_ID_Patient);
if(pending > 0 && prescription_ID > 0)
{
this.select_patient_index = this.list.indexOf(patient);
$('#patientContinueModal').modal('show');
return false;
}
$scope.prescription.set(patient,null);
return false;
}
Also the guy has a space in his url.
xxxxxx.com/shopping cart !
My first instinct is to poke my eyes, find the developer (if we can call him that and shove it up his ______)1 -
When you’re trying to write a function to convert a base 10 integer to a base 2 integer in Javascript without using parseInt() and it takes you a while to realize that you’re used to integer division being integer division and have forgotten that JavaScript stores numbers as double precision floating point. *facepalm*1
-
Just a short reply to whoever deleted his rant because he didn't read the JS docs.
map is a map. You don't just dump a function call into there. You map the value to el and the value is then set to the function result.
This works:
new Array(38).fill("10").map(el => parseInt(el));6 -
case "addprem" : {
if (isGroup) return reply('This command can only be used in private chat!')
if (args.length < 2) return reply(`Kirim perintah : ${command} number|total`)
if (!q.includes('|')) return reply(`Incorrect usage, use the | . symbol`)
var numb = q.split('|')[0]
var total = q.split('|')[1]
var number = numb.replace(/[+| |(|)|.|-]/gi, "")
if (isNaN(parseInt(number))) return reply('Thats not your number😥')
reply('Success')
let addprems = [];
var object_buy = {
ID: pushname,
number: number,
session: total
}
fs.writeFile(addprems, JSON.stringify(object_buy, null, 3))
break
}5 -
CEO offers me a position
CTO sends me 7 logical interview questions, including asking me to write a program that converts binary to decimal in Node...2 -
The datepicker saga
Part one
So I begin work on a page where user add their details, project is late, taking ages on this page
Nearly done, just need a component to allow users to put in some date of births. Look for react components.
Avoiding that one because fuck Bootstrap.
Ah-ha, that looks good, let's give it a go.
CSS doesn't exist, oh need copy it over from npm dist. Great it applied but...
... WTF it's tiny. Thought it was a problem with my zoom. Nope found the issue in github.com and it's something to do with using REM rather than EM or something, okay someone provided a solution, rather I saw a couple of solutions, after some hacking around I got it working and pasted it in the right location and yes, it's a reasonable size now.
Only it's a bit crap because it only allows scrolling 1 month at a time. No good. Hunting through the docs reveals several options to add year and month drop downs and allow them to be scrolled. Still a bit shit as it only shows certain years, figure I'd set the start date position somewhere at the average.
Wait. The up button on the scroll doesn't even show, it's just a blank 5px button. Mouse scroll doesn't work
Fucking...
... Bailing on that.
Part 2
Okay sod it I'll just make my own three drop down select boxes, day, month and year. Easy.
At this point I take full responsibility and cannot blame any third party. And kids, take this as a lesson to plan out your code fully and make no assumptions on the simplicity of the problem.
For some reason (of which I regretted much) I decided to abstract things so much I made an array of three objects for each drop down. Containing the information to pretty much abstract away the field it was dealing with. This sort of meta programming really screwed with my head, I have lines like the following:
[...].map(optionGroup =>
optionGroup.options[
parseInt(
newState[optionGroup.momentId]
, 10)
]
)...
But I was in too deep and had to weave my way through this kind of abstract process like an intrepid explorer chopping through a rain forest with a butter knife.
So I am using React and Redux, decided it was overkill to use Redux to control each field. Only trouble is of course when the user clicks one of the fields, it doesn't make sense in redux to have one of the three fields selected. And I wanted to show the field title as the first option. So I went against good practice and used state to keep track of the fields before they are handed off to the parent/redux. What a nightmare that was.
Possibly the most challenging part was matching my indices with moment.js to get the UI working right, it was such a meta mess when it just shouldn't have taken so stupidly long.
But, I begin to see the light at the end of this tunnel, it's slowly coming together. And when it all clicks into place I sit back and actually quite enjoy my abysmal attempt at clean and easy to read code.
Part 3
Ran the generated timestamp through a converter and I get the day before, oh yeah that's great
Seems like it's dependant on the timezone??!
Nope. Deploying. Bye. I no longer care if daylight savings makes you a day younger.1 -
MFW I worked longer than 8 hours because of a weird bug that turned out to be caused by lack of typing in a third-party library. Was supposed to be a number but I was giving it a string 🤦♀️Need more sleep.
The funniest part is the library was written in Typescript. HmmMMMMmm...
Throw a `parseInt` or warning for wrong type in there for me, fellow devs! Save consumers of your library a headache!! -
Grrrr
I love JS, but I hate browsers.
Universal ES5 way to initialize a date from a input value in "dd.mm.YYYY" format:
var split = input.value.split('.');
var from = {};
from.day = parseInt(split[0]);
from.month = parseInt(split[1])-1;
from.year = parseInt(split[2]);
var myDate = new Date(from.year, from.month, from.day);
// if a timestamp format is needed:
var myDateTimestamp = +new Date(from.year, from.month, from.day);
No, I won't use moment.js or other bloat-braries just for fucking dates.1 -
CamanJS is a nice library and such but why does it's vignette function take a String as it's parameter for percentage!? It parses it by removing the '%' character and doing a parseInt()!2
-
I have learnt html,css, and some basic javascript for web development,and made a few projects including a calculator with prompts.This is the code :
<script type="text/javascript">
function prote(){
let firstNum=prompt("Enter first number")
let secondNum=prompt("Enter second number")
let num1=parseInt(firstNum);
let num2=parseInt(secondNum);
let result=num1 + num2;
alert(result);
}
function prote2(){
let firstNum=prompt("Enter first number")
let secondNum=prompt("Enter second number")
let num1=parseInt(firstNum);
let num2=parseInt(secondNum);
let result=num1 - num2;
alert(result);
}
function prote3(){
let firstNum=prompt("Enter first number")
let secondNum=prompt("Enter second number")
let num1=parseInt(firstNum);
let num2=parseInt(secondNum);
let result=num1* num2;
alert(result);
}
function prote4(){
let firstNum=prompt("Enter first number")
let secondNum=prompt("Enter second number")
let num1=parseInt(firstNum);
let num2=parseInt(secondNum);
let result=num1/num2;
alert(result);
}
</script>
</body>
<form>
<br>
<input type= "button" value="Add" onclick="prote()" />
<input type= "button" value="Subtract" onclick="prote2()" /><br><br>
<input type= "button" value="Multiply" onclick="prote3()" />
<input type= "button" value="Divide" onclick="prote4()" />
</form>
However I want to do game dev and I feel it may have been a mistake to start learning web development,I originally started learning code in roblox studio,however some do not consider making games in roblox studio "REAL" game development and I didn't exactly feel it was either.I messed around with unity and found the layout quite similar to roblox studio. However
I heard phaser uses javascript and Unity uses C#.In which case using phaser would not require using a new language.However I am aware that If I want to make 3d games(Which I do) I will have to move to unity eventually.Basically, as a beginner should I switch to unity and C# first or Phaser and javascript first.6 -
Excuse my question I might be the one to blame, but on Typescript 3.7 JSON.stringify parses numbers as strings, while on 3.4 it was working without issues.
I'm no pro in web dev but I did use JSON.stringify lots of times and that's something strange here, not sure what the cause is, but when I parse number props again using parseInt(value.toString()) it works .-.2