r/dailyprogrammer • u/Coder_d00d 1 3 • Jan 02 '15
[2015-01-02] Challenge #195 [All] 2015 Prep Work
Description:
As we enter a new year it is a good time to get organized and be ready. One thing I have noticed as you use this subreddit and finish challenges you repeat lots of code in solutions. This is true in the area of reading in data.
One thing I have done is develop some standard code I use in reading and parsing data.
For today's challenge you will be doing some prep work for yourself.
Tool Development
Develop a tool or several tools you can use in the coming year for completing challenges. The tool is up to you. It can be anything that you find you repeat in your code.
An example will be shown below that I use. But some basic ideas
- Read input from user
- Input from a file
- Output to user
- Output to a file
Do not limit yourself to these. Look at your previous code and find the pieces of code you repeat a lot and develop your own library for handling that part of your challenges. Having this for your use will make solutions easier to develop as you already have that code done.
Example:
I tend to do a lot of work in C/objective C -- so I have this code I use a lot for getting input from the user and parsing it. It can be further developed and added on by me which I will.
(https://github.com/coderd00d/standard-objects)
Solutions:
Can be your code/link to your github/posting of it -- Also can just be ideas of tools you or others can develop.
24
u/adrian17 1 4 Jan 02 '15 edited Jan 03 '15
A pretty simple idea here: making a new directory for every new challenge isn't a big hassle, but it would be cool if I could simplify this.
So after a few glances at Sublime Text 3 documentation (which isn't very good tbh), I made this plugin: http://puu.sh/dZsBF/66bd9a0884.gif
It loads the title of the newest challenge, makes a new subfolder with that title, creates a new file with initial contents (easy to edit, so you can use it for any language) and extra comments at the top and finally opens the new file in Sublime and places the cursor in chosen place.
Repo: https://github.com/adrian17/DailyProgrammer-ST3-Plugin
Usage: If you have Git, just clone the repo to your Packages directory. Without Git, download both files and place in a subdirectory (of any name) in Packages directory. Edit the config variables in the script to your liking. Remember to change the challengesPath variable.
Edit:
A big update, now you can also start existing challenges. Loading all of them for the first time takes some time, but they are stored in a config file and subsequent reloads are almost instant. It's also useful for quickly jumping to challenges you've already done.
Gif: http://puu.sh/e0OxF/6ddd6da1c9.gif
4
u/[deleted] Jan 03 '15 edited Jan 06 '15
I've been working on an interactive text processor for all the wordy challenges that I like to post :3
I actually got the inspiration from /u/skeeto demonstrating his emacs setup on a google hangout session, in particular, the live filtering of all his internet history.
A link will be up later with a very crappy demonstration :D
Here's the YouTube demo
It's also on Github Like I said, quite a lot still left to implement with the biggest being to move it all over to curses for a much friendly user experience.
Here's an update
2
u/G33kDude 1 1 Jan 02 '15 edited Jan 04 '15
I was developing a simple class based GDI wrapper in AutoHotkey for displaying the output of various challenges I do in this subreddit. It's not fully featured yet and there's still a strange bug I'm trying to work out involving inverting the Y axis for coordinates. This post might just be enough for me to pick up work on it again!
<snip>Now on github https://gist.github.com/G33kDude/aa6f31f85a533f49c632</snip>
Edit: Just fixed the bugs in it I knew about, and decided to write a sample script. It scrapes the entire challenge history of this subreddit and displays it in a graph. The X axis isn't terribly accurate, but it gives a general idea. Output: http://i.imgur.com/W63ve5o.png
Edit: I redid the code so that the three colors are aligned on the same X axis. This gives more accurate results, though the amount of space between points is not the same as actual time elapsed. http://i.imgur.com/xsS2cZ8.png
Edit: Fixed font smoothing and added a data smoothing slider http://i.imgur.com/tyooT77.png
2
u/PalestraRattus Jan 02 '15
I often have to use Random calls with various programs. Not here just a whole lot yet, but elsewhere all the freaking time. In many cases so many calls need to be done so quickly it's difficult to not wind up with giant streaks where X events are being called with in 1 tick of the same seed value. Also within C# you can't call a Dispose() method on the Random class. Meaning you can't just declare a new one each time or you'll wind up with a giant memory leak long before the garbage collector does anything about it. This also makes it difficult to reuse the same method a lot within the same time span and not get matching results.
I've fiddled with this a fair bit, but I'm not going to lie. I don't fully understand why it works. I just know that it works very well for the purposes I've needed it for.
C# Sample output with stats otw
2
u/Reverse_Skydiver 1 0 Jan 02 '15 edited Jan 03 '15
I do most of my work in Java and have a class called Library where I keep methods that I use often. Here's the class if anyone is interested. Comments are poor as it's still in the making and I keep updating it with anything that can be added. Feel free to suggest improvements!
2
u/AshtonNight Jan 03 '15
I am fairly new to this and only have built a couple of the challenges, so I don't know what to make. Does anyone have any advice as to what I should possibly make based on previous challenges?
2
u/[deleted] Jan 03 '15 edited Dec 22 '18
deleted 0.4762 What is ^^^this?
1
u/_morvita 0 1 Jan 03 '15
In my previous research, I used to do a lot of work that involved simple matrix algebra operations (determinants, multiplication, dot products, etc), so I put them all into a Python library that I could just call whenever I was writing a new script that needed one of these functions. They're all pretty simple to implement, but it might be useful for someone.
1
u/[deleted] Jan 03 '15
I am sort of already done/doing this. Although it's a kinda ambitious project and still a work in progress. I had shelved the project for some time now, but I ll go back to completing this now.
https://github.com/anupamkumar/colDB
1
u/Pretentious_Username Jan 03 '15
Python 2.7 Not an overly complicated piece of code but one I find very useful in tasks that involve dictionaries. Hopefully will be helpful to some less experienced coders.
The idea is you save the dictionary in a separate file which you can then edit and load easily. I tend to find myself using it a lot for storing all the inputs to a problem before I allow manual input.
For example in the SymLinks challenge I had a text file looking like this:
To use simply create your dictionary variable and assign the function result to it. i.e.
1
u/brycem24 Jan 05 '15
Just found about daily programmer and I love the idea. I am still learning how to program so my prep work is not as interesting as the others. However throughout the books I have been learning through I have been seeing recurring classes such as Book or Customer. I have decided to create a DLL (my first time) and instead of having to rewrite the classes per example I would simply create the classes from the DLL. So far I think it has really sped me up in doing the tutorials and I thank you for giving me the idea. I plan on adding more classes because next time I see the examples I am going to conquer them with great haste. Link to the git (still learning how to use it) https://github.com/brycem24/TutorialResources.git