|
Thanks for the responses guys. To clear a few things up, it doesn't need to be secure, just not an instantly identifiable pattern. One thing I missed out in my original post is that the returned string needs to be six characters long (hence why it should take an integer between 1 and 36^6). So most readily available hashing algorithms are out of the question. I'm definitely making the problem more complicated than it needs to be, a simple random string generator will probably guarantee the level of uniqueness I'll actually need but I thought this was an interesting problem. It seems like it should be a simple function but it feels like it's just outside of my grasp. edit in-fact it doesn't need to be between 1 and 36^6. In reality 1 and 1,000,000 should suffice, but the output string does need to be 6 characters and unique. Tea Bone fucked around with this message at 10:21 on Oct 31, 2018 |
# ? Oct 31, 2018 10:17 |
|
|
# ? Jun 10, 2024 11:26 |
|
What problem are you actually trying to solve?
|
# ? Oct 31, 2018 11:39 |
|
Blinkz0rz posted:What problem are you actually trying to solve? I suppose I'm not exactly trying to solve a problem. The specification I was given was simply to generate a unique alpha numeric id that was 6 characters long. A simple random string generator does the job as I don't expect to need more than around 10k ids and even then it's easy enough to validate uniqueness. The added constraints are self imposed. It seemed like an easy enough task to map any integer to a unique random string which can be calculated at run time but I hit a wall trying to think of a way to actually do it.
|
# ? Oct 31, 2018 16:36 |
|
That's making things more complex without any benefit. Just make a random 6 char string as a your surrogate key and be done with it.
|
# ? Oct 31, 2018 16:58 |
|
Tea Bone posted:I suppose I'm not exactly trying to solve a problem. The specification I was given was simply to generate a unique alpha numeric id that was 6 characters long. A simple random string generator does the job as I don't expect to need more than around 10k ids and even then it's easy enough to validate uniqueness. Depending on the language used, there may be there already libraries that can do that for you. For example in Java you have the apache commons-lang library with its RandomStringUtils class that does exactly that. There must be similar things in other lnaguages/platforms.
|
# ? Oct 31, 2018 17:42 |
|
Tea Bone posted:I suppose I'm not exactly trying to solve a problem. The specification I was given was simply to generate a unique alpha numeric id that was 6 characters long. A simple random string generator does the job as I don't expect to need more than around 10k ids and even then it's easy enough to validate uniqueness. Just use a hash function to get a big random hexadecimal value and then do some math to convert base-16 hex stuff into a base-36 alphanumeric key. It'll be longer than you need so just truncate after 6 characters.
|
# ? Oct 31, 2018 18:13 |
|
RPATDO_LAMD posted:Just use a hash function to get a big random hexadecimal value and then do some math to convert base-16 hex stuff into a base-36 alphanumeric key. It'll be longer than you need so just truncate after 6 characters. Given the requirements, what nielsm said is probably the best: nielsm posted:Nah it's not a hash you're after, just shuffle the bits around a bit, and XOR with a static key value. It won't be secure (someone might be able to guess the static key if they can generate a sequence of values) but it will be two-way, which you probably want. Keep in mind that 36^6 is 2176782336, which is only slightly more than INT32_MAX i.e. 2^31-1.
|
# ? Oct 31, 2018 18:19 |
|
Is there anything that means the simple autoincrementing version doesn't work?
|
# ? Nov 1, 2018 00:47 |
|
Jabor posted:Is there anything that means the simple autoincrementing version doesn't work? It's supposed to be superficially random.
|
# ? Nov 1, 2018 00:58 |
|
just do what rjmccall said if you feel weird about it write a simple test to verify the uniqueness, it shouldn't take prohibitively long to run
|
# ? Nov 1, 2018 02:48 |
If you want to do it both securely and uniquely: Let C = how many characters you want your alphabet to be(i .e, base 36 -> a-z, A-Z, 0-9) let L = how long the IDs should be Generate the interval [0, C*L) and permute it randomly using your secure rng of choice Convert each number to base C and assign it to the appropriate characters - now you have unique n-length , c-possible strings Eela6 fucked around with this message at 06:03 on Nov 1, 2018 |
|
# ? Nov 1, 2018 05:21 |
|
Dren posted:just do what rjmccall said Yeah, I mean, an auto-incrementing 32-bit ID multiplied by an impressively random-looking 32-bit odd number and then printed out in base 36 is easy, cheap, and guaranteed to not repeat until you literally exhaust the 32-bit ID space.
|
# ? Nov 1, 2018 05:56 |
|
rjmccall posted:Yeah, I mean, an auto-incrementing 32-bit ID multiplied by an impressively random-looking 32-bit odd number and then printed out in base 36 is easy, cheap, and guaranteed to not repeat until you literally exhaust the 32-bit ID space. You gotta make sure your impressively random number is not a multiple of 3 either, otherwise you'll start getting repeats a little bit sooner than that.
|
# ? Nov 1, 2018 06:32 |
|
Eela6 posted:If you want to do it both securely and uniquely: sure but precomputing a permutation of a 36^6 list takes a non-trivial amount of memory there is a SO post about this problem https://stackoverflow.com/questions/7283631/one-to-one-integer-mapping-function The answer from there is to multiply by an odd number mod 36^6. The original value can be computed from the encoded value w/ the modular multiplicative inverse. It's been too long since I've mathed for me to know how to say if this method has possible collisions.
|
# ? Nov 1, 2018 07:34 |
|
Jabor posted:You gotta make sure your impressively random number is not a multiple of 3 either, otherwise you'll start getting repeats a little bit sooner than that. Not unless you're doing the multiplication mod some multiple of 3 smaller than your original value range. ..oh, I see, since 36^6 is not quite 2^32, there's some risk of that if you need exactly 6 digits. rjmccall fucked around with this message at 20:11 on Nov 1, 2018 |
# ? Nov 1, 2018 20:06 |
|
EDIT: nm
smarxist fucked around with this message at 03:06 on Nov 4, 2018 |
# ? Nov 4, 2018 00:33 |
|
Recently asked for a portfolio audit and one of the feedback points was that I need to make my Readme.md files more polished and interesting for my Github. How can I do that?
|
# ? Nov 6, 2018 15:28 |
Love Stole the Day posted:Recently asked for a portfolio audit and one of the feedback points was that I need to make my Readme.md files more polished and interesting for my Github. How can I do that? Might be easier to answer after seeing them, but I suppose part of it is answering some key questions first thing: What is it (purpose), who is the audience of the project (end users, developers), how mature is it, what are long term goals. Other good topics are project organization (code structure), build/install process, usage examples.
|
|
# ? Nov 6, 2018 15:54 |
|
"Why this project exists" and how to run locally / how to deploy are the bare minimum. If you just do those things, you're ahead of most developers. Beyond that, it's a good place for non-code-related tribal knowledge that people will need. I like having a triage section so that when people need to republish a message or something common to your app, they aren't forced to spend an hour figuring out how Kafka configs are built up for the prod environment.
|
# ? Nov 6, 2018 18:15 |
|
Can someone explain in idiot terms what RESTful means? Going off of the Wikipedia page it sounds like pretty standard best practices for efficiency and security stuff, but I'm wondering if I am missing something that makes it more complicated than what you would get taught in JS 101 at whatever college. I'm applying to entry level dev / application support positions and it comes up a lot.
|
# ? Nov 8, 2018 23:14 |
|
22 Eargesplitten posted:Can someone explain in idiot terms what RESTful means? Going off of the Wikipedia page it sounds like pretty standard best practices for efficiency and security stuff, but I'm wondering if I am missing something that makes it more complicated than what you would get taught in JS 101 at whatever college. I'm applying to entry level dev / application support positions and it comes up a lot. I think REST is one of those things where wikipedia is not the right place to learn, as the layman's usage is much simpler/concrete than the formal definition. RESTful services are: 1) called over HTTP 2) typically use the path of the URL and HTTP operation to determine the API being called and its high-level parameters (e.g. DELETE https://foo.com/_api/cars/123 = DeleteCar(123)) 3) use cross-platform textual representations like json or xml for more complicated request/response data 4) each operation should be a single request and the client shouldn't have to store any state They are so prolific and so simple that it's easy to forget there are other ways one might design services if you haven't seen them.
|
# ? Nov 8, 2018 23:36 |
|
I stupid terms it means that the service accepts regular HTTP verbs (GET, PUT, POST, DELETE, etc..) and your url endpoint describes the objects you're manipulating. Also it uses HTTP error codes to communicate success/failure crap. In practice most rest frameworks assume that the content and reply are all JSON but the spirit is that you could send anything to it.
|
# ? Nov 8, 2018 23:37 |
|
I see, that makes sense. So it is a formal name for a pretty standard way of doing things. The only parts that don't seem blindingly obvious are that the object is defined by URL endpoint and it being in JSON, although like Janitor Prime said it's not strictly required. And from stupid point of view it seems like you should almost always be using JSON for that sort of thing anyway. While I'm asking dumb questions, what's the difference between a "Single Page Application" and just a website that's all on one page and sends you to sections with different IDs when you click on a link? It says it rewrites the page when you click, would that be something like creating form objects and such or would it be creating whole new "pages" (as far as the user could tell without looking at the URL)? Whenever I read about it, it mentions scrolling being an advantage on mobile devices, which sounds like the one page site that sends you to different parts.
|
# ? Nov 8, 2018 23:48 |
|
22 Eargesplitten posted:I see, that makes sense. So it is a formal name for a pretty standard way of doing things. The only parts that don't seem blindingly obvious are that the object is defined by URL endpoint and it being in JSON, although like Janitor Prime said it's not strictly required. And from stupid point of view it seems like you should almost always be using JSON for that sort of thing anyway. SPAs are about manipulating the DOM on the client to render, and can mean as much as rendering the whole page on the fly in javascript. Using anchors like back in the day means that you still have the whole DOM delivered to you as a static page that’s all there, but if you’re using an SPA framework like React or Angular, the page is provided as template pieces that the framework adds and removes and manipulates from the DOM as needed via javascript. So say you click a link, instead of pinging the server for a new static page, the framework clears the DOM and adds the new content where it needs to be.
|
# ? Nov 9, 2018 00:00 |
|
22 Eargesplitten posted:I see, that makes sense. So it is a formal name for a pretty standard way of doing things. The only parts that don't seem blindingly obvious are that the object is defined by URL endpoint and it being in JSON, although like Janitor Prime said it's not strictly required. And from stupid point of view it seems like you should almost always be using JSON for that sort of thing anyway. It's basically blindingly obvious for almost all services now a days. There are still some scenarios where you might reject RESTful. Say, a real-time online video game: you might want to use a proprietary, binary message protocol because it makes it harder for your users to reverse engineer for nefarious purposes and you can save critical ms by not having to do json [de]serialization.
|
# ? Nov 9, 2018 00:11 |
|
dupersaurus posted:SPAs are about manipulating the DOM on the client to render, and can mean as much as rendering the whole page on the fly in javascript. Using anchors like back in the day means that you still have the whole DOM delivered to you as a static page that’s all there, but if you’re using an SPA framework like React or Angular, the page is provided as template pieces that the framework adds and removes and manipulates from the DOM as needed via javascript. I see. What you say it is sounds more like what I was thinking. Then why do all those articles talk about scrolling being such a huge thing? Is it a terminology confusion thing? It seems like what you're saying would require just as much link clicking as a multi-page application.
|
# ? Nov 9, 2018 00:22 |
|
22 Eargesplitten posted:I see. What you say it is sounds more like what I was thinking. Then why do all those articles talk about scrolling being such a huge thing? Is it a terminology confusion thing? It seems like what you're saying would require just as much link clicking as a multi-page application. IANA web developer, but I assume they mean the SPA can trigger the fetch for new content not just from clicking a link but from the user having scrolled near the end of the page (so time to fetch more pictures of cats and append them to the bottom of the DOM).
|
# ? Nov 9, 2018 00:24 |
|
22 Eargesplitten posted:Can someone explain in idiot terms what RESTful means? Going off of the Wikipedia page it sounds like pretty standard best practices for efficiency and security stuff, but I'm wondering if I am missing something that makes it more complicated than what you would get taught in JS 101 at whatever college. I'm applying to entry level dev / application support positions and it comes up a lot. It doesn’t mean anything. When asked in a job interview, say something about HTTP and verbs and JSON and media types. 22 Eargesplitten posted:While I'm asking dumb questions, what's the difference between a "Single Page Application" and just a website that's all on one page and sends you to sections with different IDs when you click on a link? These are very good questions! An SPA is a JavaScript program that uses some HTML elements here and there, whereas "just a website" is an HTML document that may use some JavaScript to enhance interactivity.
|
# ? Nov 9, 2018 00:40 |
|
22 Eargesplitten posted:I see, that makes sense. So it is a formal name for a pretty standard way of doing things. Just to be clear, the reason a person might be confused about RESTful is because: Eggnogium posted:They are so prolific and so simple that it's easy to forget there are other ways one might design services if you haven't seen them. Combined with the fact that RESTful services were not always the "standard way of doing things".
|
# ? Nov 9, 2018 00:49 |
|
I still have to deal with SOAP occasionally and configuring WSDLs is a good reminder why most places don’t use it now.
|
# ? Nov 9, 2018 01:03 |
|
22 Eargesplitten posted:I see. What you say it is sounds more like what I was thinking. Then why do all those articles talk about scrolling being such a huge thing? Is it a terminology confusion thing? It seems like what you're saying would require just as much link clicking as a multi-page application. It’s about loading than clicking. Instead of making constant http requests for html, you make one big asset dump at the start, cache it, and then little api calls from then on. Also, the client knows better how to render for itself than the server does, so responsiveness is a little easier.
|
# ? Nov 9, 2018 01:12 |
|
Interesting. Responsiveness seems like it is probably one of the most painful parts with how many different resolutions and screen sizes there are now, so that seems like a big plus. Does that big asset dump make it take longer to load on slower connections, or is it pretty equivalent if done right?
|
# ? Nov 9, 2018 01:22 |
|
PierreTheMime posted:I still have to deal with SOAP occasionally and configuring WSDLs is a good reminder why most places don’t use it now. My God, imagine having data that you can validate against a schema! The horror!
|
# ? Nov 9, 2018 01:23 |
|
redleader posted:My God, imagine having data that you can validate against a schema! The horror! My experience with all the Java tooling was that it was garbage and there was no way to generate the necessary bindings without pointing it to a deployed server. And pointing it to the server would create all the service files with hard coded urls to the server we synced against. I wasted so much time on fixing builds and poo poo that having a schema lost any value. I ended redoing all the poo poo with a RESTful web service that accepted and returned Protobuf messages. The protobufs effectively turned into the schema, but with better serialization/de-serialization performance and a smaller memory footprint over the wire. Also it had better client support since early Android xml was also garbage at the time.
|
# ? Nov 9, 2018 01:40 |
|
I freaking hate those "load as you go" pages. Many of them break the back button (looking at you Yahoo News).
|
# ? Nov 9, 2018 01:45 |
|
SOAP and WSDL exist solely to give IBM more money and are terrible. Are there any other things similar to /r/dailyprogrammer and the Euler project? The subreddit seems to be dead... Ideally more on the dailyprogrammer side than the euler project i.e. not completely focused on maths.
|
# ? Nov 9, 2018 08:13 |
|
22 Eargesplitten posted:Can someone explain in idiot terms what RESTful means? Going off of the Wikipedia page it sounds like pretty standard best practices for efficiency and security stuff, but I'm wondering if I am missing something that makes it more complicated than what you would get taught in JS 101 at whatever college. I'm applying to entry level dev / application support positions and it comes up a lot. it means, roughly: "we use http", and "we use buzzwords we don't understand" here's the rough timeline of rest 1. the web browser and http are invented 2. someone writes a thesis about the design of http and how the browser influenced it 3. people read the browser thesis and went "aha, this is about apis" 4. literally no-one. I mean no-one, uses the term rest or representational state transfer properly. If you'll forgive me, here is a burrito metaphor: using a browser is the burrito, the thesis describes the ingredients, and everyone who read it made a stir fry with the rice, meat, and beans. REST, or Representational state transfer, is the latin name for opening a link in a new tab in a browser. The state is the part of the application you want to open (like your inbox), the repesentaton of the state is the URL in the link you're clicking on, and the transfer describes the whole back-and-forth of downloading the HTML with that URL in, and then requesting it. Meanwhile, RESTful has come to mean some API that uses HTTP, and probably uses JSON too, but there isn't much of a consensus, and it entirely misses the point of what representational state transfer is about. Representational state transfer is what makes the back button work, why you can refresh a broken page and not have to restart from the beginning, and why you can open links in a new tab. (Unless it's twitter, where breaking the back button is but a footnote in the list of faults).REST is about using a browser, just one, to access different services with different interfaces. The thesis envisoned a generic user-agent, or browser, that could interact with a variety of services using common formats and protocols, built around hypertext or navigation. The big idea that each window in you application had an address, and the browser didn't need to know all of them up front but would follow links between them. Meanwhile RESTful is about expecting your users to write a client library for your web service. At least there's a rough consensus around how to use HTTP: GET for read only operations, POST for pragmatic non-repeatable operations, PUT and DELETE for people who want to be more 'correct'. A 'Restful' service will at least use JSON, Protocol Buffers or Thrift, so you won't have to write as much code as you would with a custom format. This has nothing to do with representational state transfer, but it sounds cool and it's easier to understand than a thesis decomposing the architectural constraints of a web browser. Similarly to how agile started like as a manifesto before becoming turning into "We use a bug tracker, have a planning meeting, a retrospective, and standups", REST has effectively lost all meaning in modern usage. Even the most die hard practitioners of REST have yet to build another browser, but we have a lot new ways to expose a table of posts and users and very little shared tooling. A website is far more restful than a webservice, a screen scraper is usually far more rest-like or restful than any custom api library, usually. Single page web applications, or applets, shockwave players, and other forms of plugins or code-on-demand aren't exactly using representational state transfer, but they aren't violating it either—the thesis talked at length about supporting gateways to legacy systems or existing services. The thesis, if about anything, attempted to describe the underlying constraints and design principles in building a system capable of such loose coupling REST is about browsing the web. REST is about using one client, the browser, for a variety of different services, rather than having an email client, a news client, a chat client The thesis described a utopia where we could use the same lump of code to interact with third parties without knowing everything up front, and not having to use custom clients for each and every service. By and large—browsers have done this, but only for humans. There are examples of browsing in apis, but they are few and far between. One notable example of browsing in apis is within plan 9. You create a socket by opening `/net/tcp/clone`, reading the filename given and opening the `/net/tcp/filename` as a result. You could even pretend it's a relative file path too. Outside of quirks like this, the closest most developers get to using an api lke this is when they write a screen scraper. Using an RESTful API is quite unlike using a browser. Using a browser is akin to the process of going to a restaurant, asking for a menu, then ordering. What we have done instead is to built restaurants where you need to download an app to your phone, but most of the time you have to write the app yourself. We then write a blog post explaining how this is exactly the same experience of asking for a menu, calling it MENUful. (For custom OAuth, imagine the restaurant has food poisoning). The whole point of REST is using a browser—using the _same_ browser for a variety of different remote systems—rather than the hell hole of each client-server application using a unique front end and protocol. tef fucked around with this message at 13:11 on Nov 9, 2018 |
# ? Nov 9, 2018 12:58 |
|
Eggnogium posted:I think REST is one of those things where wikipedia is not the right place to learn, as the layman's usage is much simpler/concrete than the formal definition. RESTful services are: this where you start to go wrong quote:2) typically use the path of the URL and HTTP operation to determine the API being called and its high-level parameters (e.g. DELETE https://foo.com/_api/cars/123 = DeleteCar(123)) in restful system LIKE THE WEB BROWSER you go to a web page, click on links and forms in a restful system, urls are opaque to the client the point of GET vs POST etc is so that intermediaries can cache or retry requests the client shouldn't care quote:3) use cross-platform textual representations like json or xml for more complicated request/response data the thesis says a uniform interface is something that isn't specific to the application this means using something like HTML, more than it ever will using JSON quote:4) each operation should be a single request and the client shouldn't have to store any state this is another misreading of the thesis the idea is that http proxies, caches, load balancers don't use sockets, or sessions but requests and responses the idea is that although you have a client session, you don't expect the intermediaries to store state 22 Eargesplitten posted:I see, that makes sense. So it is a formal name for a pretty standard way of doing things. it's a term that got popularised that meant "my http is better than your http" quote:While I'm asking dumb questions, what's the difference between a "Single Page Application" and just a website that's all on one page and sends you to sections with different IDs when you click on a link? It says it rewrites the page when you click, would that be something like creating form objects and such or would it be creating whole new "pages" (as far as the user could tell without looking at the URL)? Whenever I read about it, it mentions scrolling being an advantage on mobile devices, which sounds like the one page site that sends you to different parts. aside, single page apps are what the 'code on demand' part of rest is about tef fucked around with this message at 13:08 on Nov 9, 2018 |
# ? Nov 9, 2018 13:06 |
|
rest: wow, we can build rich interfaces over a simpler rpc-like protocol, by using HTML, URLS, and a browser! restful: wow, we can build CRUD interfaces unique to each service that are tightly coupled to a single client
|
# ? Nov 9, 2018 13:14 |
|
|
# ? Jun 10, 2024 11:26 |
|
22 Eargesplitten posted:Interesting. Responsiveness seems like it is probably one of the most painful parts with how many different resolutions and screen sizes there are now, so that seems like a big plus. The first load can be painful but the browser can/will cache some amount of it, and if the app is built well the code that changes a lot will be separated from the code that does not, so future visits will load quicker. Server and client are then happy since from then on they're essentially only talking in deltas, not whole pages.
|
# ? Nov 9, 2018 13:43 |