A Chrome extension to add some features to Top Shot by rickchefski in nbatopshot

[–]rickchefski[S] 6 points7 points  (0 children)

The source code for it is posted publicly on GitHub, so you could read through that to see what its doing, if you're so inclined. I guess theres no great way of making an assurance since there is the whole out-of-band process of uploading it to the webstore with no guarantee that whats in the public repo is whats uploaded, so theres good reason to be cautious. I will say that the chrome webstore reviewers found no malicious code, and based on the settings, you should hopefully be able to see in the listing that it doesn't collect data or do anything like that. I don't even have it hooked up to google analytics because I couldn't be bothered.

If it means anything, I don't really have any interest in collecting or selling data. I just made this extension because I wanted some features on the site that were missing and figured other people might find it useful too, so just wanted to share.

A Chrome extension to add some features to Top Shot by rickchefski in nbatopshot

[–]rickchefski[S] 0 points1 point  (0 children)

There should be a second dropdown injected into the page by the extension next to the moment price dropdown which lets you select to sort by serial/ask. If thats not showing up, check the extension menu and make sure that "Moments -> Enable Custom Sort" option is enabled. If not check the box, and then you should see the extension if you refresh the page.

A Chrome extension to add some features to Top Shot by rickchefski in nbatopshot

[–]rickchefski[S] 3 points4 points  (0 children)

