If so a script is definitely the way I'd do it with symbolic links, it should be pretty quick.
The Big Programming Thread - Page 896
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
bo1b
Australia12814 Posts
If so a script is definitely the way I'd do it with symbolic links, it should be pretty quick. | ||
Manit0u
Poland17197 Posts
On July 05 2017 10:58 bo1b wrote: I could be reading this wrong, but I get the impression you want to copy current files to new folders? If so a script is definitely the way I'd do it with symbolic links, it should be pretty quick. Exactly. But I can't use symlinks, I needed actual, physical files (needed to test other script that operates on files and how long will it take specific server to upload 50GB to S3). | ||
bo1b
Australia12814 Posts
Can do it fairly easily in shell script if you know it, if you don't a ruby script will work just as well. I'm guessing you work in some form of backend development? You probably know all this anyway haha. | ||
BrTarolg
United Kingdom3574 Posts
i can try to tackle that "find the first non unique letter in a string" def find_non_unique(y): target = [x for x in str(y)] for letter in target: if target.count(letter) > 1 return letter return "?" --- obviously doesn't cover all the edge cases yet (inputs could be numbers etc.) but it's a start! | ||
bo1b
Australia12814 Posts
Actually a really good simple way to implement data structures the more that I look at it. Try using some sorting algorithms - radix sort comes to mind. | ||
Manit0u
Poland17197 Posts
On July 05 2017 17:42 BrTarolg wrote: Ok so i'm still a noob, but maybe a little less nooby than before i can try to tackle that "find the first non unique letter in a string" def find_non_unique(y): target = [x for x in str(y)] for letter in target: if target.count(letter) > 1 return letter return "?" --- obviously doesn't cover all the edge cases yet (inputs could be numbers etc.) but it's a start! All is well. Except the task was to return the first unique letter ![]() | ||
Acrofales
Spain17852 Posts
On July 05 2017 18:51 bo1b wrote: An excellent opportunity to learn some different algorithms and data structures btw. Try chucking the values into a hash table and seeing what you can learn from it. Also, in regards to determining if the character is a letter or not, ascii tables are definitely the way to go. Actually a really good simple way to implement data structures the more that I look at it. Try using some sorting algorithms - radix sort comes to mind. To be fair, the sample code is python, so just use isalpha() ![]() Not quite sure how isalpha is implemented, but my bet would be that it uses simple comparison (>= a, <= z, same for caps). If it works with unicode it'll be more complicated, though. E: in Python 3 it works with unicode. So it probably uses unicode metadata. | ||
bo1b
Australia12814 Posts
| ||
Acrofales
Spain17852 Posts
I am trying to configure avahi-daemon on my raspberry pi to broadcast the service I just programmed, which needs to be discoverable automatically. It sorta works, but not quite, and I cannot figure out why not. If I use:
it works just fine, but that doesn't configure it to start automatically. For that I need to add it to a config, so I did just that. I added myservice.service in /etc/avahi/services with the following content:
This should work (according to all the documentation I've seen), but doesn't. It also doesn't work if I run
It doesn't give an error. It just doesn't publish my service (despite the log saying it read my config file). Now for the really fucky funky bit: if I copy the default ssh.service over from the avahi documentation and then RERUN the systemctl command above, it recognizes a "change" in the service files, reloads and then BOTH ssh and myservice are published correctly. Moreover, if I then remove ssh.service and run systemctl again, it recognizes that ssh.service is gone, and removes that service, but leaves myservice completely functional. However, if I reboot the device, it stops working again. Moreover, if I leave ssh.service and reboot it also doesn't work... I don't understand what is wrong. | ||
Manit0u
Poland17197 Posts
On July 05 2017 22:03 Acrofales wrote: Okay, I'm stumped. StackOverflow doesn't seem to know either (0 responses). It's not really programming. More fucky linux stuff that should work but doesn't: I am trying to configure avahi-daemon on my raspberry pi to broadcast the service I just programmed, which needs to be discoverable automatically. It sorta works, but not quite, and I cannot figure out why not. If I use:
it works just fine, but that doesn't configure it to start automatically. For that I need to add it to a config, so I did just that. I added myservice.service in /etc/avahi/services with the following content:
This should work (according to all the documentation I've seen), but doesn't. It also doesn't work if I run
It doesn't give an error. It just doesn't publish my service (despite the log saying it read my config file). Now for the really fucky funky bit: if I copy the default ssh.service over from the avahi documentation and then RERUN the systemctl command above, it recognizes a "change" in the service files, reloads and then BOTH ssh and myservice are published correctly. Moreover, if I then remove ssh.service and run systemctl again, it recognizes that ssh.service is gone, and removes that service, but leaves myservice completely functional. However, if I reboot the device, it stops working again. Moreover, if I leave ssh.service and reboot it also doesn't work... I don't understand what is wrong. Perhaps it has some problems with the socket? https://superuser.com/a/649970 | ||
Deleted User 3420
24492 Posts
1.)use bucketsort on the string, putting their index into the bucket that corresponds to their value (you'd have to adjust your bucketsort if you want capitalization or whatever) 2.) traverse each bucket that corresponds to a letter(we only care about letters right?). if a bucket contains more than 1 element in it's list immediately move to the next bucket 3.) return the first index from a bucket with only 1 element I think that this is roughly 1 traversal. Worst case n+however many ascii characters you are counting as letters. | ||
Acrofales
Spain17852 Posts
On July 06 2017 01:40 travis wrote: regarding the "return the first non-unique letter in a string", it's not actual code but what I would do is 1.)use bucketsort on the string, putting their index into the bucket that corresponds to their value (you'd have to adjust your bucketsort if you want capitalization or whatever) 2.) traverse each bucket that corresponds to a letter(we only care about letters right?). if a bucket contains more than 1 element in it's list immediately move to the next bucket 3.) return the first index from a bucket with only 1 element I think that this is roughly 1 traversal. Worst case n+however many ascii characters you are counting as letters. Doesn't seem great. You'd also have to find all your buckets with only 1 element, find all of their occurrences, and then pick the minimum. Come on travis, you can do better than that. As for my own issue: gonna learn about what avahi does with sockets. Doesn't seem too promising, but it's at least something I can muck about with ![]() E: well, still haven't figured out what the hell is wrong, but if I add "systemctl reload avahi-daemon" to my rc.local script, it works. Avahi is still a compete piece of shit, though. This is not the first problem I have had with zeroconf requiring a LOT of conf... | ||
Deleted User 3420
24492 Posts
On July 06 2017 02:11 Acrofales wrote: Doesn't seem great. You'd also have to find all your buckets with only 1 element, find all of their occurrences, and then pick the minimum. Come on travis, you can do better than that. ah shit you're right, well I didn't spend more than a couple minutes on it. gimme a little bit i'll redeem myself lol edit: ok i have homework to do but basically the best I can come up with in this small amount of time is to use what I already said except for just run through the string a second time, and look up how many of each letter you come across is in a bucket so worse case ~2n it's basically the same as just making an array that corresponds to characters and then incrementing them by 1 as you go through the string then go through the string again and return the first letter that has a count of 1 I actually want to think about this more, lol. it's a fun one but I gotta study for final ![]() | ||
mahrgell
Germany3942 Posts
so looping once over the string is enough.
| ||
![]()
NovemberstOrm
Canada16217 Posts
| ||
Blisse
Canada3710 Posts
+ Show Spoiler +
| ||
mahrgell
Germany3942 Posts
On July 06 2017 05:16 Blisse wrote: Am I missing something? Thought this was really straightforward? + Show Spoiler +
your find unique doesnt work and will always return the first character of the string, given that it surely will have an entry in your map, thus the count(c) will always return 1 on it. And even if you fix that bug in your code, I think it was never argued that this problem is a challenge to solve, but the question is how to solve it efficiently. And that optimization is the way more tricky part with a lot of probably interesting potential ideas. Using maps is certainly something I would avoid in that regard! | ||
BrTarolg
United Kingdom3574 Posts
On July 05 2017 20:29 Manit0u wrote: All is well. Except the task was to return the first unique letter ![]() Lmao I can't believe how badly I'm reading this problem hahaha Oh well == 1 then :p Its ok I'd rather fails now than in an interview Mostly tackling stuff on codewars atm, I'm a lowly 5/6kyu but making progress Edit: tbh from codewars I'm learning I could solve most of these really simply in a few lines but I'm really reliant on the inbuilt python functions and clever use of list comprehension. Not sure how I would do without but the simplest I guess would be to make a count function within the function (returns a count number, very simple) and then use that | ||
Deleted User 3420
24492 Posts
http://www.cs.umd.edu/class/summer2017/cmsc351/fin-prac.pdf | ||
Manit0u
Poland17197 Posts
On July 06 2017 05:28 mahrgell wrote: your find unique doesnt work and will always return the first character of the string, given that it surely will have an entry in your map, thus the count(c) will always return 1 on it. And even if you fix that bug in your code, I think it was never argued that this problem is a challenge to solve, but the question is how to solve it efficiently. And that optimization is the way more tricky part with a lot of probably interesting potential ideas. Using maps is certainly something I would avoid in that regard! Actually, it's an algorithms interview question everyone is asked at my company. Making it optimal isn't important. Making it work is semi-important (good attempts count, even if they fail somehow - my initial solution could enter an infinite loop but I've corrected it when it was pointed out and it was fine). 90% of the candidates can't make it past this test ![]() My pretty shitty solution during the interview:
Obviously, it was a bit more complicated, since I've decided to do it in C for whatever reason. The only optimization was that with each pass it had to go through smaller char arrays (but still, it was quite a bit of work). My mind simply went blank and I went down to absolute basics of programming, without using any existing libraries or built-in functions for it. | ||
| ||