Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
  • 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
i quit]
stupid links
i said i need to make a website i need code for it
bro i said
@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
@Liberatys 🙌
With ideas and invents
i need to make a movie app i need codes
Aditya Narayan Nayak
Julian Gonggrijp
Hi @AdityaN71677515_twitter :wave:
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!
A sensor
A program
Tell me a time to chatt
Julian Gonggrijp
@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.
//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;

    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

@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!

Thanks for the tips. @jgonggrijp It's really helpful and educational.
Julian Gonggrijp
Welcome @Srinath-V-S
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
I do not have codes
My friend
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
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
creating custom address from '0x' to some other word in ethereum private blockchain (using puppet)
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

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
@Aura09c what kind of challenge?
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
@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
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
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
@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?
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?.
Julian Gonggrijp
@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
how to create custom public ethereum address starting with say '0xajc'
Just confirming I m here


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

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
@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
What's an unix command to check what process(es) are currently writing/reading from a file / directory?
Julian Gonggrijp
@danlugo92 lsof
1 reply
Victor Koji