• Breaking News

    Sunday, February 25, 2018

    Need help with finding a phrase in a string in python Ask Programming

    Need help with finding a phrase in a string in python Ask Programming


    Need help with finding a phrase in a string in python

    Posted: 25 Feb 2018 02:58 PM PST

    I want to open a text file and see if a word or phrase is in a text file that belongs to a list and return it.

    name = str(entry_field1.get()).lower() counter = 0 for word in name.split(): print(word) 

    The procedure here works for a word. How do I make it work for a phrase? for example, if have ['great expectations'] and if the text contains "I have great expectations from you", this would return -1 as 'great' and 'expectations' are two different words while 'great expectations' is considered a single string rather than a phrase,

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

    Prevent navigation from overlapping with the logo

    Posted: 25 Feb 2018 04:11 PM PST

    When I change the size of my browser window, the navbar overlaps with the logo: https://i.imgur.com/YcxTFlk.png

    Live example: http://crds.co/

    Any ideas how I can prevent this from happening?

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

    How to make universal keyboard shortcuts to control pc?

    Posted: 25 Feb 2018 09:39 PM PST

    Is there a way to make keyboard shortcuts that give me complete control? For example, I can end a specific process or launch specific web pages? If not, are there any similar tools out there?

    My goal is to map my own keyboard shortcuts to do very specific tasks (i.e. ctrl+7 to open a specific file or url). Does anyone know any tools to do this? My goal is to get complete control, but if that's not possible I'll take anything else too (like shortcuts for windows or firefox only).

    This sounds like something that would work better on Linux but ideally I would like to do this on Windows 10. Thanks.

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

    C# weird vector problems.

    Posted: 25 Feb 2018 05:39 PM PST

    I made my own Vector class in C# for a game I'm making. It contains a normalize() method that shrinks the vector to a length of 1 and a scale() method that multiplies the x & y values by a scalar.

    For some reason this works:

    Vector temp = velocity.clone(); temp.normalize(); temp.scale(magnitude); velocity = temp; 

    But this doesn't:

    velocity.normalize(); velocity.scale(magnitude); 

    Obviously normalize() and scale() both work because they work in the first example, but for some reason, not in the second. They don't produce the same result. Is there a quirk with C# that I'm missing? I've been staring at this for the last 30 minutes with no clue what's going on, so any help is appreciated.

    I'm fairly new to the language so that's probably why it's not working for me.


    EDIT: After some experimenting, I've confirmed that normalize() definitely isn't the issue.

    velocity.normalize(); vel = new Vector(vel.x * magnitude, vel.y * magnitude); 

    The above code works but this does not:

    velocity.normalize(); vel.scale(magnitude); 

    scale() is essentially:

    this.x *= magnitude; this.y *= magnitude; 

    So I have no idea why it won't work. I suspect there's something about creating a new object that fixes the problem. But I'd like to not do that because that's a lot of objects per second. I'd rather just modify an existing object instead.

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

    C#/SQL Server - Comparing one string from C# to three columns from the same table in an SQL database?

    Posted: 25 Feb 2018 04:38 PM PST

    The title explains most of it. I have three identification devices, I get a similar but unique string from each one, if one of the strings matches a field in the table then set the labels in the C# form to the data in the SQL table

    I want to create one method to compare the received string to all three columns in the DB table, instead of making three separate methods or forms.

    Here's my C#/SQL Command:

     public UserPanel(String value, SqlConnection con) { InitializeComponent(); String idValue = value; SqlCommand command = new SqlCommand("Select * from db2 where BarcodeID = '" + idValue + "'",con); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); // userName_Label.Text = reader["dbo2.fullName"].ToString(); userName_Label.Text = reader.GetString(1).ToString(); userGender_Label.Text = reader.GetString(2).ToString(); UserOccupation_Label.Text = reader.GetString(3).ToString(); userCard_Label.Text = reader.GetString(4).ToString(); userFingerprint_Label.Text = reader.GetString(5).ToString(); userBarcode_label.Text = reader.GetString(6).ToString(); } else { MessageBox.Show("ID not found!"); } } 

    So if I had CardID and FingerprintID fields in the table, how would I add them in the command string to be compared to the idValue?

    Sorry for the bad english, it's not my first language.

    I know doing each identification process in a different method or form might be better or more secure but I want to see if this is possible and apply it.

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

    I want to create a REST API for the purpose of serving up configuration data to various applications (and possibly updating data in the future). How do I implement authentication?

    Posted: 25 Feb 2018 12:39 PM PST

    I want to limit access to expected client hosts (request.client.hostname?), and to expected clients on those hosts (secret key?). I want to avoid authenticating via a username/password. What is the recommended approach? Not to influence people, but I've been leaning toward OAuth.

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

    Opaque Data Types And Pointers

    Posted: 25 Feb 2018 08:10 PM PST

    Sometimes in C headers I see something like

     typedef struct Stack_T *Stack_T; extern Stack_T Stack_new (void); extern int Stack_empty(Stack_T stk); extern void Stack_push (Stack_T stk, void *x); extern void *Stack_pop (Stack_T stk); extern void Stack_free (Stack_T *stk); 

    Why would anyone use a typedef like that over a typedef like

     typedef struct Stack_T Stack_T; 
    submitted by /u/nanoman1
    [link] [comments]

    Is coding boot camp worth it? Which is one is better? Why?

    Posted: 25 Feb 2018 03:05 PM PST

    Creating a unsorted array with randomised numbers (no duplicates)

    Posted: 25 Feb 2018 05:45 PM PST

    I'm trying to create a int array where all the numbers are unique, but in no particular order. The highest number is whatever the length of the array is.

    int arr4[] = new int[100000]; Random rand = new Random(); for (int x = 0; x < arr4.length; x++) { // set 4 n = rand.nextInt(99999) + 0; if (!(Arrays.asList(arr4).contains(n))) { arr4[x] = n; } } 

    In this example, i have an array with a length of 100 000. I want the numbers 0 to 99 999 in a random order. However, the array is still producing duplicates.

    Note: I need to do this without arraylists or sets

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

    How does renting a server work? I need to use software that's very very ram intensive.

    Posted: 25 Feb 2018 10:09 AM PST

    I'm not familiar at all with renting and using virtual servers. How does it work? Do I simply rent one, install my software on it and run it in browser (or desktop app)? The software I need to use runs complex simulations and it needs a ton of ram to work well. Ideally, I would like a server with 256gb ram, but that might be too costly.

    edit: I think 128gb may be enough.

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

    How to move between frames/classes after clicking a button in java gui?

    Posted: 25 Feb 2018 11:37 AM PST

    (AdminLogin is my second class which i want to move to after clicking a button from WelcomePage class). When i try to run there's an error at "admin.setVisible(true)". What did i do wrong?

    /** * Launch the application. */ 

    public class WelcomePage { private JFrame frame;

    public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { WelcomePage window = new WelcomePage(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public WelcomePage() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.getContentPane().setBackground(Color.BLUE); frame.setBackground(Color.BLUE); frame.setBounds(100, 100, 495, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); JLabel lblOnlineElectionManager = new JLabel( "Welcome To Online Election Manager"); lblOnlineElectionManager.setForeground(Color.WHITE); lblOnlineElectionManager.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblOnlineElectionManager.setBounds(100, 11, 284, 47); frame.getContentPane().add(lblOnlineElectionManager); JLabel lblLoginAs = new JLabel("Login as"); lblLoginAs.setForeground(Color.WHITE); lblLoginAs.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblLoginAs.setBounds(195, 84, 77, 36); frame.getContentPane().add(lblLoginAs); btnAdmin = new JButton("ADMIN"); btnAdmin.setFont(new Font("Tahoma", Font.PLAIN, 16)); btnAdmin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() == btnAdmin) { AdminLogin admin = new AdminLogin(); frame.setVisible(false); admin.setVisible(true); } } }); btnAdmin.setBounds(45, 192, 117, 36); frame.getContentPane().add(btnAdmin); JButton btnVoter = new JButton("VOTER"); btnVoter.setFont(new Font("Tahoma", Font.PLAIN, 16)); btnVoter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { } }); btnVoter.setBounds(267, 192, 117, 36); frame.getContentPane().add(btnVoter); } 

    }

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

    SQL Help

    Posted: 25 Feb 2018 09:14 AM PST

    Hey Reddit!

    Having trouble with this SQL query i've made.

    I have two tables, one with transaction data and one with categories. The categories table holds an id and name. The id being a primary key.

    The transaction table some columns about name, amount etc and three columns are primary_category, secondary_category and tertiary_category which are foreign keys from the category table.

    I'm trying to join them to resolve the category ids to their respective names. I have this which works for one...

    select transactions.tra_id, transactions.date,transactions.place,transactions.amount,transactions.balance,transactions.type, category.name AS primary_category, category.name AS secondary_category, category.name AS tertiary_category from transactions left join category on transactions.primary_category = category.cat_id 
    submitted by /u/MetalCactuar
    [link] [comments]

    Is OOP inherently bad?

    Posted: 25 Feb 2018 06:02 AM PST

    Originally was going to post this in /r/changemyview but I wasn't sure whether a non-programming sub would be appropriate. I'm a developer who mainly works with .NET desktop applications and I love OOP. Recently I've been reading a lot of "opinion pieces" where the author states object-oriented programming is a bad paradigm that should just disappear. In all of these pieces the author seems to simply have bad experience with bad code bases - I can't see anything negative specific to OOP or object-oriented design.

    Are there any real reasons OOP should be specifically avoided or are these writers just ignorant of their situation?

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

    Question for ambitious people: How can I create multiple background in Unity?

    Posted: 25 Feb 2018 02:12 PM PST

    Hi

    I'm noob in this place, hope I don't make a mistake posting.

    First of all apologise my English writing. :)

    I can't find anything about it, or at least not as accurate .

    How can I manage multiple backgrounds?

    I'm trying to make a running game. In that game i want to change the background after every 120 seconds or 30 points, like in game like "Jetpack joyride" or "Flappy bird"(day and night) .

    How can i do that? Any ideas..??

    Generally, I have 6 backgrounds images.

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

    How to divide between exception source?

    Posted: 25 Feb 2018 06:28 AM PST

    What is better programming practice?

    try: open(file) #throws fileNotFoundException open(anotherFile) #throws fileNotFoundException except FileNotFoundException: some Code 

    or should I put every open() function inside there own try blocks to better determine which exactly triggered my exception like:

    try: open(file) except FileNotFoundException: some code try: open(anotherFile) except FileNotFoundException: someCode 

    I think for reading the code the first is better but the second would indicate where it exactly catched the exception if it was in the first block or the second

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

    Where can I learn how to write functions that cut branches, add children, look up ancestors and otherwise interact with trees?

    Posted: 25 Feb 2018 02:14 AM PST

    I am some way towards writing a chess AI and I want to include the three-fold repetition rule. This means that the children of a node (available moves) will now be a function of all its direct ancestors. I can also rewrite the playMove(str) function to just do some big branch deletes (saving computation time on the next move).

    The problem is I don't really know how to work with trees: delete branches, look up ancestors, write children. What is a good resources for improving my understanding of trees (and practical manipulation of data types in general)?

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

    What language for PostgreSQL backed web service/api running under Linux?

    Posted: 25 Feb 2018 04:43 AM PST

    I am planning to write my own automated central heating system, mainly as a learning experience.

    I have an ESP2866 and a Pi3 which I will use for development purposes. I plan to start by getting the ESP2866 to submit temperature readings to a service running on the Pi at regular intervals, rather than have a service on the Pi polling the ESP2866. I want to get the latter to last for weeks if not months when running off a battery as there isn't a power source in the optimum place for a temp sensor in the main part of the house.

    The service on the Pi would store the received values in the PostgreSQL DB and I would probably build a web app to display them.

    Evolving the idea over time, I would add another ESP2866 with a relay to turn the heating on and off and add the facility to create schedules to the web app on the Pi, which are then used with the most recent temperature data to determine whether the heating should be off or on.

    The only thing I am fixed on is using PostgreSQL as I could do with gaining some more experience of it for work. I would like to use REST APIs where appropriate for the same reasons. The web app for instance, should use the REST API and at a later date I will probably look at building a web app too.

    Thanks in advance for your thoughts .bs

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

    How to check time conflicts in this situation

    Posted: 25 Feb 2018 12:29 AM PST

    I have a sqlite database of classes that contains the courseID, days they occur (ex: Mon, Fri) and Time (11-12:30). I also have a ArrayList of currently enrolled classes (courses). Now here is my issue, I am trying to see if a time conflict will occur if you enroll in a specific course. I am not sure how to go about this in Java as the dates and times are in text so I am stuck. If you need anymore information please let me know.

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

    I’m looking for a simple script to scour 2 websites for information. Can someone write it for $? PM for details.

    Posted: 24 Feb 2018 10:41 PM PST

    No comments:

    Post a Comment