• Breaking News

    Thursday, April 25, 2019

    Comparing Character Array in C and Byte String in Python Ask Programming

    Comparing Character Array in C and Byte String in Python Ask Programming


    Comparing Character Array in C and Byte String in Python

    Posted: 25 Apr 2019 10:53 AM PDT

    I'm attempting to reproduce some C code in Python, and ran into an issue with character formatting. Specifically, I'm working on rewriting some old C code that uses the RS-232 standard for communication with some devices.

    I want to reproduce a character array in C that is formed in the following way:

    char msg[128]; msg[0] = 'J'; msg[1] = 182; msg[2] = 0;

    My naive attempt to do this was to simply use a byte string, where:

    msg = b'J1820'

    However, the output I receive after sending this command to the device does not match what I expect at all (it's always b'\x15', seemingly regardless of what I send).

    Is there a difference between using the byte string as I am in Python with the above C code? To be clear I'm using Python3.4.

    submitted by /u/phybae7
    [link] [comments]

    Is C# a good programming language to render graphics? And if so, any resources?

    Posted: 25 Apr 2019 01:08 PM PDT

    What language is best suited for my program idea?

    Posted: 25 Apr 2019 08:25 PM PDT

    I want to develop a piece of software. You input a url for a news story and it writes tweets based on the body text of the news story. I realize something this basic could probably be done with almost anything, but is there any language better suited for this than others? Thanks in advance.

    submitted by /u/87534629
    [link] [comments]

    How do I relieve "Brain Fog"...

    Posted: 25 Apr 2019 05:02 AM PDT

    I could also call it, a hazy brain. Is there any remedies youd recommend? I just lay in bed for 15 minutes then get up and try to do something

    submitted by /u/moxiesmiley
    [link] [comments]

    js - selecting and iterating through a table from a website

    Posted: 25 Apr 2019 06:03 PM PDT

    if i wanted to scrape a table from a website and a part of its html looked like

     <table> <tbody> <tr> <td>1A</td> <td>1B</td> <td>-</td> <td>1C</td> </tr> <tr> <td>2A</td> <td>2B</td> <td>2C</td> </tr> <tr> <td>3A</td> <td>3B</td> <td>3C</td> </tr> </tbody> </table> <table> <tbody> <tr> <td>4A</td> <td>4B</td> <td>-</td> <td>4C</td> </tr> <tr> <td>5A</td> <td>5B</td> <td>5C</td> </tr> <tr> <td>6A</td> <td>6B</td> <td>6C</td> </tr> </tbody> </table> <table> <tbody> <tr> <td>7A</td> <td>7B</td> <td>-</td> <td>7C</td> </tr> <tr> <td>8A</td> <td>8B</td> <td>8C</td> </tr> <tr> <td>9A</td> <td>9B</td> <td>9C</td> </tr> </tbody> </table> 

    how would i, for example, select the the second table (no id or classes distinguishing tables) and get the text content for the A and C (4A, 4C, 5A, 5C, 6A, 6C) of each row?

    i know i would use the request library to get to the website and then maybe jquery or cheerio for the actual scraping? i wouldn't be able to use the document method in this case, would i?

    submitted by /u/cash4soul
    [link] [comments]

    20 Questions Game in Java

    Posted: 25 Apr 2019 04:43 PM PDT

    So I am trying to finish up my final project for my programming class. The goal is to make a game of 20 questions (or something similar) using binary search trees. One of the harder parts of this project is that we have to use 4 separate classes (one for the methods of the binary search tree, one for the questions, one for the answers, and another main module). I have all of the methods for the tree; however, I am having a lot of trouble with trying to figure out how all the classes should work together. Mainly how to insert nodes as questions and iterate down the tree based on the response yes or no.

    Here is what I have for the BST:

    public class LinkedBinaryTreeNode<E> implements BinaryTreeNode<E> {
    E data;
    BinaryTreeNode<E> parent;
    BinaryTreeNode<E> leftChild;
    BinaryTreeNode<E> rightChild;
    int depth = 0;
    /**
    * Returns the data stored in this node.
    */
    @Override
    public E getData() {
    return data;
    }
    /**
    * Modifies the data stored in this node.
    */
    @Override
    public void setData(E data) {
    this.data = data;
    }

    /**
    * Returns the ancestor of this node that has no parent,
    * or returns this node if it is the root.
    */
    @Override
    public BinaryTreeNode<E> getRoot() {
    BinaryTreeNode<E> currentNode = this;
    if (currentNode.getParent() != null) {
    currentNode.getParent().getRoot();
    }
    return currentNode;
    }
    /**
    * Returns the parent of this node, or null if this node is a root.
    */
    @Override
    public BinaryTreeNode<E> getParent() {
    return parent;
    }
    /**
    * Modifies the parent when binary tree changes
    *
    */
    private void setParent(BinaryTreeNode<E> parent) {
    this.parent = parent;
    }
    /**
    * Returns the left child of this node, or null if it does
    * not have one.
    */
    @Override
    public BinaryTreeNode<E> getLeft() {
    return leftChild;
    }
    /**
    * Removes child from its current parent and inserts it as the
    * left child of this node. If this node already has a left
    * child it is removed.
    */
    @Override
    public void setLeft(BinaryTreeNode<E> child) {
    leftChild = child;
    if (child != null) {
    ((LinkedBinaryTreeNode<E>) child).setParent(this);
    ((LinkedBinaryTreeNode<E>) child).depth = depth + 1;
    }
    }
    /**
    * Returns the right child of this node, or null if it does
    * not have one.
    */
    @Override
    public BinaryTreeNode<E> getRight() {
    return null;
    }
    /**
    * Removes child from its current parent and inserts it as the
    * right child of this node. If this node already has a right
    * child it is removed.
    */
    @Override
    public void setRight(BinaryTreeNode<E> child) {
    rightChild = child;
    if (child != null) {
    ((LinkedBinaryTreeNode<E>) child).setParent(this);
    ((LinkedBinaryTreeNode<E>) child).depth = depth + 1;
    }
    }
    /**
    * Returns true if the node has any children.
    * Otherwise, returns false.
    */
    @Override
    public boolean isParent() {
    return hasLeftChild() || hasRightChild();
    }
    /**
    * Returns true if the node is childless.
    * Otherwise, returns false.
    */
    @Override
    public boolean isLeaf() {
    return !isParent();
    }
    /**
    * Returns true if the node has a left child
    */
    @Override
    public boolean hasLeftChild() {
    return leftChild != null;
    }
    /**
    * Returns true if the node has a right child
    */
    @Override
    public boolean hasRightChild() {
    return rightChild != null;
    }
    /**
    * Returns the number of edges in the path from the root to this node.
    */
    @Override
    public int getDepth() {
    return depth;
    }
    /**
    * Returns the number of edges in the path from the root
    * to the node with the maximum depth.
    */
    @Override
    public int getHeight() {
    final int[] height = {0};
    BinaryTreeNode<E> root = getRoot();
    root.traversePreorder(node -> {
    int depth = node.getDepth();
    if (height[0] < depth) {
    height[0] = depth;
    }
    });
    return height[0];
    }
    /**
    * Returns the number of nodes in the subtree rooted at this node.
    */
    @Override
    public int size() {
    final int[] size = {0};
    BinaryTreeNode<E> root = this;
    traversePreorder( node -> {
    size[0]++;
    });
    return size[0];
    }
    /**
    * Removes this node, and all its descendants, from whatever
    * tree it is in. Does nothing if this node is a root.
    */
    @Override
    public void removeFromParent() {
    if (getParent() != null) {
    if (getParent().getLeft() == this) {
    getParent().setLeft(null);
    } else {
    getParent().setRight(null);
    }
    setParent(null);
    }
    }
    /**
    * Returns the path from this node to the specified descendant.
    * If no path exists, returns an empty list.
    */
    @Override
    public ArrayList<BinaryTreeNode<E>> pathTo(BinaryTreeNode<E> descendant) {
    ArrayList<BinaryTreeNode<E>> pathFrom = descendant.pathFrom(this);
    Stack<BinaryTreeNode<E>> stack = new Stack<>();
    for (BinaryTreeNode<E> node : pathFrom) {
    stack.push(node);
    }
    ArrayList<BinaryTreeNode<E>> pathTo = new ArrayList<>();
    while (!stack.isEmpty()) {
    pathTo.add(stack.pop());
    }
    return pathTo;
    }
    /**
    * Returns the path to this node from the specified ancestor.
    * If no path exists, returns an empty list.
    */
    @Override
    public ArrayList<BinaryTreeNode<E>> pathFrom(BinaryTreeNode<E> ancestor) {
    BinaryTreeNode<E> currentNode = this;
    ArrayList<BinaryTreeNode<E>> pathFrom = new ArrayList<>();
    while (currentNode != null && currentNode != ancestor) {
    pathFrom.add(currentNode);
    currentNode = currentNode.getParent();
    }
    if (currentNode == null) {
    return new ArrayList<>();
    }
    pathFrom.add(currentNode);
    return pathFrom;
    }
    /**
    * Visits the nodes in this tree in preorder.
    */
    @Override
    public void traversePreorder(Visitor visitor) {
    visitor.visit(this);
    if (hasLeftChild() ) getLeft().traversePreorder(visitor);
    if (hasRightChild() ) getRight().traversePreorder(visitor);
    try {
    PrintWriter writer = new PrintWriter("tree.data");
    } catch (Exception e) {
    System.out.println("Error");
    }
    }
    /**
    * Visits the nodes in this tree in postorder.
    */
    @Override
    public void traversePostorder(Visitor visitor) {
    if (hasLeftChild() ) getLeft().traversePostorder(visitor);
    if (hasRightChild() ) getRight().traversePostorder(visitor);
    visitor.visit(this);
    }
    /**
    * Visits the nodes in this tree in order.
    */
    @Override
    public void traverseInorder(Visitor visitor) {
    if (hasLeftChild() ) getLeft().traverseInorder(visitor);
    visitor.visit(this);
    if (hasRightChild() ) getRight().traverseInorder(visitor);
    }
    }

    I am relatively experienced with Java and know the end goal of this project but I am having some difficulty in figuring out how to get going. Any help would be greatly appreciated thank you!

    submitted by /u/Scherz707
    [link] [comments]

    How can I quickly find any search terms in multiple columns in a table?

    Posted: 25 Apr 2019 03:41 PM PDT

    Let's say I have an invoice table that has a customer (first, last, address, phone, email, etc), a PO#, a reference # and other random fields.

    The client wants a single search box where they can enter in, for example, a last name and a city or a phone # and a city and it will return all the records containing any of that information. Some fields will be startswith (like first and last name) and some will be contains (like address).

    For example, I could have a PO with a customer of Mark Smith at 123 Washington Road. I could enter "smith washington" and it would find that record.

    Then, on top of that, I need to sort by any of those fields and return a total records found as well as a paged result set of the actual records.

    Currently, I have a Sql Server view that gets the 10 or so fields for every record and returns all of them to C#. In C#, I'm comparing each field in each record to see if a match is found, then I order that result set, then I take the final result set and return it.

    Please tell me there is a better way to do this?

    submitted by /u/dotnetguy32
    [link] [comments]

    [Python] Can we Pipe output of wget to Google drive?

    Posted: 25 Apr 2019 10:20 AM PDT

    As title says.

    I was using the google-api-client package for uploading and downloading local files which i was able to do successfully.

    The documentation only shows how to upload local files but i wanted to pipe my output directly.

    Can't find anything on StackOverflow :(

    Is there any way to do so?

    submitted by /u/its_shubzzz
    [link] [comments]

    If Visual Studio's object type list in a heap snapshot is empty, does that mean there's no memory leaks?

    Posted: 25 Apr 2019 10:14 AM PDT

    I'm doing a school project in C. I'm working on it on my Windows laptop right now, but I have to show it on a lab computer running Ubuntu, and use Valgrind to show there are no memory leaks.

    I tested my frees by putting a breakpoint on "return 0" and saw that if I commented them out, the unfreed stuff will show up in the "Object Type" list. Uncommented, however, there's nothing in the "object type" list.

    Does this mean my program doesn't have memory leaks?

    submitted by /u/redvibes99
    [link] [comments]

    I don't understand python.who can help me get this things very easily

    Posted: 25 Apr 2019 05:44 PM PDT

    A rugby team has 15 players. A bus company has only big busses that can carry 38passengers. Write a program that the tournament organiser can use to calculate the number of big busses that should be hired .In your solution be clear

    submitted by /u/KIMPYTHONLEARNER
    [link] [comments]

    Edit "Cascade windows" dimensions.

    Posted: 25 Apr 2019 12:07 PM PDT

    I very much dislike the dimensions of the Cascade windows tool in Windows 10 because it takes up a lot of desktop space. I do however love that I can resize all my windows and then stack them quickly and orderly. Could someone possibly solve this for me and figure out the correct procedure for locating the code so I can edit the default "Cascade" sizing? Would really appreciate it.

    Also, if there is somewhere better to ask this question don't hesitate to let me know. Thanks!

    submitted by /u/deamonz
    [link] [comments]

    Is there a site or a reddit sub where a challenge is issued to code an algorithm, then people submit their code, but *crucially* they get together to talk about it

    Posted: 25 Apr 2019 12:01 PM PDT

    I'm getting competent enough at programming now where I am submitting solutions to interesting challenges on various websites. But i'm also often seeing more efficient, or interesting takes on the same problem by other users. And I want to discuss them. These sites typically don't really facilitate anything more beyond simply checking and submitting your solution.

    Perhaps there is a reddit sub with weekly challenges or something similar, such as r/52weeksofcooking ?

    I know I could probably go to codereview.stackexchange.com and post my code and ask for advice, but it would make more sense to ask other people who are already invested in the particular task at hand.

    submitted by /u/Im_Justin_Cider
    [link] [comments]

    How exactly does Google Ads identify the context of a page for an display ad?

    Posted: 25 Apr 2019 11:53 AM PDT

    I realize that there are many factors utilized including browsing history, but in the case of the contextual google ads, how are these selected?

    I assume they are using the text, but how do they determine what keywords are best suited for a display ad?

    submitted by /u/GoingToMakeItBrahs
    [link] [comments]

    What's your favorite documentation software/platform?

    Posted: 25 Apr 2019 11:17 AM PDT

    Hey AskProgramming subreddit!

    I'm trying to implement a self-hosted documentation site to allow our user community (website users, support, developers) to see information like Release notes, documentation for modules, etc without spending a buttload of money for a seat based doc software. I'm looking to self host on a VM.

    Preferably I'd like a recommendation that is fairly regularly maintained (or proven to be stable with scale). Does anyone have good recommendations for a software/platform like this? I'd love to know why you also recommend the software so I can bring the pros/cons back to the rest of my team! Thanks a bunch in advance!

    submitted by /u/PaxDev
    [link] [comments]

    Looking for Filemaker pro alternatives with multiuser support

    Posted: 25 Apr 2019 06:25 AM PDT

    Hello

    I am looking for a program like filemaker pro that has a database and graphic interface like form view where i can see and print any entry like a customer history. I also need to access the file from different computers at once like google sheets. Filemaker pro cloud server is way too expensive.

    submitted by /u/isyerindereddit
    [link] [comments]

    i cant figure out whats wrong with my code and my debugger is not working.

    Posted: 25 Apr 2019 04:26 AM PDT

    https://drive.google.com/file/d/1B7UiF1v9vSDL26rgFmFfxmuM94U-1bE8/view?usp=sharing

    i did this question that i was able to find somewhere and it does compile without any errors but i dont get any output and my debugger is not working so i cant even figure out whats wrong.

    the link above contains both the question and my answer to it using c++, if anyone can help me figure out what i did wrong that would be great.

    submitted by /u/riddler2012
    [link] [comments]

    Socket

    Posted: 25 Apr 2019 03:15 AM PDT

    Is http polling under the hood of socket protocol or socket is made by pure tcp/ip?

    submitted by /u/vordankarmir
    [link] [comments]

    Trying to automatically generate passwords for every combination possible in an array.

    Posted: 25 Apr 2019 02:37 AM PDT

    I have a video game, each possible save state should have a password that lets you load it.
    Since there's potentially thousands or tens of thousands of possibilities, instead of me manually creating passwords for each possible order of this array.

    Instead I'd want an algorithm that does it for me.

    For example.

    [0, 1, 2, 3, 4]
    Is ADWF
    [0, 2, 3, 4, 1] Is EETU

    I don't care about the letters being a specific order, just that they match up with every possible save state.

    That way when a player chooses to "save" the game. They also get a passcode, this allows them to load that state on any other game, without needing the memory file of that save.

    I'm not really asking people to do my work for me. I am just wondering what algorithm or logic is required for me to do this.

    Edit: Nvm I figured it out I'm dumb. I just iterate through every possibility, and simply have for each iteration, to randomly generate text that hasn't been used before. And save that text inside its own key value) {[0, 2, 3, 4, 1] = EETU} Upon entering a value on the password screen, I will query to find a matching value and then return the key it belongs to.

    submitted by /u/Silver-Monk_Shu
    [link] [comments]

    How to edit already stored user data php mysql

    Posted: 25 Apr 2019 02:36 AM PDT

    Editing/updating data in server is unexceptional. In daily basis, we make use of Facebook post edit feature, changing password, name, picture, age and much more.

    continue reading...

    submitted by /u/superguideblog
    [link] [comments]

    Dynamic C Mystery - Recovering Legacy Code

    Posted: 24 Apr 2019 10:19 PM PDT

    I have a bit of a mystery on my hands:

    I was handed an integrated control device whose original developers left our working group long before my time. I have been asked to port the exact functionality of this control device to a modern platform (like Arduino) so that my system can be a drop in replacement for the existing controller.

    Only one problem: the source code is gone! All that I have to work with is the compiled firmware on the device. Thankfully, I have been able to force the microcontroller (an old Rabbit 2000 series) to regurgitate the contents of its flash modules and convert the resulting dump into a .bin file. I also know that the development language is Dynamic C (a C-like language for Rabbit microcontrollers).

    I am struggling with the decompilation process. I theoretically know all of the information required to decompile, but I have not been able to find a decompiler from the binary to Dynamic C. I know the exact processor and microcontroller that the code was run on, and I even have the IDE.

    At the end of the day, I need to learn the handshaking and data transmission routine between the controller and the many external devices that the current system uses so that I can mirror the controller on a different platform. I tried sniffing network packets, but there is far too much traffic between these devices to determine a meaningful procedure (as far as I know).

    Does anyone have advice on decompiling Dynamic C from a .bin file? Thanks!

    submitted by /u/KentAshfield
    [link] [comments]

    No comments:

    Post a Comment