Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Sep 04 03:35
    @MadLittleMods banned @alexchole:matrix.org
  • Jun 16 19:43
    @jgonggrijp banned @VictoriaE776_twitter
  • Jan 21 00:46
    @jgonggrijp banned @brianna1234_gitlab
  • Oct 23 2021 22:35
    @jgonggrijp banned @moviehdapk123_gitlab
  • Oct 05 2021 19:17
    @MadLittleMods banned @Bubel14
  • May 07 2021 14:51
    @MadLittleMods banned @A13516729925
  • Apr 27 2021 17:13
    @MadLittleMods banned @leon:nilsu.org
  • Apr 26 2021 16:32
    @MadLittleMods banned @parveshpremi12_gitlab
  • Apr 18 2021 16:15
    @MadLittleMods banned @Mkhaleel201978_twitter
  • Apr 13 2021 03:52
    @MadLittleMods banned @Henaniy
  • Apr 03 2021 18:52
    @MadLittleMods banned @yvvhxCawUPdTI48_twitter
  • Apr 01 2021 03:53
    @MadLittleMods banned @soravsolanki15319_gitlab
  • Mar 30 2021 21:09
    @MadLittleMods banned @awanandco_twitter
  • Mar 30 2021 03:58
    @MadLittleMods banned @ayaz9102_twitter
  • Mar 28 2021 19:58
    @MadLittleMods banned @ashokykv_twitter
  • Mar 28 2021 19:04
    @MadLittleMods banned @dong7318
  • Mar 27 2021 18:59
    @MadLittleMods banned @Mahira110Khan_twitter
  • Mar 27 2021 17:24
    @MadLittleMods banned @ManapeetS_twitter
  • Mar 27 2021 17:24
    @MadLittleMods banned @ShramaRavindra_twitter
  • Mar 26 2021 20:32
    @MadLittleMods banned @AR_Khan110_twitter
Ninja2SuS
@Ninja2SuS
bro i said
Liberatys
@Liberatys
@Ninja2SuS @jgonggrijp is just trying to help you. You seem to be in a hurry or otherwise aggravated, but please keep in mind that this is a public forum where we exchange help/advice. If you were to provide some more information about your website, in a behaved manner, we would probably be able to either help you directly or point you to some sources. (Which Julian already did!) @jgonggrijp thank you for providing help 👍🏻
Julian Gonggrijp
@jgonggrijp
@Liberatys 🙌
Bubel14
@Bubel14
With ideas and invents
Ninja2SuS
@Ninja2SuS
@Bubel14
Ninja2SuS
@Ninja2SuS
i need to make a movie app i need codes
Aditya Narayan Nayak
@AdityaN71677515_twitter
hi
Julian Gonggrijp
@jgonggrijp
Hi @AdityaN71677515_twitter :wave:
Srinath
@Srinath-V-S
I've starting to develop a data unit converter. I have a text box and dropdown( which will have all the units such as bits,kilobits,...upto terabytes). So user will type in some number and select a unit(say byte). On selecting i need to print the equivalent values for other units. How can i programmatically achieve this?. For eg if i type 1 and select kilobyte as unit then it should show all equivalent values like whats 1 KB is equal to how many bits,kilobits,..upto terabytes) excluding KB obviously. Thanks!
Bubel14
@Bubel14
A sensor
A program
To
Plus
Bubel14
@Bubel14
Ok
Tell me a time to chatt
Ok
Julian Gonggrijp
@jgonggrijp
@Srinath-V-S :point_up: 7 september 2021 11:56 Could you perhaps show a little bit of code that you already have? I think there is more than one way to do it.
Srinath
@Srinath-V-S
//using base unit data this function returns the equivalent data for other units
function response(data) {
    let obj = {};
    obj.bits = data;
    obj.kbits = data / 1000;
    obj.mbits = data / (1000 * 1000);
    obj.gbits = data / (1000 * 1000 * 1000);
    obj.tbits = data / (1000 * 1000 * 1000 * 1000);
    obj.bytes = data / 8;
    obj.kilobytes = data / 8000;
    obj.megabytes = data / (8000 * 1000);
    obj.gigabytes = data / (8000000 * 1000);
    obj.terabytes = data / (8000000 * 1000 * 1000);

    return obj;
}

// convert any units data into base unit data ( here bits)
function toBits(data, unit) {
    let obj = {};
    obj.b = data;
    obj.kb = data * 1000;
    obj.mb = data * 1000 * 1000;
    obj.gb = data * 1000 * 1000 * 1000
    obj.tb = data * 1000 * 1000 * 1000 * 1000;
    obj.B = data * 8;
    obj.KB = data * 8000;
    obj.MB = data * 8000 * 1000;
    obj.GB = data * 8000000 * 1000;
    obj.TB = data * 8000000 * 1000 * 1000;
    console.log(obj);

    for (let key in obj) {
        if (key == unit) {
            return obj[key];
        }
    }
}
Basically I'm considering bit as base unit, so whatever unit user selects it will be converted to its bits form and fed into response function to get other equivalent unit's data.
Julian Gonggrijp
@jgonggrijp

