10 ms·
Show HN: Deck of Cards – A playing card API
- flashman 11y agoI'm not sure what this file does: https://github.com/crobertsbmw/deckofcards/blob/master/list.txt https://github.com/crobertsbmw/deckofcards/blob/master/list....
- sturmeh 11y ago(ಠ_ಠ)
- fosk 11y agoRemember to always gitignore your list.txt file folks!
- crobertsbmw 11y agoGood catch, haha.
- ChristianBundy 11y agohttps://github.com/crobertsbmw/deckofcards/pull/3 https://github.com/crobertsbmw/deckofcards/pull/3
- bdcravens 11y agoThat of course doesn't delete it from the history :-) You can do that via https://help.github.com/articles/remove-sensitive-data/ https://help.github.com/articles/remove-sensitive-data/, but once it's been cloned, the file is of course out of the toothpaste tube so to speak :-)
- ctekin 11y agoAlso unfortunate : https://github.com/crobertsbmw/deckofcards/blob/fb02c09b9bc48ba8ccaf4a872df8edd650c08cf6/spades/settings.py https://github.com/crobertsbmw/deckofcards/blob/fb02c09b9bc4...
- crobertsbmw 11y agoI've changed the secret key that I am using in production. I wanted the settings.py to be there so it works out of the box if anyone forks it.
- tjbiddle 11y agoNeat! Nice work! Some are definitely criticizing, but hey - you'll always have critics. Unless they're following through with a pull-request, don't mind them. Great job on putting the project out there! An idea: Multiple options for deck images - obviously would take time on the artwork, but you could set this in your initial call for a deck (Or maybe even make it so you can change it whenever - if someone would have a need for that for some reason). May be fun. Great work!
- nicobn 11y agoThe absence of a pull request does not negate the validity of a criticism. Hacker News is one of the most tech-savvy, intelligent and experienced audience you can find on the web. Everyone sucks, myself included. With that kind of attitude, I would never have learned anything. Shielding yourself from criticism using an arbitrary criteria only perpetuates ignorance.
- javajosh 11y agoHa, nice. Your choice of images is...interesting :) https://github.com/crobertsbmw/deckofcards/blob/master/static/img/JACKSPADES.png https://github.com/crobertsbmw/deckofcards/blob/master/stati...
- crobertsbmw 11y agoI just stole all the images off wikipedia. I wanted to make sure I wouldn't get sued.
- lectrick 11y agohttps://code.google.com/p/vectorized-playing-cards/ https://code.google.com/p/vectorized-playing-cards/
- jdeisenberg 11y agoThese strongly resemble the ones made by Nicu Buculei at http://openclipart.org http://openclipart.org
- jwcrux 11y agoNeat! Possible typo: > After two weeks, if actions have been made on the deck then we throw it away. Might be "if no actions"?
- crobertsbmw 11y agofixed. Good catch.
- voltagex_ 11y agoI wonder if returning SVG would be possible - https://code.google.com/p/vectorized-playing-cards/ https://code.google.com/p/vectorized-playing-cards/ Edit: Could be an excellent idea - 8 of Clubs is: * 28kb as a PNG. * 14kb as an SVG * 4kb as a gzipped SVG
- Everlag 11y agoThought about that as soon as I saw it returning rasters. SVG would be best offered alongside as an option; it requires more effort to use than just a png. Perhaps a 'vector' to accompany each 'image'?
- voltagex_ 11y agoAccept: headers. Default to image/png
- evv 11y agoThose cards look great! Much better than the OP's raster images. But they seem familiar. I can't help but wonder, are they infringing on any copyrights?
- jessaustin 11y agoFollowing that link, the first section on the page: These poker sized cards have been created and hand optimized in various vector formats (.eps and .svg) using the open source .svg graphics editor Inkscape http://www.inkscape.org http://www.inkscape.org. .... Generally, this means the cards are free to use (commercially and non commercially) but must be properly attributed (see "README.txt" file) and (The library itself, not your project) re-distributed only under the same license.
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]
- 11y ago
- hartror 11y agoNice one! Good on you for building a thing and putting it out there. A few comments/suggestions: * You have DEBUG = True in your production Django config. (eg. http://deckofcardsapi.com/api/ http://deckofcardsapi.com/api/) * You are mutating state with HTTP GET, this is an anti-pattern for a number of reasons. The common one I use with people I coach is that browsers/proxies will happily cache GET requests unless told not to, but there are a number of other reasons if you read up on REST [1]. * Being a public API in a well known domain this is a good opportunity to make the API self documenting & navigable with a hypermedia format. (eg HAL, Siren, JSON-LD) [2] [1] http://martinfowler.com/articles/richardsonMaturityModel.html http://martinfowler.com/articles/richardsonMaturityModel.htm... [2] http://sookocheff.com/posts/2014-03-11-on-choosing-a-hypermedia-format/ http://sookocheff.com/posts/2014-03-11-on-choosing-a-hyperme...
- voltagex_ 11y ago>good opportunity to make the API self documenting & navigable with a hypermedia format. (eg HAL, Siren, JSON-LD) Other than learning, what's the benefit here?
- hartror 11y agoI assume you mean what is the benefit of hypermedia? Martin Fowler does a good job explaining it (http://martinfowler.com/articles/richardsonMaturityModel.html#level3 http://martinfowler.com/articles/richardsonMaturityModel.htm...). As does Mike Amundsen (http://www.infoq.com/presentations/Building-Hypermedia-API http://www.infoq.com/presentations/Building-Hypermedia-API).
- iamflimflam1 11y agoI don't see much benefit in martin fowler's example <openSlotList> <slot id = "1234" doctor = "mjones" start = "1400" end = "1450"> <link rel = "/linkrels/slot/book" uri = "/slots/1234"/> </slot> <slot id = "5678" doctor = "mjones" start = "1600" end = "1650"> <link rel = "/linkrels/slot/book" uri = "/slots/5678"/> </slot> </openSlotList> Each slot now has a link element which contains a URI to tell us how to book an appointment. Well, not really - we can only guess that by the fact that the link ends in "book". We also don't know if we are supposed to GET, PUT, DELETE, POST.. or what data we are supposed to send to the url to actually make the booking.
- adanto6840 11y agoWhat's being used for RNG?
- Walkman 11y agohttps://github.com/crobertsbmw/deckofcards/blob/master/deck/views.py#L23 https://github.com/crobertsbmw/deckofcards/blob/master/deck/...
- sirclueless 11y agoAppears to be python's random module, so not very secure if that's what you're after but it's probably correctly pseudorandom: https://github.com/crobertsbmw/deckofcards/blob/master/deck/models.py#L33 https://github.com/crobertsbmw/deckofcards/blob/master/deck/...
- sneak 11y agoDoesn't matter, as the whole thing is served without TLS.
- hurin 11y agoSeriously, why wouldn't you just use a local RNG? Do you realize it's actually less work than reading API documentation?
- crobertsbmw 11y agoConsider it a bad Rube Goldberg Machine.
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]
- hurin 11y agonumbers = ['2','3','4','5','6','7','8','9','10','J','K','Q','A'] suits = ['CLUBS', 'SPADES', 'HEARTS', 'DIAMONDS'] deck = [(num,suit) for num in numbers for suit in suits] random.shuffle(deck) draw_card = lambda deck: deck.pop()
- packetized 11y agoIs something new with this project? I believe this same thing was posted 10 days ago. https://news.ycombinator.com/item?id=9462184 https://news.ycombinator.com/item?id=9462184 Would be interesting to hear if some of the issues raised in the previous submission were fixed or updated.
- evan_ 11y agoIf it supported the idea of multiple players, keeping track of what cards each player has, and facilitating passing cards between players; it could be a cool backend for lots of different card games.
- sirclueless 11y agoI wonder if you could do most of this cryptographically. If you did, you could make a client that could do all of this peer-to-peer. I think you would just need the following to make a wide range of games (many popular ones, perhaps most?): 1. Client can produce a signature that it drew the k'th card from the deck for any k. 2. Client can produce a signature that the k'th card is X if it drew the k'th card. 3. Client can produce a signature that card X came from any arbitrary set of card indices containing k if it drew the k'th card. (This is the hardest one.) If it's easier, you could get most of this even restricting it to sets of cards that the client has drawn. With just that, I bet you could make a protocol for most card games where no one can cheat, where the central server's role is only to give out information about k'th card one and only one time. Certainly it's enough for blackjack, most forms of poker, hearts, and go fish. Anyone have a game that would be difficult? Maybe one where hidden cards get passed from player to player.
- crobertsbmw 11y agoI don't know much about cryptography. But this is very intriguing to me.
- lann 11y agoYou can! http://en.m.wikipedia.org/wiki/Mental_poker http://en.m.wikipedia.org/wiki/Mental_poker
- jonobird1 11y agoI'm just getting a "400 Bad Request" for the home page (from Brisbane, Australia)
- bt3 11y agoSeconded. US here.
- crobertsbmw 11y agoSorry about that. Should be fixed now.
- crobertsbmw 11y agoFixed.
- recursive 11y agoHTTP errors as a service
- crobertsbmw 11y agoFixed.
- deleted 11y ago[deleted]
- mattkenefick 11y agoLooks good.
- xxbondsxx 11y agoPretty cool! Love that theres no authentication and I can start straight from curl. Nit: drawing from an empty deck does not throw an error: > curl http://deckofcardsapi.com/api/draw/i763hn8lcg0e/ http://deckofcardsapi.com/api/draw/i763hn8lcg0e/ {"remaining": 0, "cards": [], "deck_id": "i763hn8lcg0e", "success": true} As does drawing a comically large number of cards: > http://deckofcardsapi.com/api/draw/vzlem7q4jhna/?count=100000; http://deckofcardsapi.com/api/draw/vzlem7q4jhna/?count=10000... (...) "success": true}\n
- bloodspatter504 11y agoCan someone show or explain: 1. An example of how this could be used. 2. How to do something other than just shuffling the cards.
- d0m 11y agoI think it was just a fun side project. But as to how it could be used.. just a few weeks ago we were at a hackathon and built a quick poker texas holdem game. A library like that (arguably a bit more comprehensive) would have saved us a few hours.
- MeghdeepRay 11y agoWas it just a texas hold em ? Or a variation of it ? I assume being a hackathon it wasn't a vanilla texas hold em. Could you provide some more details and maybe the code ? After seeing this I'm interested to know what else you've done.
- d0m 11y agoSo we wanted to learn/play with react native. The project idea was to play a hand of poker online randomly against someone in less than 30 seconds. The fun part is you can only fold or go all-in : )
- bloodspatter504 11y agoCan someone show or explain: 1. An example of how this could be used. 2. How to do something other than just drawing the cards.
- soup10 11y agoI like the website design but shuffling cards is extremely trivial to code. Also cards are mostly used for gambling games and it's a huge security hole to use a third party api for that unless it's from a very trustworthy source. One maybe useful thing about this api is the card images, but there are also probably plenty of decks in the public domain.
- nly 11y ago> Also cards are mostly used for gambling games and it's a huge security hole to use a third party api Depends. If you're writing a game you wanted the player to trust you might want to use an external shuffling service so you can easily show proof-of-deck after the game is over. Of course, you could do this simply by giving the player a cryptographic hash of the shuffled deck beforehand, e.g. SHA-256(5H,4D,AS...)
- ivanche 11y agoI've worked as a developer for online gambling games for 6 years. We never shuffled the deck of cards. Instead, as player requests another card(s), they are generated using hardware RNG and returned to player. Deck only knows which cards are left in it, but their order is undefined until that call to RNG.
- sesquipedalian 11y agoIf I'm not mistaken, this sounds like an incremental fisher-yates shuffle.
- ivanche 11y agoYou are correct. As the matter of fact, a bunch of games in majority of cases needed only the next card from the deck, that's why in our heads we almost always thought of "not shuffling at all".
- g8gggu89 11y agoHow is that better? You just don't want to spend the time to shuffle a deck if only a few cards will be used? Or you are worried someone might cheat by being able to read card order ahead of time?
- gabemart 11y agoThis seems like a really cool project! But how are you shuffling the cards, and how are you identifying unique shuffled decks? It looks like the deck_id is 12 characters, numbers or lower-case letters. That gives a range of 36^12 or around 4.7 * 10^18. The total range of a physical deck of shuffled cards is 52! or around 8 * 10^67. It's possible I have misunderstood what deck_id is for.
- kornish 11y agoLooks like deck_id references a persisted model: https://github.com/crobertsbmw/deckofcards/blob/master/deck/models.py#L23 https://github.com/crobertsbmw/deckofcards/blob/master/deck/... The model stores the state of the deck, including things like order and remaining cards and how many "decks" of 52 cards are in play.
- carrotleads 11y agoSounds straightforward and simple. Well done. Would like an option to set parameters of a deck. Some card games use only 8 cards from a set and not the whole 13.
- comrh 11y agoAdding and subtracting from the starting deck would very useful. Adding Jokers, playing with only 1-10 (scopa), ect
- drinchev 11y agoWow. I never thought this could be an API. Really good work. I remember I spent a lot of time developing a class that deals with a deck of cards, shuffle and associate the card with a png. I would use this API in the future.
- deleted 11y ago[deleted]
- alangpierce 11y agoWhile this looks to me like a pretty clean and straightforward API, it's definitely not a REST API (not that it claims to be): * The API doesn't really follow HTTP. It allows GET for state-modifying actions, which breaks assumptions that could be made by browsers, client libraries, caches, and proxies. Also, the "success" field seems fishy; a 200 response code is the usual HTTP way to indicate success. * The API is not resource-oriented; the URLs "shuffle" and "draw" are verbs that describe the action to take. In a "real" REST API, URLs define conceptual resources (nouns), and you interact with the API by interacting with those resources. * The API does not use hypermedia. Hypermedia and HTTP compliance are discussed elsewhere in this thread, but I wonder if others have an opinion on the fact that the API isn't resource-oriented. This "resource-oriented" rule has always bugged me about REST APIs. My impression has been that REST advocates claim that pretty much every API can and should be implemented with a CRUD-like interface (where the entire API consists of performing GET, POST, PUT, and DELETE on a conceptual set of resources), but it seems like that would be really awkward for this "deck of cards" use case. Is there value in trying to use resources here? What might it look like?
- salex89 11y agoNot that I had a similar situation, but how to implement actions such as shuffle or draw and make them-resource like?
- SilasX 11y agoI guess shuffles and draws should be their own resources, and you POST to it to do that action? You'd then keep a table of shuffle/draw events, which mutate the deck as a side effect.
- salex89 11y agoI get it. I had an idea to make a "shuffled-copy" or a new deck with one less card, made from the original deck. Than you can theoretical rewind your shuffle process, since it's a chain of immutable decks. But I'm afraid that will really consume too much storage for a rather unimportant thing, at least in this case :) .
- murbard2 11y agoCute, but an implementation of the mental poker protocol would be far more valuable.
- crobertsbmw 11y agoI think I'll do that next.
- listic 11y agoWhat's it good for, if it doesn't visualize my cards?
- brettkc 11y agoSaw something similar demoed at Microsoft's Build event. Looks nice.
- Navarr 11y agoThere are so many things a good API would have to do... Different types of decks, handling of a discard, shuffling a card into the deck, shuffling the discard pile into the deck, handling hands, milling a card from the deck, multiple decks acting as one... Though the simplicity of this api currently just having a deck that you take cards from is neat.
- blt 11y agoOP: what was your motivation for this project?
- crobertsbmw 11y agoThanks for asking. I wanted to build a very simple API, and document it that my year ago self could understand it and actually figure out how to use the whole thing. I don't know if this is a good or bad thing, but I spent more time documenting/designing the single doc page then I did writing the actual API. I also thought the idea was unique enough that it was worth sharing. The reason for GET and POST is that it was easier for my year ago self to copy and paste a GET url into chrome and hit Enter and see what happens.
- spdustin 11y agoHas anyone noticed that it's on Github, and thus it wouldn't be too tough to submit an Issue or, even, a PR?
- jessaustin 11y agoThis thread is yet more evidence of the Bikeshed Phenomenon.
- aarondf 11y agoHey, you did a thing and told people [0]! Good for you. Is it perfect? No idea, but from reading the comments here a lot of people don't think so. Who cares though [1]! You're so far ahead of so many people because you actually did something. Next time maybe all your GETs will be RESTful, maybe not. Either way, you've done a thing, put it out there, and are presumably learning a lot by doing so. Great work. [0] http://carl.flax.ie/dothingstellpeople.html http://carl.flax.ie/dothingstellpeople.html [1] http://www.garann.com/dev/2013/how-to-blog-about-code-and-give-zero-fucks/ http://www.garann.com/dev/2013/how-to-blog-about-code-and-gi...
- deleted 11y ago[deleted]
- gooseus 11y agoI'm seeing a lot more discussion and debate, rather than criticism. So good job for that too... I think this Deck of Cards API would make a great case study for analyzing and discussing the varying takes on how a RESTful interface should handle certain situations which aren't as straightforward as the typical blog or todo list examples.
- amouat 11y agoA lot of the time it doesn't feel like that to me. People release things they have worked long and hard on, only to get a bunch of negative comments picking on holes and mistakes. The weird thing is they are the lucky ones; it's pretty damn hard to make it onto the front-page of HN now, regardless of the quality of the content. (Don't believe me? Take a look at how many times some articles have been reposted and the disparity in number of votes.) Getting feedback should be great, but not many of us are good at it. Generally, we only comment on things we care about or find interesting (ignoring the stuff that is so bad it deserves harsh criticism like storing passwords in plain-text), but we forget to say that in the comment and only mention the minor flaw we saw. I don't have a solution to this, other than to tell posters to be prepared for criticism and to take each up-vote as a major token of respect in what you've built.
- leovander 11y ago-people to spam - -weber@kcnext.com -info@cremalab.com -andy@lovekc.org -info@truckily.com -info@secondlifestudios.com -help@getflywheel.com -hello@elevate.co -hello@goodtwin.co -Info@ObjectLateral.com -editor@siliconprairienews.com -info@squareoffs.com -josh@socialchangenation.com -websupport@psicurity.com -sales@rfp365.com -travis@rivetcreative.com -info@phlyppgear.com -kyle@feralfew.com -matt@feralfew.com -zach@feralfew.com -courtney@feralfew.com -ben@homesforhackers.com -info@cyberjammer.net -info@SponsorShout.com https://github.com/crobertsbmw/deckofcards/commit/2b5675df526ea146c20bcfcee40b134b8a8bf222 https://github.com/crobertsbmw/deckofcards/commit/2b5675df52...
- jaideepsingh 11y agoKudos! Simple and to the point.