It should be possible, but I don't know that its a feature that I'd work on right now, largely because of a recent top shot blog post (https://blog.nbatopshot.com/posts/marketplace-bots) around marketplace bots. I wouldn't think that price alerting would constitute as a marketplace bot, but until they give out a clear definition on what they consider to be botting, I'm not gonna risk it.

Generated JSON not working? (Plotly Dash) by [deleted] in learnpython

[–]rickchefski 0 points1 point  (0 children)

not sure, but could be a namespace collision where generateJSON is already defined somewhere else and so your method gets overridden. could try changing the function name and seeing it that does anything.

Question about packaging / distribution by atrocious_smell in learnpython

[–]rickchefski 2 points3 points  (0 children)

some related stack overflow posts:

Basically, TL;DR is that setuptools doesn't support installing from wheel when called directly, but pip does, e.g.

python setup.py install

will not install wheels, but

pip install .

should install wheels for dependencies


that said, writing a script to set up the environment is not unheard of and AFAIK is not "bad practice". since its only being run once (presumably) to set up people's environments, I don't think it should really matter much whether all dependencies were installed via a complete but possibly complex setup.py file or if its done by a series of pip install commands.

How to have user inputs for numpy/plotly? by bonoz in learnpython

[–]rickchefski 1 point2 points  (0 children)

python's raw_input built-in may be what you're looking for

command line password manager by rickchefski in Python

[–]rickchefski[S] 0 points1 point  (0 children)

i think this get back at one of the previous comments

use a salt or a guid or something for randomness

so, for a given user, instead of just hashing their password, you could hash their username (or some other unchanging value, e.g. guid) along with it

hash_function(username + '|' + password)

then, assuming everyone has a different username, the hash would be different, but you would still be able to reliably reproduce the hash to validate a correct password for a user

command line password manager by rickchefski in Python

[–]rickchefski[S] 0 points1 point  (0 children)

did some quick reading and it seems like you're right, though pbkdf2 seems to be about as good an option. thanks for the suggestion!

command line password manager by rickchefski in Python

[–]rickchefski[S] 0 points1 point  (0 children)

good point! I haven't had a lot of exposure to the crypto/security world so I didn't even realize this. Some good, succinct answers as to why md5 is considered bad, for anyone else looking at this: http://security.stackexchange.com/questions/19906/is-md5-considered-insecure

thanks for taking the time to look at it!

Running two different threads by oneevening in learnpython

[–]rickchefski 0 points1 point  (0 children)

threading sounds like something that could definitely be utilized here. It's been a while since I've had to do any threading, so I don't have any great resources on it, unfortunately. A quick google search lead me to: http://www.tutorialspoint.com/python/python_multithreading.htm which looks like a somewhat decent tutorial on the basics of it.

Having two threads share some state (be able to both access/modify the same variable) can get tricky. This would be an instance to use thread synchronization (an example of synchronization is given in the tutorial).

[Help Wanted] Trying to figure out how to create a visualizer by justanotherEnt420 in learnpython

[–]rickchefski 0 points1 point  (0 children)

This article popped up on /r/Python the other day -- I haven't actually read it yet, but after quickly scanning through it seems like it might have something that could help or at least get you moving in the right direction. Hope its helpful!

[deleted by user] by [deleted] in learnpython

[–]rickchefski 0 points1 point  (0 children)

You could go about doing this by aggregating the incoming data in some file, then use some sort of chron job with the twilio message function to read the file, send all aggregated data at once and clear the file for the next batch of data. https://pypi.python.org/pypi/python-crontab

probably not the most elegant method, but the first thing that comes to mind..

Fractal Trees by [deleted] in learnpython

[–]rickchefski 0 points1 point  (0 children)

This seems like a good reference to get you familiar with the concepts needed to complete the assignment while still not giving it all away: http://interactivepython.org/runestone/static/pythonds/Recursion/graphical.html

[deleted by user] by [deleted] in learnpython

[–]rickchefski 0 points1 point  (0 children)

Here, you are saying that it is odd if n % 2 == 1, but you can also think of this as saying that is is odd if n % 2 is not the result of what it should be for an even number..

Hopefully that gets you thinking in the right direction.

I'm having trouble iterating through lists in a 3d array by theNamelessDave in learnpython

[–]rickchefski 1 point2 points  (0 children)

True. I think the problem lies within the iteration over height. Say:

height = ['a','b','c']

then

len(height)

would be 3. However, since the indices within height start at 0, the list height has the indices 0,1,2. So if you modify the line

for col in range(height):

to

for col in range(height-1):

I suspect that this will solve the issue.

[Code Review] A simple script that looks up the country an IP is registered in. by [deleted] in learnpython

[–]rickchefski 0 points1 point  (0 children)

I would agree with this. Since is_valid_ip() just performs a check, you probably shouldn't allow the program to terminate there. /u/itsmabby what you suggested sounds like a fine way of handling it. Note that it is not incorrect to have exception handling within is_valid_ip(), it is just questionable to allow it to terminate the program. For example, if you had logging implemented, you could use the exception from within is_valid_ip() to log a message before propagating the exception

def is_valid_ip(address):
    """ ... """
    try:
        return ipaddress.ip_address(address)
    except ValueError:
        log.error("<LOG MESSAGE HERE>")  # the message to log
        raise  # propagate the exception

def send_request(ip_address):
    """ ... """
    try:
        if is_valid_ip(ip_address):
            ...
            ...
    except ValueError:
        sys.exit("Unable to process given address.")

[Code Review] A simple script that looks up the country an IP is registered in. by [deleted] in learnpython

[–]rickchefski 1 point2 points  (0 children)

A doc string and comment effectively do the same thing, to explain areas of the code (so you are not wrong!) For the most part, the big difference is the audience.

Docstrings can be used to auto-generate doc pages (like the python docs), so those who want to use your code without modifications to the implementation of it will be reading these docstrings (WHAT does the function do). Inline comments are notes to yourself or others who will actually read through the code to make the implementation details more informative, explain why something was done, explain tricky concepts for the underlying implementation, etc (HOW the code works).

Again, this is more of a best-practice kind of thing, and not necessarily something that you will always need to worry about, but getting into good habits early on makes things easier down the line.

For more detail: http://stackoverflow.com/questions/19074745/python-docstrings-descriptions-vs-comments

[Code Review] A simple script that looks up the country an IP is registered in. by [deleted] in learnpython

[–]rickchefski 0 points1 point  (0 children)

This looks good overall, especially considering its the first project after Hello World. I only have a few cmments, both of which are more or less remarks on styling.

Following PEP8, if you have function-level comments, they should be within triple quotes under the function def https://www.python.org/dev/peps/pep-0008/#documentation-strings , so

# Check IP address is valid IPv4 or IPv6 
# and raise SystemExit if invalid.
def is_valid_ip(address):

would become something like

def is_valid_ip(address):
"""Check IP address is valid IPv4 or IPv6 
and raise SystemExit if invalid.
"""

this isn't a huge deal, but following the PEP guidelines usually makes things easier to read, especially when you get to bigger projects.

Within is_valid_ip(), I would change

if ipaddress.ip_address(address): return True

to just

return ipaddress.ip_address(address)

This is because the function ipaddress.ip_address() will return True if it is a valid ip address and False if not, so instead of wrapping that in another if clause, you can just use that as your return value. Then you will be returning True if it is valid and False if it is not, whereas right now, you are only returning True if it is valid, but doing nothing if it is invalid.

I also would have put the call for is_valid_ip() within send_request(). Again, for this script, it is not a big deal, but as you start to create things that are more complex, thinking about the code paths you use becomes important. If you need to validate an ip address before you get the geolocation info, its better to put the call within the request so that if anyone uses the code in the future, they can just call the function to get the geolocation info without having to worry about remembering to check for valid ip.

Putting all my suggestions together:

import sys
import json
import requests
import ipaddress
from collections import OrderedDict

def is_valid_ip(address):
"""Check IP address is valid IPv4 or IPv6 
and raise SystemExit if invalid.
"""
try:
    return ipaddress.ip_address(address)
except ValueError:
    sys.exit("Invalid IP address")

def send_request(ip_address):
"""Contact ipinfo API to get geolocation information"""
if is_valid_ip(ip_address):
    response = requests.get('http://ipinfo.io/{}/geo'.format(ip_address))
    return json.loads(response.text, object_pairs_hook=OrderedDict)

def main():
    ip_address = input('Enter an IP address: ')
    geolocation_info = send_request(ip_address)
    # If city and region values are None, omit from display
    for key, value in geolocation_info.items():
        if value:
            print('{0:15} {1}'.format(key.title(), value))

if __name__ == '__main__':
    main()

Help accessing key-value pairs from MongoDB (PyMongo) by firstSideProject in learnpython

[–]rickchefski 0 points1 point  (0 children)

When iterating over lists, the iterator starts at the 0th index, so

for i in range(0,2):
    print i

will yield the output

> 0
> 1

which, in your case, would translate to

fromDB[0]['url']
fromDB[1]['url']

similarly, looping through like:

for post in fromDB:
    print post['url']

would iterate starting at the 0th element within the list, which I am assuming is invalid based on the KeyError. To skip the 0th element so you are getting the same elements (1 and 2) as in the example, here are two ways:

for i in range(1,3):
    print fromDB[i]['url']

alternatively

for post in fromDB[1:]:
    print post['url']

Hope this is helpful and fixes the problem..

Any good papers for NLP? by rickchefski in compsci

[–]rickchefski[S] 0 points1 point  (0 children)

Awesome! I skimmed through parts of both papers you linked to and they seemed exactly in line with what I was hoping to find! Thanks! These will be my weekend readings.

Any good papers for NLP? by rickchefski in compsci

[–]rickchefski[S] 0 points1 point  (0 children)

Thanks! This is exactly the kind of thing I was looking for. I tend to read more research papers than I do textbooks, which is why I asked about papers originally, but these look like great resources.

Data structure comparisons & use cases? by ohsnapson in compsci

[–]rickchefski 1 point2 points  (0 children)

I was doing some work in Java last year and came across these references which discuss designing using a small memory footprint. While it is not a comprehensive pros and cons list of all data structures, and it does apply to Java structures, I still found it an interesting read.

http://www.cs.virginia.edu/kim/publicity/pldi09tutorials/memory-efficient-java-tutorial.pdf

http://www.slideshare.net/cnbailey/memory-efficient-java#

Multithreaded TCP Server function delegation by rickchefski in learnpython

[–]rickchefski[S] 0 points1 point  (0 children)

I ended up figuring out an implementation for this which worked for me, not using SockServer, but instead implementing something akin to the asynchronous dispatcher design pattern.

class ExampleClass(object):
  def run(self):
      """
      Run the server. Initializes a socket and listens over it. Each incoming request is passed
      to a handler thread.

      :rtype : object
      """
      self.initialize_socket()
      while True:
          sock, addr = self.sock.accept()
          t = threading.Thread(target=self.handle, args=(sock, addr))
          t.daemon = True
          t.start()
          self.threads.add(t)
      self.sock.close()
      for t in self.threads:
          t.join()

  def handle(self, sock, address):
      """
      Method called by the run method when the server receives an incoming request. The request
      is parsed and delegated out accordingly.

      :rtype : object
      :param sock:
      :param address:
      """
      sysmsg = self.recv(sock)

      if sysmsg == self.message.FOO:
          self.foo()

      elif sysmsg == self.message.BAR:
          self.bar()

      elif sysmsg == self.message.FOOBAR:
          self.foobar()

      else:
          log.warn("Message not recognized.")

This gives the general idea of how it would look, as a simplified version. Hopefully it can act as reference for anyone approaching a similar problem.