@Srinath-V-S Before I answer your question, let me give you a few tips. Firstly, in the toBits function, you're constructing a large object and then throwing away all of it except for one of its properties. You could avoid this, performing only the calculation you need, by using a switch statement like this:

function toBits(data, unit) {
    switch(unit) {
    case 'b': return data;
    case 'kb': return data * 1000;
    case 'mb': return data * 1000 * 1000;
    case 'gb': return data * 1000 * 1000 * 1000
    case 'tb': return data * 1000 * 1000 * 1000 * 1000;
    case 'B': return data * 8;
    case 'KB': return data * 8000;
    case 'MB': return data * 8000 * 1000;
    case 'GB': return data * 8000000 * 1000;
    case 'TB': return data * 8000000 * 1000 * 1000;
    }
}

However, you can still do better based on the next two tips.

Secondly, I recommend using consistent names for the units. In response you're writing the names in full, while in toBits, you're using abbreviations. On top of that, those abbreviations aren't consistent with the SI prefixes. It's "kB", not "KB", and "Mb"/"Gb"/"Tb", not "mb"/"gb"/"tb". Using consistent names makes it easier for yourself to predict which name you should be using in your code, and also helps with the next tip I'm about to give.

Thirdly, note that you're repeating the numbers in both functions. You can share them in a common variable so you don't have to repeat yourself:

const unitFactors = {
    b: 1,
    kb: 1000,
    Mb: 1000 * 1000,
    Gb: 1000 * 1000 * 1000,
    Tb: 1000 * 1000 * 1000 * 1000,
    B: 8,
    kB: 8 * 1000,
    MB: 8 * 1000 * 1000,
    GB: 8 * 1000 * 1000 * 1000,
    TB: 8 * 1000 * 1000 * 1000 * 1000,
};

function response(bits) {
    const obj = {};
    for (let unit in unitFactors) {
        obj[unit] = bits / unitFactors[unit];
    }
    return obj;
}

function toBits(value, unit) {
    return value * unitFactors[unit];
}

This has the added benefit that if you want to show a dropdown with units, you can just use Object.keys(unitFactors) (or _.keys(unitFactors) if using Underscore or Lodash) to get an array with all the unit names. Also, if you want to display full unit names somewhere, you can just use a second mapping from abbreviations to full names:

const unitFullNames = {
    b = 'bit',
    kb = 'kilobit',
    Mb = 'megabit',
    Gb = 'gigabit',
    Tb = 'terabit',
    B = 'byte',
    kB = 'kilobyte',
    MB = 'megabyte',
    GB = 'gigabyte',
    TB = 'terabyte',
};

Now to answer your original question. You may have already realised that if the user inputs a value and a unit, you can obtain an object with equivalent values in all units (including the one the user entered) with the expression response(toBits(value, unit)). If I understood your question correctly, you want to remove the unit that the user entered from this object. A simple way to do that is with the delete operator:

const otherUnits = response(toBits(value, unit));
delete otherUnits[unit];

Underscore has a helper function omit that lets you achieve the same thing in a single expression:

const otherUnits = _.omit(response(toBits(value, unit)), unit);

I hope this helps!

Srinath
@Srinath-V-S
Thanks for the tips. @jgonggrijp It's really helpful and educational.
Julian Gonggrijp
@jgonggrijp
Welcome @Srinath-V-S
Ghost
@ghost~61377f966da037398484f775
New to this platform (a beginner) . Can anyone help me in roadmaps and suggestions for Java web development. Currently knowing only Java servlets,jsp , tomcat server and MySQL database
Bubel14
@Bubel14
I do not have codes
My friend
Rocking_star_yash_fans_
@Rocking68644662_twitter
Hey I want to build an chatting app which includes 4 memers chatting and with video calling and audio calling + chatting what I do?
Julian Gonggrijp
@jgonggrijp
Ambitious plan, @Rocking68644662_twitter ! I don't know what memers are, but I suspect building a chatting/conferencing app that works well takes at least a few thousand hours (with companies like M$ and Zoom likely spending tens or even hundreds of thousands of hours). Unless you have that much time or that much money, your best bet is probably to take an open source project that already works, such as Jitsi, and customize it to your needs.
Ankit Joshi
@AJONCODE
creating custom address from '0x' to some other word in ethereum private blockchain (using puppet)
Aura09c
@Aura09c
I am starting this new project. I think i will problaby need some help. Does anyone here have a discord thats up for the Challenge
Daniel Gomes Pina
@DanielGPina

