• Breaking News

    Friday, April 27, 2018

    Using boolean variables in C Ask Programming

    Using boolean variables in C Ask Programming


    Using boolean variables in C

    Posted: 27 Apr 2018 12:52 PM PDT

    What is the proper way to use boolean variables in C.

    • should I use _Bool or bool from stdbool.h
    • when using stdbool.h shoud I set the variable to 0 and 1 or to true and false ?

    Actually is it even "good design" to use booleans in C rather than integers?

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

    Is there a way to make video games bot in nodejs?

    Posted: 27 Apr 2018 09:13 PM PDT

    I want to make a bot like in this video where the the bot calculated the numbers on the screen and respond according to all the logic based on the screen shots.

    https://www.youtube.com/watch?v=lfk_T6VKhTE

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

    Advice on flattening styling layers?

    Posted: 27 Apr 2018 09:02 PM PDT

    I'm building a fast, specialized HTML processor in C which converts basic HTML into style instructions. I'm already perfectly fine extracting all tags into one array and storing their effective range on the resultant (human displayed) text. This, for example, is what I'm printing out from my tokenizeHTML method:

    TAG: i starts at 11 ends at 26 TAG: b starts at 6 ends at 28 TAG: a href="https://test.com" starts at 28 ends at 36 TAG: p starts at 28 ends at 36 

    The resultant, human displayed text (which all the above indexes are anchored to) is: Plain bold bold and italic. Wikitest

    The original HTML is: Plain <b>bold <i>bold and italic</i>. </b><p><a href=\"https://test.com\">Wikitest</a></p>

    The issue is that the styling system I'm using only lets me have one layer of formatting, so no nesting allowed. I'm trying to think of a good, high speed way to make this into a simplified, 1D range like as follows:

    6-11: bold

    11-26: bold+italics

    26-28: bold

    28-36: p-block+link

    I'm an int array with a length the size of the total text range would work if I gave each text format a unique bit. I could then perform a pass over the array for each formatting range and apply the bitmask that corresponds to the tag. I'd then of course need to reinterpret all the bitmasks.

    Any thoughts on how I could be more efficient? I'm trying to make this super fast and so every little bit is important!

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

    ASAP Java Assistance, Willing to pay

    Posted: 27 Apr 2018 07:28 PM PDT

    halfway completed through a basic menu program, desperately need help since i've hit a wall. Willing to pay LTC / ETH for assistance with completion of this program.

    What is left: Struggling to catch output statements to print, configuration of sales tax and regular pricing, action/itemlistener and need help with borderlayout/panels. Msg me directly or post here if interested in helping. will be fairly compensated for time and effort.

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

    Weird issue with file i/o

    Posted: 27 Apr 2018 06:52 PM PDT

    Hi everyone, I've run into a really odd problem and was hoping someone has seen something similar. I'm working on an assignment that uses file i/o. My current function is adding a line to the end of my file (Adding an item to a food menu). My program reads the file when I run it and should update the information to account for the new item that was added.

    When I run the function to add a line and re-run the program, it does not appear that the line was accounted for when reading the file when I run the program. HOWEVER, if I open the file (like physically open the .txt file in terminal) and save it, the program runs perfectly as intended and notices the update.

    Why could it be that when I open the text file in terminal before running, it makes the program function properly.

    I am using C++ Here is an example of a run of the program https://imgur.com/a/LsLBECA

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

    Display empty star rating if numerical average is 0

    Posted: 27 Apr 2018 02:35 PM PDT

    In my Wordpress plugin, visitors can leave a star rating on the post as comment feedback. This star rating is shown elsewhere as a post archive table, providing an overview of data on each post (author/rating/etc).

    It is working as expected, except (a) the posts without any comments show nothing and (b) the stars are a bit too large. The math in this snippet s throwing me a bit, where I am trying to figure out how to show 5 empty stars for posts with no comments, and make the stars a bit smaller.

    Any help would be appreciated!

    function get_star_rating( $id ) { $stars = ''; $average = get_average_rating( $id ); for ( $i = 1; $i <= $average + 1; $i++ ) { $width = intval( $i - $average > 0 ? 20 - ( ( $i - $average ) * 20 ) : 20 ); if ( 0 === $width ) { continue; } $stars .= '<span style="overflow:hidden; width:' . $width . 'px" class="dashicons dashicons-star-filled"></span>'; if ( $i - $average > 0 ) { $stars .= '<span style="overflow:hidden; position:relative; left:-' . $width .'px;" class="dashicons dashicons-star-empty"></span>'; } } $star_rating = '<p class="average-rating">' . $stars . '</p>'; return $star_rating; } 
    submitted by /u/DinnerMilk
    [link] [comments]

    What language/skill do you think should be learned when learning to program?

    Posted: 27 Apr 2018 05:26 PM PDT

    also, is there anything you wished you had learned sooner, like what you use for a job?

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

    Is there a text editor that can represent its code as a diagram?

    Posted: 27 Apr 2018 05:25 PM PDT

    Diagrams / flow charts are great for visualizing what a program does and the pieces that do each thing.

    However, the only diagrams I've heard of are separate files from the code itself, meaning you need to update the code *and* the diagram each time you make a change.

    Is there a text editor that is smart enough to represent code as a diagram? This way, the code and the diagram would always be in sync. Ideally, I'd also be able to add blocks visually, then "zoom in" to them on a text level to fine-tune them.

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

    template function that acts different depending on which type of vector is passed to it?

    Posted: 27 Apr 2018 01:19 PM PDT

    I'm writing a program for class where i have to use a single template function that sorts the vector thats passed to it then returns the sorted vector.

    That part i understand, i know how to sort all the primitive data types and i know how to use template functions, what i DON'T know how to do is make the function KNOW which type of vector was passed to it (vector<int>, vector<double>, vector < char>, vector < string> .

    is there any way to implement like a "if vector V is a char vector..." or something? this is c++ btw

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

    Painting text on a canvas, and the after effects

    Posted: 27 Apr 2018 09:17 AM PDT

    So I was thinking about how applications like web browsers, word processors, etc paint text on a canvas which is pretty straightforward. But I then started to wonder how the copy/paste function works. When text is rendered onto a web browser canvas, for instance, it is now a graphic item. So how does highlighting this text work? I suppose this is really no different than any GUI which implements textboxes for example. It seems there must be underlying map of sorts to help the UI find and locate these objects, because even the act of selecting text must result in a repaint of the canvas.

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

    Can you figure out this algorithm?

    Posted: 27 Apr 2018 04:28 PM PDT

    I posted on programminghelp and it didn't get a response. I have a simple program for class due at midnight that i have to create a simple sorting algorithm using 1 stack, 1 queue, and outputting to a vector.

    It has to be a template function and work for all primitive data types.

    i got it to correctly get the first and last element correct but the ones inside aren't.

    Please help

    template<typename T>

    vector<T> mysort(vector<T> data)

    {

    vector<T>outvector;

    stack<T> mystack;

    queue<T> myqueue;

    for (int i = 0; i < data.size(); i++)

    { mystack.push(data[i]);

    }

    for (int i = 0; i < data.size(); i++)

    {

    T min = mystack.top(); mystack.pop(); while (!mystack.empty()) { if (min > mystack.top()) { myqueue.push(min); min = mystack.top(); mystack.pop(); } else { myqueue.push(mystack.top()); mystack.pop(); } } outvector.push_back(min); for (int i = 0; i < myqueue.size(); i++) { mystack.push(myqueue.front()); myqueue.pop(); } 

    }

    return outvector; }

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

    Best way to monitor changes to 1m+ profiles via API?

    Posted: 27 Apr 2018 11:38 AM PDT

    I'm building a vehicle data tracker for my dad's small car lot, essentially just for fun, something for us to watch/play with together.

    We've quickly piled up more vehicle profiles than we (read: our software) can handle. Originally, the process was simple:

    1. Get the 100 oldest/most outdated vehicle profiles and refresh/fetch their info from the API
    2. Compare this data to the old data
    3. Log any changes that a vehicle profile underwent

    This worked well for the first few thousand vehicles, but it's gotten to the point where it basically won't run anymore. The API we use only allows 100 profiles to be fetched at a time. I could run this task back to back to back, but that just seems wrong.

    The issue is essentially finding the most efficient way of watching a URL and waiting for the output to change.

    I've never built anything of this nature, just curious what the best way to go about something like this would be. Is it a matter of raw computing power that I don't have, or is there an inherent flaw in my approach?

    I'm guessing the latter, thanks!

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

    Whats wrong with my sort algorithm?

    Posted: 27 Apr 2018 03:01 PM PDT

    I'll leave my code at the end because its lengthy. My sort algorithm is supposed to sort everything from smallest to biggest (don't worry about main, i've got some weird requirements for my assignment, focus on the sort function)

    It sorts the first 2, and then gives me gibberish for the rest.

    so if i pass it a vector of 10 integers in random order, it successfully gives me the first 2 smallest then breaks down.

    i've never seen that. usually if an algorithm is broken it breaks after the first loop, its weird it does 2 successful loops and then breaks.

    here's the code

    include <iostream>

    include <string>

    include <vector>

    include <stack>

    include <queue>

    using namespace std;

    template<typename T>

    vector<T> mysort(vector<T> data)

    { vector<T>outvector;

    stack<T> mystack; queue<T> myqueue; for (int i = 0; i < data.size(); i++) { mystack.push(data[i]); } for (int i = 0; i < data.size(); i++) { T min = mystack.top(); mystack.pop(); while (!mystack.empty()) { if (min > mystack.top()) { myqueue.push(min); min = mystack.top(); } if (min <= mystack.top()) { myqueue.push(mystack.top()); } mystack.pop(); } outvector.push_back(min); for (int i = 0; i < myqueue.size(); i++) { mystack.push(myqueue.front()); myqueue.pop(); } } return outvector; 

    }

    int main()

    { int intarray[10]= { 1,5,8,16,60,4,2,17,6,30 }; double Intarray[10]; vector<double> intvector; vector<double> outintvector; vector<int>finalintvector; for (int i = 0; i < 10; i++) { Intarray[i] = (double)intarray[i]; intvector.push_back(Intarray[i]); }

    double doublearray[10] = { 7.0, 41.5, 22.7, 9.32, 49.11, 55.2, 31.01, 12.13, 99.99, 48.16 }; vector<double> doublevector; vector<double> outdoublevector; for (int i = 0; i < 10; i++) { doublevector.push_back(doublearray[i]); } char chararray[10] = { 'b','w','v','m','z','e','c','k', 'd', 'g'}; vector<string> charvector; vector<string>outcharvector; vector<char>finalcharvector; for (int i = 0; i < 10; i++) { char mychar = chararray[i]; string mystring; mystring = mychar; charvector.push_back(mystring); } string stringarray[10] = { "longing", "rusted", "furnace", "daybreak","seventeen", "benign", "nine", "homecoming", "one", "freightcar" }; vector<string> stringvector; vector<string>outstringvector; for (int i = 0; i < 10; i++) { stringvector.push_back(stringarray[i]); } outintvector = mysort(intvector); for (int i = 0; i < 10; i++) { int x = outintvector[i]; finalintvector.push_back(x); } outdoublevector = mysort(doublevector); outcharvector = mysort(charvector); for (int i = 0; i < 10; i++) { string x = outcharvector[i]; char y = x[0]; finalcharvector.push_back(y); } outstringvector = mysort(stringvector); cout << "Here is the sorted INT vector: " << endl; for (int i = 0; i < 10; i++) { cout << finalintvector[i] << endl; } cout << "Here is the sorted DOUBLE vector: " << endl; for (int i = 0; i < 10; i++) { cout << outdoublevector[i] << endl; } cout << "Here is the sorted CHAR vector: " << endl; for (int i = 0; i < 10; i++) { cout << finalcharvector[i] << endl; } cout << "Here is the sorted STRING vector: " << endl; for (int i = 0; i < 10; i++) { cout << outstringvector[i] << endl; } 

    }

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

    Using Telnet in C++ (Linux)

    Posted: 27 Apr 2018 07:24 AM PDT

    I want to write a program that runs telnet commands and I for the life of me can't seem to find what the include lines and commands should be.

    I have telnet installed on my CentOS7 VM and can use it in a terminal but is there a guide to use the library in C++?

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

    Wondering if my idea is possible and what it would take to program such a thing

    Posted: 27 Apr 2018 10:31 AM PDT

    Not sure if this is the right place to ask, but no hurt in trying.

    I'm looking to have a program or indicator developed that uses data on trading charts, specifically the site Trading View.

    There is an indicator on Trading View called the TTM Squeeze. What I'd want to do with my program is be able to find any stock or cryptocurrency that is currently in a squeeze. Here is a quick look at the TTM Squeeze indicator on Trading View and how it works.

    As you can see, when a stock or cryptocurrency is in a squeeze, there are red dots leading up to price action. Two green bars after a squeeze indicate momentum up, two pink bars after a squeeze indicate momentum down.

    So yeah, if there was some way I could create a scanner that identifies which stocks and cryptocurrency are in squeezes, that would be great! (at various time frames: 1 week, 1 day, 1 hour, 4 hour, 2 hour, 1 hour, 45 minutes, 30 minutes, 15 minutes)

    Let me know your thoughts on my idea and if anything like this would be possible. Appreciate it.

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

    Azure Service Fabric Plugin for Eclipse no longer available?

    Posted: 27 Apr 2018 08:53 AM PDT

    The instruction on How to install the SF plugin has this link http://dl.microsoft.com/eclipse/azure/servicefabric to install the plugin. But it is empty, is this no longer supported?

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

    Socket Linux Help

    Posted: 27 Apr 2018 08:15 AM PDT

    I am new to using the sys/socket library in linux and have a few questions. There is a server that I am trying to connect with to request information. Every example online seems to have the same 3 examples all stolen from one another and no one seems to break it down easily enough (at least for me!).

    I want to open a connection on some IP address and port no. then I would like to send a plain text command and read the output.

    I am doing the following:

    sock = socket(127.0.0.1, SOCK_STREAM,0); connect(sock, 127.0.0.1, 32) 

    it says that I have too many decimals points in the integer for IP address but what notation should I be using? Also, is this the correct way to set up a connection using socket? Where do I say which port to use?

    Thanks!

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

    ALSA MMAP Access help

    Posted: 27 Apr 2018 01:55 AM PDT

    Hello everybody, I'm currently learning to use the Linux ALSA. As an exercise I wrote a program to record audio. Basic recording works, as well as the use of snd_pcm_mmap_readi. Now im struggeling with using the "full" mmapped access. You can find the code here: https://github.com/LLKJS/DMAaudio It needs libasound2-dev installed to compile.

    My problem is in file rec.c in the function read_mmap(), I guess the write access is wrong but I'm not sure how to do this correctly.

    I'd highly appreciate any help (and gerneral hints on how to improve this code;) )

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

    URGENT: fix my algorithm before a deadline

    Posted: 27 Apr 2018 04:05 PM PDT

    I posted a while ago but the thread died. I have till midnight to submit this algorithm. i created a sorting algorithm for class and needed to use a template function, exactly 1 stack, and exactly one queue. Don't pay too much attention to main, but my algorithm gives me correct first and last in each sort but the middle is all messed up. please help

    include <iostream>

    include <string>

    include <vector>

    include <stack>

    include <queue>

    using namespace std;

    template<typename T>

    vector<T> mysort(vector<T> data)

    {

    vector<T>outvector; stack<T> mystack; queue<T> myqueue; for (int i = 0; i < data.size(); i++) { mystack.push(data[i]); } for (int i = 0; i < data.size(); i++) { T min = mystack.top(); mystack.pop(); while (!mystack.empty()) { if (min > mystack.top()) { myqueue.push(min); min = mystack.top(); mystack.pop(); } else { myqueue.push(mystack.top()); mystack.pop(); } } outvector.push_back(min); for (int i = 0; i < myqueue.size(); i++) { mystack.push(myqueue.front()); myqueue.pop(); } } return outvector; 

    }

    int main()

    {

    int intarray[10]= { 1,5,8,16,60,4,2,17,6,30 }; double Intarray[10]; vector<double> intvector; vector<double> outintvector; vector<int>finalintvector; for (int i = 0; i < 10; i++) { Intarray[i] = (double)intarray[i]; intvector.push_back(Intarray[i]); } double doublearray[10] = { 7.0, 41.5, 22.7, 9.32, 49.11, 

    55.2, 31.01, 12.13, 99.99, 48.16 };

    vector<double> doublevector; vector<double> outdoublevector; for (int i = 0; i < 10; i++) { doublevector.push_back(doublearray[i]); } char chararray[10] = { 'b','w','v','m','z','e','c','k', 'd', 'g'}; vector<string> charvector; vector<string>outcharvector; vector<char>finalcharvector; for (int i = 0; i < 10; i++) { char mychar = chararray[i]; string mystring; mystring = mychar; charvector.push_back(mystring); } string stringarray[10] = { "longing", "rusted", "furnace", 

    "daybreak","seventeen", "benign", "nine", "homecoming", "one", "freightcar" };

    vector<string> stringvector; vector<string>outstringvector; for (int i = 0; i < 10; i++) { stringvector.push_back(stringarray[i]); } outintvector = mysort(intvector); for (int i = 0; i < 10; i++) { int x = outintvector[i]; finalintvector.push_back(x); } outdoublevector = mysort(doublevector); outcharvector = mysort(charvector); for (int i = 0; i < 10; i++) { string x = outcharvector[i]; char y = x[0]; finalcharvector.push_back(y); } outstringvector = mysort(stringvector); cout << "Here is the sorted INT vector: " << endl; for (int i = 0; i < 10; i++) { cout << finalintvector[i] << endl; } cout << "Here is the sorted DOUBLE vector: " << endl; for (int i = 0; i < 10; i++) { cout << outdoublevector[i] << endl; } cout << "Here is the sorted CHAR vector: " << endl; for (int i = 0; i < 10; i++) { cout << finalcharvector[i] << endl; } cout << "Here is the sorted STRING vector: " << endl; for (int i = 0; i < 10; i++) { cout << outstringvector[i] << endl; } 

    }

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

    Would like a way to access a property created on the initial thread of a program using async/await pattern in C# from any subsequent thread, similar to a request or thread identifier (code called from both Asp.Net API and console app)

    Posted: 26 Apr 2018 10:23 PM PDT

    I have a program that I need to resolve what the current transaction is in a lot of the end methods, we call a lot of these and it would be really helpful to allow the database repository methods to resolve a couple of minor things (username to allow data audits for instance).

    I can put a property of an interface type defining a method that can do that on the data manager, and then create a class per api or app to resolve the username accordingly.

    This works well but I'm using the httpcontext for the api and it seems to get dropped whenever we use a bunch of threads in parallel, and from what I've seen it isn't threadsafe anyway. (I know iis usually handles the parallel threads for you so we don't need to do this, but many methods are also called from worker applications so it's very helpful to make them parallel)

    It's frustrating because it works for a while, but eventually is dropped - I can see a .ConfigureAwait(false) would do this, but I've eliminated all these from our codebase. It's possible this is in a library we're calling or simply in the nature of using Task.WhenAll or the ParallelForEachAsync library.

    A custom SyncronizationContext gets dropped even faster (after the first await in a method).

    Is there any way to set up a property to track the request without putting a parameter on every repository and entity manager method in the system?

    Additional code, the session is set in the globas.asax.cs and called before database calls in the repository - the problem is currently in the GetSessionId:

    ISessionInformation interface:

    public interface ISessionInformation { /// <summary> /// Gets a transaction id for the current set of operations, usually a webjob or api call /// </summary> /// <returns></returns> Guid GetSessionId(); /// <summary> /// Returns a username (or string such as "worker") indicating the user that initiated an operation /// Used in combination with common properties /// </summary> /// <returns></returns> string GetUsername(); } 

    API Implementation of interface:

     /// <summary> /// Session information for transactions and common properties /// </summary> public class SessionInformation : ISessionInformation { string _requestIdKey = "RequestId"; public Guid GetSessionId() { if (HttpContext.Current?.Items == null) { throw new Exception("Lost http context"); } if (HttpContext.Current?.Items?.Contains(_requestIdKey) ?? false) return (Guid)HttpContext.Current.Items[_requestIdKey]; var id = Guid.NewGuid(); HttpContext.Current.Items.Add(_requestIdKey, id); return id; } public string GetUsername() { if (HttpContext.Current?.User != null) { var user = HttpContext.Current?.User?.GetCurrentUserClaims(); if (user?.EmailAddress != null) return user.EmailAddress.ToString(); } return ""; } } 
    submitted by /u/MrHall
    [link] [comments]

    Javascript Array help

    Posted: 27 Apr 2018 12:23 AM PDT

    I'm having HUGE HEADACHE trying to solve this. In an online made up store, the following are product SKU names, the quantity of each item ordered, and the location of the item in the warehouse. It needs to output the product SKU name and quantity only.

    INPUT:

    HL-OH-F1504P-CH-AM (1) <br>2EX2-4 / 2G-7</br> HID-LED-9004-LB (2) <br>2M-2_5</br>FMK (1) <br>2ND FL</br> 

    OUTPUT:

    HL-OH-F1504P-CH-AM (1) HID-LED-9004-LB (2) FMK (1) 

    I'm so lost as how to delete all the fluff in between the product SKU's!!! Can anyone help?

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

    No comments:

    Post a Comment