|
Tea Bone posted:I need to generate a seemingly random alphanumeric string using an integer between 1 and 36^6 as the seed value. The string must be unique and I need to be able to regenerate that same string again by using the same seed. Wait, so do you need a random result, or do you need a 1-to-1 mapping between integers and strings? Something that's really random won't have a perfect distribution and will produce some strings for more than one input and some never at all.
|
# ¿ Oct 31, 2018 05:25 |
|
|
# ¿ May 3, 2024 23:26 |
|
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 |
|
that's literally the exact opposite of nosql
|
# ¿ Nov 25, 2018 02:27 |
|
It's like a 3d array but with one more dimension. In the same way that a 2d array is just a bunch of 1d arrays sitting next to each other in a row, a 4d array is just a bunch of 3d arrays next to each other. Same for 5d etc. In the end a 200-dimensional array is not really any more complex to work with than a 2-dimensional array.
|
# ¿ Dec 24, 2018 23:59 |
|
There are a couple of open source "personal media server" projects that already do this. (Somehow extract series from the filename and identify the episode title etc from an api lookup on TVDB or whatever.) You might want to check Kodi or Plex and see what you can crib off of them.
|
# ¿ Jan 6, 2019 18:39 |
|
DoctorTristan posted:There are any number of (paid) services that do things like scrape news sources for company names and push out a feed with the time stamp, ticker and some kind of sentiment score - the usual suspects in the financial data world (Thomson Reuters, Bloomberg, Factset, Nasdaq...) all offer something like this. It sounds like he's asking for a set of articles that make concrete measurable predictions, and then a dataset showing how accurate those predictions turned out to be. Not a comprehensive list of every "Apple is good"/"apple is bad" blog alongside a graph of the apple stock price.
|
# ¿ Jan 9, 2019 09:07 |
|
So the A objects all know what their "default" options should be anyways, since they use those to initialize the options class, right? Just make all the values in the optionsForAnA nullable, then have the A class use its own default value for fields that are null in the options. Then rather than needing to populate the options class with appropriate defaults on construction, you just populate it with nulls, which'll work universally for any A.
|
# ¿ Apr 14, 2019 08:21 |
|
I really really doubt you need to set up a database for 50 whole rows of simple numbers. Unless there are a bunch of different scratchoffs with different prizes from each state? I don't really know how all that works.
|
# ¿ May 14, 2019 23:36 |
|
Rocko Bonaparte posted:I'm suffering the prep for the programming interview algorithm lottery and decided to look at the closest points problem based on experiences relayed from a friend. I implemented something that seems to work but actually slower than brute force. It looks like the number of distance calculations I compute is the dominant factor. When timing the code, the disparity is proportional to the number of distance calculations I make. I am making more distance calculations using what should be the more efficient solution that is dividing the space. I'm assuming I am doing something stupid so I thought somebody would want to play with it. Your optimized solution is buggy because you've confused two different concepts of distance. The best_pair class is actually storing the square of distance, but then later on you're doing code:
Since you're not squaring the distance here, the check is incorrect and you end up going on to the expensive inner loop for lots of points that could not possibly be valid. If your closest points have a distance less than 1, this will actually throw out valid results too and result in bad answers. e: the paper also mentions creating the sorted list of y values once and just filtering it each time, whereas here you're sorting it again each time you recurse. RPATDO_LAMD fucked around with this message at 23:18 on May 20, 2019 |
# ¿ May 20, 2019 22:45 |
|
The algorithm would still work if that wasn't true, though. The complicated moon elf crap is just for the proof that that border-check is O(1) time complexity
|
# ¿ May 22, 2019 11:12 |
|
Dumb Lowtax posted:What on EARTH are you all talking about just scroll up Rocko Bonaparte linked a paper describing an algorithm, and referred to a confusing step in the algorithm as magic.
|
# ¿ May 22, 2019 22:30 |
|
e: wrong thread
|
# ¿ Jun 30, 2019 19:59 |
|
Scionix posted:this is maybe a really stupid question I googled "C# lorem ipsum generator" and apparently yes e: here's another one RPATDO_LAMD fucked around with this message at 07:36 on Nov 7, 2019 |
# ¿ Nov 7, 2019 07:33 |
|
Hash collisions are still relatively rare so you could get the benefit of cache-coherency for the common case and only have to deal with cache misses on the uncommon case that a key has collisions. Better for cache than making every bucket a linked list. Or you could do the variant where the base node of the linked list is physically inside the hash table (instead of a pointer to the first node), so you again only have to deal with indirection / cache misses for keys that collide with something.
|
# ¿ Nov 14, 2019 07:07 |
|
Dominoes posted:So uh... What's a monad? Or is this Worth Its Own Thesis? Simplified bad answer: Basically, it's a higher level type like "maybe" that can be used to create types like "maybe int" or "maybe butt", and it comes with a set of functions to do things like finagle using a "maybe int" with a function that just wants a normal int, so (fake syntax) map(square, maybe 2) produces "maybe 4" and map(square, none) produces none.
|
# ¿ Dec 24, 2019 19:43 |
|
Dominoes posted:Do you use Vim and are under 40 years old, or do you know anyone who falls into this category? I've tried to like it because I hear good things about it on the internet, but my current hypothesis is it's exclusively used by guys who learned it decades ago and are either used to it, or are subject to the sunk costs fallacy. I'm a CS student. I use the vim keybinds extension in emacs just because the default emacs hotkeys are so ludicrously anti-ergonomic. I've worked on group projects that were only buildable as Visual Studio solutions so I've used a "normal" IDE as well, and it's fine on a desktop with a proper mouse. But when I'm working on my laptop it's way nicer to be able to just do everything from the keyboard. e: I was already used to the vim-style movement keys before I started programming because I played a lot of old roguelike games like Nethack and Angband when I was younger, and they used vim keys for movement. So maybe it's still Stockholm syndrome RPATDO_LAMD fucked around with this message at 07:12 on Mar 13, 2020 |
# ¿ Mar 13, 2020 06:58 |
|
Twitch chat definitely has some kinda API, since there are desktop apps for it.
|
# ¿ Apr 26, 2020 03:38 |
|
Might not be the issue but are you using the same version of python as the guide? Python2 and Python3 have enough differences that you'd run into a bunch of syntax errors if there was a mismatch
|
# ¿ Sep 17, 2020 17:46 |
|
credburn posted:Right now my biggest problem is that some keys have multiple values. I can't for the life of me figure out how to update the key within the while loop in which all this is happening. When you have a problem like this, you should stop and consider how you're structuring your data. It sounds like currently when you get input like "20: Gunsmoke" you are using 20 as the key and gunsmoke as the value. In a dictionary, each key has to be unique, but values can be duplicated as much as you want. When you organize your data like this, you are basically implicitly saying "there can only be one show with 20 seasons, and it is gunsmoke". Then when you get "20: Law & Order" as input later, you get problems. On the other hand, if that code got "21: gunsmoke" as an input, it would be perfectly happy storing that since 21 is a new unique key. The problem is that your key, "20" is not actually a unique identifier for the TV show. Multiple tv shows might have 20 seasons, and a show's season count might even change after the fact. So using the season count as your dictionary key causes problems. To fix it you have to change how you organize your data. The simplest solution is to use the tv show as the key and the season count as the value in your dictionary -- there's only ever one instance of each tv show, and duplicate values are fine. Another solution would be to use a list of pairs instead of a dictionary, like this: code:
edit: spoilered the "answer" since you might not want to just hear it RPATDO_LAMD fucked around with this message at 03:40 on Mar 14, 2022 |
# ¿ Mar 14, 2022 03:35 |
|
Gin_Rummy posted:Well the issue I run into there is that I can’t run the code independent of their powershell script. I’d be just fine if I could debug via VS Code or whatever (i don’t even think I can use pdb since the shell will probably collect that output as well?), but the only way to execute anything without getting a dependency error right off the bat is through executing run (runs the program) or test (initiates pass/fail checks on their automated unit tests) on their script. OK but how does the powershell script actually call your python program? Like what is the specific line of the script that calls it? That is the important detail for figuring all this out. If it is just redirecting stdout into a file like .\mypythonthing.py > output.txt you can just modify it to use the powershell buildtin "tee". .\mypythonthing.py | tee --filepath output.txt will send your program output to both stdout and the file. You can also connect your debugger to an already-running process. Stepping through with a debugger and being able to inspect variable values, step one line at a time etc is way more helpful than stdout-based "printf debugging" anyways. If your program isn't interactive, you might need to add some temporary bit in your program to wait for user input before beginning so you have time to attach the debugger before it runs. RPATDO_LAMD fucked around with this message at 21:21 on Mar 22, 2022 |
# ¿ Mar 22, 2022 21:19 |
|
Those are features in Jetbrains' upcoming editor, "Fleet". But it's currently in "closed preview" state and you can't buy it. Keep an eye out for when it becomes available, I guess. https://www.youtube.com/watch?v=ow5kdhDa_pk The video shows off the multi-person editing stuff at 2:48 and 5:21, including running some tests and seeing output in the latter section. RPATDO_LAMD fucked around with this message at 21:56 on Apr 2, 2022 |
# ¿ Apr 2, 2022 21:53 |
|
KillHour posted:The goal is to offset by the normal, yes. And it's definitely not working right. You're right - it's going along the tangent of the curve sometimes instead of the normal of the curve, because the normal is the tangent rotated 90 degrees, which is the same as flipping either the x or y of the tangent (depending on the direction you want to rotate). So what's happening is my logic for "when do I want to flip the x or y or both tangent signs to get the correct normal?" is wrong, and it's wrong because I don't know enough about the underlying math to know what the correct algorithm is, and Google is dropping me into the middle of a calculus / matrix algebra lesson. You haven't shown any of the actual math forumulas you're creating these shapes with so I'm pretty unclear on this, but when you say "tangent" do you mean the trigonometric tan function or the tangent line to the curve? It seems like you are using those two interchangeably. What you actually want is a vector that is tangent to the curve in a calculus sense of the word tangent, not the trig tan function. Then you can simply rotate that vector by 90 degrees and you will get the exact normal you want: a vector pointing perpendicularly out from the curve that's on a consistent side every time. (Make sure to normalize it first though so it is a consistent length) To rotate a vector <x,y> by 90 degrees you just transform it into either <-y, x> or <y, -x> depending on whether you want to rotate counterclockwise or clockwise. If you do that you should get the behavior you want. If your curve is defined by y = sin( at + b) and x= cos(ct + d), the tangent vector v at t should be v_y = a * cos (at + b) and v_x = -c * sin (ct + d) RPATDO_LAMD fucked around with this message at 06:43 on Apr 11, 2022 |
# ¿ Apr 11, 2022 06:36 |
|
What does it look like on a non-circle shape? Circles can hide a lot of errors with this kind of thing, like with the tan thing above. But it looks like your "rotate" section is not actually rotating the vector. The important thing is that you have to swap the values of x and y, not just multiply x by -1 as you're doing here. For example, if a vector's value was <100, 2> going very far to the +x direction and a tiny amount in the +y direction, the perpendicular vector would be <-2, 100>, going very far in the +y direction and a small amount in the -x direction. If you swapped it to <-100, 2> instead, you would get a vector that was almost horizontal, just like the original -- not rotated by 90 degrees at all.
RPATDO_LAMD fucked around with this message at 08:49 on Apr 11, 2022 |
# ¿ Apr 11, 2022 08:46 |
|
KillHour posted:I edited my post above with a more complex example. I just switched it back to a circle temporarily to reduce the number of variables in what could have been causing the wobbling. I'm swapping the x and y on the normalize function under the rotate section. Here's the final (working) graph. Oh nice, congrats! KillHour posted:Finally gently caress. Thanks for the help. I probably would have literally sat there and built some kind of ridiculous truth table to figure out how to force tan to do what I want when there was a much simpler algorithm (although I have no loving idea how it works) That formula is just a regular old-fashioned derivative. I don't think there is a way to make the tan thing work.
|
# ¿ Apr 11, 2022 09:09 |
|
foutre posted:Not sure if this is the best spot for this, but is there any way to use the parts of the Spotify API that require user authorization without actually loading up a browser with the redirect url at some point? Rather than running a web browser on your raspberry pi it seems like you should run a web server (which should be more lightweight). Serve a webpage on your local network that has a "log in through spotify" button and then just visit that page on your phone. That's the method Spotify shows off on their own web api tutorial page at least. Their examples are in nodejs w/ Express but you should be able to do basically the same thing in Python with Flask. RPATDO_LAMD fucked around with this message at 07:38 on Apr 17, 2022 |
# ¿ Apr 17, 2022 07:34 |
|
Gothmog1065 posted:I'm having a dumb, and google isn't giving me a good answer. This is in shell, KSH 93 mainly. Echo does not interpret escape sequences like \n, so it's outputting the literal characters '\' and 'n' rather than the whitespace sort wants. It seems like code:
RPATDO_LAMD fucked around with this message at 22:09 on Apr 27, 2022 |
# ¿ Apr 27, 2022 22:06 |
|
Yeah uh this sounds like the typical X-Y problem where you have one thing you're trying to do, you've decided OCRing the screen from C is somehow the best solution, and now you're asking about how to do ocr in C instead of asking about your actual end goal. I'd suggest looking into autohotkey if you're trying to mess around with graphical windows programs somehow but really I have no idea what you're trying to do.
|
# ¿ Apr 29, 2022 00:55 |
|
cheetah7071 posted:this is an idle curiosity more than something truly important but: what is the actual algorithm for dynamic memory allocation? When I call new or malloc, what does the assembly that generates actually do? It's typically an intrusive linked list, or more often a collection of several linked lists containing free chunks of different sizes. You might have one linked list each for memory chunks of 16, 32, 64, etc etc bytes and just hand out the smallest size that fits what the caller needs. If a caller allocates close to 512 bytes, you just pull an arbitrary node outta the 512-byte free list. Different allocators will have different strategies for how they choose this arbitrary node to achieve goals like keeping cache locality for back-to-back allocations or minimizing fragmentation or etc etc. You also need logic for handling splitting up chunks of memory (e.g. if you only have 512-byte chunks left and a user tries to allocate 32 bytes, you don't want to waste tons of memory) and for coalescing adjacent small chunks back together into big chunks again (e.g. after the user allocates and frees a few thousand 32-byte objects, they might try to allocate a 512-byte object again, which means you need some efficient logic that can figure out when a bunch of smaller chunks of free memory are all adjacent and can be combined into one larger chunk). And if you're totally out of memory you grab another memory page from the OS/kernel. I had to write a little toy memory allocator for my data structures class, although it only had to deal with one size of allocation so I didn't get into all the crunchy memory coalescing algorithms. For example here is the struct glibc's malloc.c uses: code:
Glibc uses different "bins" (linked lists) for chunks of different sizes, according to this scheme: code:
RPATDO_LAMD fucked around with this message at 07:50 on May 24, 2022 |
# ¿ May 24, 2022 07:45 |
|
Sirocco posted:I'm rendering sprites to two different textures in OpenGL, one's for the main game, and the other is for a cutscene. The point of this is so that I can run a shader program to have a transition effect where the cutscene moves onto the screen and pushes the gameplay screen off. For testing purposes, I've rendered a single small sprite to the centre of the second texture. But when I try to sample from that texture the sprite's not small but fills up the whole of it and I can't quite seem to figure out why. The transition works fine, but instead of a black screen coming down with a small sprite in the centre, I just get an enormous sprite filling up the screen. You're pretty light on details here, and the exact issue is probably somewhere in the details. Render-to-texture should work out just the same as rendering to a framebuffer. Does that single small sprite show up as the correct size etc if you render it to the main framebuffer instead of the texture?
|
# ¿ Jun 5, 2022 21:07 |
|
cheetah7071 posted:Is there any way to configure git to handle committing to two repositories simultaneously in a coherent way? I have a project where the main branch is still in constant flux, but as part of a deadline issue I'm sprinting to make a version of it that's suitable for internal use before then, which would, in better circumstances, be a private fork of the main branch because it will have some stuff that doesn't belong in the public repository. Is there a reason why your fork needs to be an entirely separate repository and not just another branch in the first repo? As long as you make sure to make separate commits for changes touching the universal files vs the project-specific stuff you can just cherry-pick all the relevant stuff back to the main branch. RPATDO_LAMD fucked around with this message at 02:28 on Jun 23, 2022 |
# ¿ Jun 23, 2022 02:25 |
|
Git doesn't have any internal concept of public or private. When you want to publicize things later down the road you can fork this current repo and delete all the branches and commits with private stuff in them. Hopefully by then you won't be simultaneously developing 2 versions of the same software? Otherwise it will be a pain and you'll have all the same problems you have right now all over again.
|
# ¿ Jun 23, 2022 02:58 |
|
LongSack posted:It may be, and there are a number of good suggestions in that thread, so thanks for that link. Other jetbrains IDEs have this feature under "actions on save" in the settings I would really be surprised if Rider was missing it since afaik their ides for different languages are mostly based on the same codebase with just a few tweaks
|
# ¿ Jun 29, 2022 16:06 |
|
rjmccall posted:Note that if this is an MMO or something like it, this sort of pattern is not at all unlikely to get detected and get your account banned. Presumably the reason you can't use autohotkey is "the anticheat detects autohotkey and complains"? So yeah if you are gonna program your own thing your first step is to reverse engineer the whole anticheat system, understand how it works and figure out a way to bypass it. Which is a lot of work! The people who do that sort work often sell their cheats for realmoney online.
|
# ¿ Aug 22, 2022 23:20 |
|
Yeah the big thing you have to watch for when rewriting your "technical debt" in new trendy language/framework of choice is that you're not just losing out on the main functionality but also on what's at this point 30-40 years of bugfixes and special handling for weird edge cases. There is no technical reason to ever use COBOL in a new project, it's just a very old language that used to be pretty popular and is now extremely unpopular. But there is no business reason to throw out and remake the 40 year old system you have in maintenance mode that still works fine. Especially for banks where reliability and correctness are worth way more to them than efficiency -- it doesn't really matter if it's running on a crappy old ancient mainframe and can't scale up the way a cool cloud-based containerized microservice thing could. It's still fast enough to do what it needs to do, and unlike e.g. Google the hardware costs are a negligible part of their total business. Having their fancy new java backend go down for an hour due to some unknown new bug introduced in development would probably cost the bank more money than maintaining the old COBOL crap for 10 more years. Although a lot of non-bank tech companies make this mistake anyways and throw out their 3-to-5 year old projects for full rewrites at the behest of their devs. It's a lot of fun for the devs! And probably better for the devs' careers too since they get to put whatever trendy modern framework they used in their resume. But it usually isn't too helpful for the actual business part of the business. RPATDO_LAMD fucked around with this message at 22:17 on Sep 19, 2022 |
# ¿ Sep 19, 2022 22:15 |
|
Circle buffers are cool! Suppose you want to store the last 20 results of some operation, and wherever a new result comes in you want to kick out the oldest piece of data. With a normal array you would have to constantly reorder it whenever you made a change. But if you use a circle buffer, instead of having a fixed head and tail position you keep track of a moving head pointer. Then the tail (the oldest piece of data) is always gonna be at (head + 1) % 20. So when a new piece of data comes in you just overwrite the tail and bump the head pointer forward by 1. The modulo makes sure that it loops around, so if the head is at 19 and you push something, the head ends up at 0 again. Push 20 more things and it'll loop all the way around and back to where it started. You can keep writing data forever and never run out of space. Modulos are also used for some cool math stuff, for example RSA Encryption is based on modular arithmetic. The public and private keys are chosen alongside some modulus m such that, for any x, ((x ^ pub) ^ priv) % m = x. But the kinds of numbers used for serious encryption won't fit in a 64-bit int so your language's built-in % operator probably can't be used to implement it, unless you use Python. RPATDO_LAMD fucked around with this message at 08:35 on Oct 3, 2022 |
# ¿ Oct 3, 2022 08:23 |
|
The situation of "a commit I thought was gone came back and jumpscared me" can happen if you reset or rebase away the original commit instead of just reverting it. Those operations both 'rewrite history' instead of adding on to the end of it, which is why they should only really be used locally, and why you can't do them on a remote repo without using force-push. So probably won't be an issue on your remote Repo A unless somebody is force pushing crap inappropriately.
|
# ¿ Oct 5, 2022 17:15 |
|
So your problem is that you are ordering by date but there are several rows with the exact same date field. You want to pick the latest or the lowest-row in the spreadsheet or whatever, but ORDER BY is a stable sort, so it never changes the order of things which actually have equal values in the ordered-by column. As an example, here is "select * order by A asc" and "select * order by A desc", you can see that the values which have the same date / "A" value actually stay in the same order between each: Seems like your best bet is to add an extra automatically-generated index column that has no dupes or equal values, and order by that. So add an index column that counts up from 1 to infinity, ORDER BY that index, and then you can do limit 1 with ASC or DESC to actually capture the first/last element guaranteed. RPATDO_LAMD fucked around with this message at 16:34 on Oct 17, 2022 |
# ¿ Oct 17, 2022 16:27 |
|
pokeyman posted:Really? Why do people avoid let? I remember var's scoping rules being pretty baffling. Though maybe I shouldn't be surprised about a community that rallied around automatic semicolon insertion. It's let vs const, not let vs var. It's just a question of not making variables mutable when they don't need to be. Rust has the right idea with everything defaulting to its version of const and needing a specific keyword to make it mutable. Like every other language has a best-practices styleguide of "use const whenever you can unless you specifically need a non-const variable" but many programmers just don't do it just because it's an extra keyword and more effort.
|
# ¿ Oct 27, 2022 17:19 |
|
Dominoes posted:Why is that I can compile a rust program using `cargo build`, and even if it has GUI, 3d graphics etc it'll just work on any modern version of the OS brand I compiled on, but when I try to compile C-based OSS software, it's a nightmare and usually doesn't work?* What does this have to do with the language and system dependencies? Could someone make a Cargo for C/C++? Because cargo is a centralized package manager which can automatically fetch the correct versions of dependencies from one authoritative centralized source. When the metadata files (cargo.toml) say your program depends on version a.b.c of serde, cargo knows exactly where it can find that package (and all the versions of it) -- https://crates.io/crates/serde. So it can easily automatically download the exact files your program needs. Same for js's npm, go's built in dependency manager, python's pip (kinda, but the fact that packages are systemwide instead of local is a huge PITA and needs its own workarounds with venv etc), and pretty much any other modern language C and C++ have no central package manager or official package repository -- they require you to janitor the dependencies yourself, and to run all over the place finding the "correct" versions of all the source files and binaries you need. Or using some ad-hoc hacky system that tries to do the same thing automatically.
|
# ¿ Oct 27, 2022 22:58 |
|
|
# ¿ May 3, 2024 23:26 |
|
There is a windows version of git, you don't need to install linux or whatever crazy stuff. https://git-scm.com/download/win Of course it's still a command line interface, if you want a friendlier gui there are many third-party gui clients. Github desktop is pretty crap, I recommend Git Extensions or maybe the free versions of git fork / gitgraken. Github, btw, is just a company that offers a git hosting service. So it's just a regular ol' git repo that works with any non-github-affiliated git tool, there's nothing special about being a 'github repo' besides the fact the url has github.com in it.
|
# ¿ Oct 28, 2022 03:54 |