Hey I want to build an chatting app which includes 4 memers chatting and with video calling and audio calling + chatting what I do?

I'd first try to build a text only chat between 2 people, after I knew how to do that I'd try and implement on top off it. Don't start from the end start from the start

Rajarshi Bandopadhyay
@Theocrat
@Aura09c what kind of challenge?
Srinath
@Srinath-V-S
How many bytes make 1 KB? is it 1000 or 1024? as far as i learned it is 1024 bytes. Getting mixed results on the internet so confusing . What is the right answer?
Julian Gonggrijp
@jgonggrijp
@Srinath-V-S The kB traditionally used to mean 2^10 bytes, but in recent years, people have reverted to using the "kilo" prefix exclusively in the SI meaning, i.e., a factor of 10^3. There is now a new prefix ki ("kibi") for 2^10 so you can be more explicit about what you mean. Likewise, Mi for 2^20, Gi for 2^30, and so on.
Amit Prasad
@amitprasad01_twitter
Hello Here!
Can someone guide me , how to debug the backtracking algorithms
I am getting puzzled when it comes to recursion call inside loop again
Any link/tutorial if you guys know would also help. PS: I have googled but not got the breakthrough in the sense i could not understand
14 replies
Jonah
@Jonah31162987_twitter
Hi, I use Python on a school chromebook (because I'm not at home and my phone is incredibly laggy) and I want to know if there are any Python coding applications that you can download without linux? (I can't use linux.)
Julian Gonggrijp
@jgonggrijp
@Jonah31162987_twitter since you write that you are already using Python, what exactly do you mean by a Python coding application? What are you trying to achieve?
Srinath
@Srinath-V-S
Hi. I'm creating a tool like diff-checker. I use codemirror library for that. They provide a addon called merge/merge.js which basically has all the functions that i needed for diff check tool. However when i add that file in my project and use one of its constructor CodeMirror.MergeView, I'm getting Uncaught TypeError: CodeMirror.MergeView is not a function this error. Please help me what i'm doing wrong?.
Thanks!
Julian Gonggrijp
@jgonggrijp
@Srinath-V-S Could you post a link to your code? Without seeing your code it's going to be blind-guessing.
2 replies
Ankit Joshi
@AJONCODE
how to create custom public ethereum address starting with say '0xajc'
InfernapeRed
@InfernapeRed
Just confirming I m here
captainjay22
@captainjay22
Yup
Srinath
@Srinath-V-S

@jgonggrijp

var value, orig1, orig2, dv, panes = 2,
    highlight = true,
    connect = null,
    collapse = false;
initUI();

function initUI() {
    var target = document.getElementById("view");
    target.innerHTML = "";
    let dv = CodeMirror.MergeView(target, {
        value: value,
        origLeft: panes == 3 ? orig1 : null,
        orig: orig2,
        lineNumbers: true,
        mode: "",
        highlightDifferences: highlight,
        connect: connect,
        collapseIdentical: collapse
    });

}

I thought once its constructor is initialized i'll get two panes in the UI but getting that error mentioned above.

Julian Gonggrijp
@jgonggrijp
@Srinath-V-S Is this the whole script? There is no header with import or require statements? Do you have <script src="..."></script> lines somewhere in your HTML that will import codemirror and the merge extension?
2 replies
Daniel Lugo
@danlugo92
What's an unix command to check what process(es) are currently writing/reading from a file / directory?
Julian Gonggrijp
@jgonggrijp
@danlugo92 lsof
1 reply
Victor Koji
@victorkoji
EINBOX
@EINBOX
Hello,
can someone help !!!
i want to tap on mobile browser<chrome> to turn pages right to left or left to right
when i tap on left side of the page it turns to left and viceversa, this is the 1st time am using webdriverIO.
i have tried using performActions but not working
await browser.performActions([{
type: 'pointer',
id: 'pointer1',
parameters: { pointerType: 'mouse' },
actions: [
{ type: 'pointerMove', origin: this, x: 380, y: 350 },
{ type: 'pointerDown', button: 0 },
{ type: 'pointerUp', button: 0 },
{ type: 'pause', duration: 10 },
{ type: 'pointerDown', button: 0 },
{ type: 'pointerUp', button: 0 }
]
}])
browser.releaseActions();
Chlorine Pentoxide
@ChlorinePentoxide
Hello, does anyone why is the CSS Grid acting abnormally on this page (here). The relevant CSS classes used are grid grid-cols-7. I have been using multiple methods(float and flex) to properly render and align the divs, but can't seem to make them work the way it should be. Any insight into what is happening here will be helpful.
JomoPipi
@JomoPipi

Hi,

I decided I want to try to get my first Software Development job.
How is my portfolio, so far?
https://ronald-ronaldmcorona.vercel.app