I feel like getting Ruby on Rails up and started is kinda difficult, especially for Linux herp-derps like me. I will start by saying that I kinda suck at Linux, so it took me a while to set up Ruby on Rails. But eventually I found a procedure that will work! I'll keep things short and simple, since you probably just want Ruby on Rails up and running ASAP!
We're going to do [pretty much] everything from the terminal. So one thing to keep in mind is, I'm going to use "yum" since I use Fedora, but if you use Debian, Ubuntu, or Mint, you would use "apt-get" in place of all the times I used "yum". The easy way to do this is, if one of them didn't work, then try the other!
I read online that all the kool katz these days use this thing called RVM to manage their Ruby versions, so I decided to hop on the bandwagon and do it too (and so should you).
Now, enough talking... open the Terminal and let's get started. The important stuff will be in red, so you can ignore all of my noobish comments. Every line that starts with a $ means that you type everything after the $ into the terminal, and every time you you do a "sudo yum install" it will ask for your password (so type that in when prompted) and ask if it's OK to install stuff (so type "y" to confirm).
Step 1: Update your pre-existing packages
$ sudo yum update
Step 2: Install curl
$ sudo yum install curl
Step 3: Install RVM
$ \curl -L https://get.rvm.io | bash -s stable
Step 4: Load RVM
$ source ~/.rvm/scripts/rvm
Step 5: Install dependencies
$ rvm requirements
That should print out a bunch of crap, but we're only interested in the stuff immediately after "# For ruby:" under "Additional Dependencies." I don't know if it'll be verbatim when you're reading this, but as of now, that's how it goes.
Copy all of the stuff after "sudo yum ..." until the end of the paragraph and paste it into the current line in the Terminal, and then press [ENTER]. This could possibly take some time.
Step 6: Install Ruby and set a default version
The current version as of now is 2.0.0, but it might be different, so do a Google search to find out what version we're currently at.
$ rvm install 2.0.0
$ rvm use 2.0.0 --default
This part might take some time... so go play Intergalactic Exterminator while you wait, since that's what I did.
Step 7: Install RubyGems
$ rvm rubygems current
Step 8: Install Rails
$ gem install rails
This part also might take some time, so go ahead and beat another few levels in Intergalactic Exterminator. When you beat the game, the installation should be finished [for a while, probably].
Yay! You're done. But you might have run into some errors. One of the errors I remember that came up was the sqlite3 problem.
Step 9: Fix Errors (i.e. Google search)
So here's how you fix that particular error (blue text for possibly important):
$ sudo yum install sqlite-devel
$ sudo yum install ruby-devel
$ gem install sqlite3
A good way to check if "rails" is installed/working is typing the following command. You should get some version number like 3.2 or something. It might not be the exact same when you're doing it, but it's 3.2 right now for me.
$ rails -v
Now you can use Terminal and navigate to the folder you want to put your first Ruby on Rails program in. If you don't know what I mean, read up (i.e. do a Google search) on the cd command. Now you simply type (of course replace "<project-name>" with the name of your project):
$ rails new <project-name>
After that, it's all up to you where you want to go! I'd say you should look at what a scaffold is since it makes starting up quickly very easy. Don't forget to cd into your project's folder!
Step 10: One last thing - Starting RVM automatically with Terminal
Now one thing I found rather frustrating was that whenever I closed terminal, I couldn't use "rails" in Terminal anymore, unless I typed the following command:
$ source $(rvm 2.0.0 do rvm env --path)
Which is really annoying to do every time. So I did what any rational human would do -- I did a Google search. Took a little bit, but I was able to scrape enough information to come up with a solution!
$ gedit ~/.bashrc
A text-editing program should open up. Add one line to this file containing the following:
source $(rvm 2.0.0 do rvm env --path)
Now, every time you open terminal, you are able to just do "rails" stuff right off the bat! Neat!!!
Well, I hope this was able to help you. If it was, then it's probably because I'm a complete amateur (right now, at least) in doing stuff on Linux, so I have to keep it simple (and without complex explanations that make no sense to noobs like me anyway). I feel like if I had these step-by-step instructions, it would have saved me quite some time and frustration in getting Ruby on Rails set up and ready.
Showing posts with label Program. Show all posts
Showing posts with label Program. Show all posts
Saturday, March 2, 2013
Tuesday, January 4, 2011
LaTeX
I found out about LaTeX last year (oh wait -- 2009's two years ago now!). It's similar to Word in that it makes typed documents, but it's really not the same.
Microsoft Word is a WYSIWYG (What-You-See-Is-What-You-Get) program, meaning that whatever is currently displayed on the screen is exactly what you're getting. If you hit the print button, it will print out the document for you, as it is shown on the screen.
However, LaTeX is like programming. You type in "code" that tells the program what kind of document to create and what text, pictures, and other stuff to include in it. Then, you "build" your document, similar to compiling code in a programming language like C#. It can output to several different file formats, but I prefer the PDF because it is so universal and widely used.
There are a few advantages of this:
Now that you're totally excited and want to try this out, you probably want to know how to get it on your computer! Luckily, it's really easy.
First, download and install MiKTeX, which includes all the files you'll need to format these documents and build them from the ground up. I recommend going to http://miktex.org/ and downloading the latest version. You can either get the Basic or Complete setup. It's barely worth mentioning due to the obviousness, but the Basic setup will take less time to install than the full thing. NOTE: Remember what folder you installed MiKTeX to because you'll need to reference that folder later!
Now that you have the files that form the backbone, we need some User Interface. TeXnicCenter was created to work with MiKTeX and make your job as easy as possible. Go to http://www.texniccenter.org/resources/downloads to download it, and again, get the latest stable version.
This one should install pretty quickly, so just follow the prompts. When it's done, run the program, and it will give you a wizard to help you set it up. It will ask for the location of the executables, so go to your install folder to MiKTeX, and find the a folder called "miktex". In that folder, there's another folder called "bin". Copy the entire address of this folder and put it into the prompt for the path to the executable files. You can leave everything else blank.
If you screw up, then you can just open up TeXnicCenter and go to "Build" --> "Define Output Profiles..." (or Alt + F7), and click "Wizard..." at the bottom-left corner of the dialog window that pops up. Now you can try again!
After you set it up correctly, it's all yours to play with. First, you should change the dropdown menu to say "LaTeX => PDF" unless you want to build to some other format. I like to rearrange the toolbars so that they only take up 2 rows at the top. Then, I close the "Navigator" on the left side so I can have more screen space. It's all up to you to do what you want to make it as nice as possible. You might want to play with the options in the "Tools" menu.
Now you can create your first document. I recommend that you start with this as a template, since LaTeX needs a few things before you can actually type out your stuff. Here's the code that you can use:
\documentclass[12pt,letterpaper]{article}
\usepackage[margin=2.5cm]{geometry}
\begin{document}
\title{}
\author{}
\maketitle
\end{document}
In the blank line, you can start typing out your document. You can put your title in the brackets after "\title" and your name in the brackets after "\author". If you don't want a cool, fancy header, you can just delete the lines between (but not including) "\begin{document}" and "\end{document}".
Now you have to build an output file. Just go to the "Build" menu and then use the things there. A few nice shortcuts are [Ctrl + Shift + F5] to build and view the output, [F7] to just build the file, and [F5] to just view the output.
That was just a very brief introduction to the world of LaTeX. I'm not a complete pro at this, but I'll probably make a post in the future about how to do the basics.
Have fun making professional-looking PDF documents now!
Microsoft Word is a WYSIWYG (What-You-See-Is-What-You-Get) program, meaning that whatever is currently displayed on the screen is exactly what you're getting. If you hit the print button, it will print out the document for you, as it is shown on the screen.
However, LaTeX is like programming. You type in "code" that tells the program what kind of document to create and what text, pictures, and other stuff to include in it. Then, you "build" your document, similar to compiling code in a programming language like C#. It can output to several different file formats, but I prefer the PDF because it is so universal and widely used.
There are a few advantages of this:
- The document after it is processed appears much more professional, and uses advanced typesetting algorithms and such. For example, if there are two "f" letters in a row, they are supposed to be connected. Of course, Word doesn't do this for you, but LaTeX will.
- Although you can make Word documents into PDFs, it's not automatic whereas PDF files can be opened anywhere. The code can be edited with a simple text editor, such as the feature-empty Notepad that comes with Windows.
- You can even use online compilers, (just Google : "Online LaTeX Compiler"). That means you can do your stuff anywhere you want.
- LaTeX is designed especially for writing professional-looking reports, including scientific ones. As such, processing code for math typesetting (like the fraction bar, nested radicals, and Greek letters).
- You're learning how to use a handy tool that you might have to use when you go to college (or whenever you do professional science work).
Now that you're totally excited and want to try this out, you probably want to know how to get it on your computer! Luckily, it's really easy.
First, download and install MiKTeX, which includes all the files you'll need to format these documents and build them from the ground up. I recommend going to http://miktex.org/ and downloading the latest version. You can either get the Basic or Complete setup. It's barely worth mentioning due to the obviousness, but the Basic setup will take less time to install than the full thing. NOTE: Remember what folder you installed MiKTeX to because you'll need to reference that folder later!
Now that you have the files that form the backbone, we need some User Interface. TeXnicCenter was created to work with MiKTeX and make your job as easy as possible. Go to http://www.texniccenter.org/resources/downloads to download it, and again, get the latest stable version.
This one should install pretty quickly, so just follow the prompts. When it's done, run the program, and it will give you a wizard to help you set it up. It will ask for the location of the executables, so go to your install folder to MiKTeX, and find the a folder called "miktex". In that folder, there's another folder called "bin". Copy the entire address of this folder and put it into the prompt for the path to the executable files. You can leave everything else blank.
If you screw up, then you can just open up TeXnicCenter and go to "Build" --> "Define Output Profiles..." (or Alt + F7), and click "Wizard..." at the bottom-left corner of the dialog window that pops up. Now you can try again!
After you set it up correctly, it's all yours to play with. First, you should change the dropdown menu to say "LaTeX => PDF" unless you want to build to some other format. I like to rearrange the toolbars so that they only take up 2 rows at the top. Then, I close the "Navigator" on the left side so I can have more screen space. It's all up to you to do what you want to make it as nice as possible. You might want to play with the options in the "Tools" menu.
Now you can create your first document. I recommend that you start with this as a template, since LaTeX needs a few things before you can actually type out your stuff. Here's the code that you can use:
\documentclass[12pt,letterpaper]{article}
\usepackage[margin=2.5cm]{geometry}
\begin{document}
\title{}
\author{}
\maketitle
\end{document}
In the blank line, you can start typing out your document. You can put your title in the brackets after "\title" and your name in the brackets after "\author". If you don't want a cool, fancy header, you can just delete the lines between (but not including) "\begin{document}" and "\end{document}".
Now you have to build an output file. Just go to the "Build" menu and then use the things there. A few nice shortcuts are [Ctrl + Shift + F5] to build and view the output, [F7] to just build the file, and [F5] to just view the output.
That was just a very brief introduction to the world of LaTeX. I'm not a complete pro at this, but I'll probably make a post in the future about how to do the basics.
Have fun making professional-looking PDF documents now!
Monday, January 3, 2011
SparkNotes Compiler-Extractor
Ever find yourself in an English class in which the the text you're supposed to read is borderline incomprehensible? Or if you're "that guy" who always needs to read supplement texts AFTER reading the original to make sure you have complete mastery of what you were supposed to read?
Either way, you probably read the SparkNotes. Maybe you want to print them out and bring them to school so you can have a look at them in class. Maybe your teacher is so magnanimous that he/she lets you use your notes on tests and/or quizzes.
If you fall in any of those categories, then you can find use in the SparkNotes Compiler/Extractor. (If you're in middle school, you might not need this, but once you get into high school, SparkNotes will become your good friend, especially if you take higher-level English courses. Or if you're just completely lazy.) This way, you don't have to manually copy-and-paste the text (and waste a lot of time) for every SparkNotes page for every book that you're supposed to be reading.
I'd say that this program is pretty self-explanatory, but I'm the one who wrote it, so I'd think it's easy to use no matter what, right? Here's a quick run-through of how to use the program. You might want to just download and try the program first, and come back and read the rest of this post if you don't get it.
When you download the file ("SparkNotes Compiler-Extractor.zip"), you should extract the ZIP archive to wherever you want. In your unzipped folder, you should have 6 items (in no particular order):
Either way, you probably read the SparkNotes. Maybe you want to print them out and bring them to school so you can have a look at them in class. Maybe your teacher is so magnanimous that he/she lets you use your notes on tests and/or quizzes.
If you fall in any of those categories, then you can find use in the SparkNotes Compiler/Extractor. (If you're in middle school, you might not need this, but once you get into high school, SparkNotes will become your good friend, especially if you take higher-level English courses. Or if you're just completely lazy.) This way, you don't have to manually copy-and-paste the text (and waste a lot of time) for every SparkNotes page for every book that you're supposed to be reading.
I'd say that this program is pretty self-explanatory, but I'm the one who wrote it, so I'd think it's easy to use no matter what, right? Here's a quick run-through of how to use the program. You might want to just download and try the program first, and come back and read the rest of this post if you don't get it.
When you download the file ("SparkNotes Compiler-Extractor.zip"), you should extract the ZIP archive to wherever you want. In your unzipped folder, you should have 6 items (in no particular order):
- SparknotesCompiler.cs -- This is the source code for the program. You can open it, read it, change it, and basically do anything you want with it except sell it!
- c_SparknotesCompiler.bat -- Run this file to compile SparknotesCompiler.cs if you make any changes to the source code.
- SparknotesCompiler.exe -- This is the actual program. Run this program.
- SparkNotes.dotx -- This is a word template I created just for these SparkNotes. You just open the HTM document generated by Sparknotes.exe, copy all the text, and paste it into this template. There's more to it, so read on.
- SparkNotes.bas -- This is a Word macro for fixing up the formatting in your document. You'll find out more about this further down the post.
- styles.css -- This CSS file is needed for the generated HTM files to display correctly. NOTE: The HTM files that are generated must be put in the same folder as the styles.css file!
Now you can compile/extract a SparkNotes! First, run SparknotesCompiler.exe. The first prompt wants you to complete a URL. Let's compile Heart of Darkness by Joseph Conrad, for example. To get SparkNotes's URL for that certain book, just Google it: "SparkNotes Heart of Darkness". Probably the first one will be a link to it. You can either click it or just use the web address that you see: "www.sparknotes.com/lit/heart". All you have to fill out is the end of this URL, so type into the program: "lit/heart" and press [ENTER].
NOTE: If you get a URL like "http://www.sparknotes.com/lit/heart/section1.html", then just take out anything after the book's (probably abbreviated) name in the URL. Also, don't include the forward-slash at the end, like the program tells you in case you didn't read it because you don't like to follow directions.
If you're just a normal user, then I recommend you just leave all the files extracted in the same folder, meaning that you shouldn't move them around and separate them. You can move the entire folder if you want, just not the individual files. That way, it helps keeps styles.css in the same folder as your HTM files.
When the program prompts you for a name, you should just enter the name without a path, such as "Heart of Darkness" or "Heart of Darkness - Conrad" or something like that. Do not include the ".HTM" extension at the end; only put in the name. Any characters not allowed in a normal file name are not allowed here. The program will crash if you try something funny.
Now the program will start listing a whole bunch of URLs that it has finished getting the data from. It'll tell you how long it took. If you want to view the generated file right now, then press [ENTER] when the program is done (and gives you the prompt). Otherwise just close it and maybe look at your SparkNotes later.
If you want a Word document version, then you have to do some work yourself (don't worry, it's pretty easy -- I already did most of it for you!). First, you open up a new document based on SparkNotes.dotx by double-clicking it. Then, you copy and paste in the text from your HTM document. Remember to paste in the good-looking stuff that you normally read, not the HTML source code. I'd fix up the formatting at the top a bit so that the book's title and author's name take up less space, but that's just my personal preference. Next, you should change the name in the header (on the second page) to display the correct book title and author name in the corresponding places.
Here's something you might learn now: Word macros. If you don't know what they are, it's OK because I already made it for you. Because this post is already so long, I won't post the actual code here.
Here are the instructions for Word 2007. If you have a different version of Word, it's probably pretty similar. First, go to "View' on the ribbon and click "Macros" --> "View Macros" on the right. Or, Alt - W - M - V is the Office 2007 shortcut for you. Then, type in the name of the macro we're going to use. For this one, I recommend something like "SparkNotes". Then click the "Create" button. It'll bring up this code screen. But don't be afraid! Click "File" --> "Import File..." and navigate to the folder where this program is. Select "SparkNotes.bas". Save and close the code window and go back to your Word document. Go view your macros again. This time, select "SparkNotes" and click "Run". It will format your document for you. I think that you only have to do this once, because it will save the macro with Word. How useful! You don't have to save this word document with the rest of the HTM files, styles.css, and the other files because Word has it's own independent formatting now. It has no dependencies on other files!
If you're OK with a Word document (which you probably are), then you're fine. If you want to make a PDF out of it, I recommend that you get CutePDF Writer. It's a great, easy-to-install, free tool. You can save/move the PDF files anywhere you want, just like the Word documents. Just remember to keep the 6 downloaded files and the generated HTM files together!
That's all... it was pretty easy, wasn't it? You didn't need those instructions -- you probably think I am insulting your intelligence right now!
If you didn't find the link in that massive bulk of text above, here it is again:
Saturday, November 27, 2010
Learn to Program!
Learning how to program is a very useful tool! Since I do most of my programming in C#, I'm going to recommend it to you. (Other languages are Visual Basic & Java. Visual Basic is similar to C# in terms of what they actually do because they both use the .NET framework, but the Java syntax is much close to C# syntax)
The important things will be red so you know exactly what to look for if you don't want to read through this whole post.
The first thing we need to do is download and install C#. Follow this link to get the free Microsoft Visual C# 2010 Express. Select your language and run the file you downloaded (something like vcs_web.exe). Now, just follow the instructions on the screen. Installing it and updating your .NET framework may take a little bit of time, so go have a snack. Hang out with your friends. Play a video game.
When it's finally done installing (maybe even after restarting your computer for the .NET framework), it probably made a shortcut to C# on your desktop. If it didn't, go into your Start Menu > Programs > Microsoft Visual Studio 2010 Express. So, open C#.
It might say it's configuring for your first time. Again, you have to wait. But not that long, so go get a drink of water or something.
When that's done, click the "New Project" button right under the File menu. In the window that pops up, select Windows Forms Application, which should be the default. Name it "HelloWorld" and hit "OK". The window-like thing you see in the middle of your screen is called a "Form" which houses everything you are going to put on it.
Let's keep it simple and create a simple program that displays "Hello World" when a button is clicked. Click on your form and go to the Properties window in the bottom-right of your screen. These are values that change how your Form looks. First, lets change the "Name" property. This is how you will reference your Form in your code. Change the Name field to "frmHelloWorld" (I use the frm prefix for Forms). Now, lets change the "Text" property, which is what will be displayed on the title bar. You can put whatever you like here.
Now that we set up our form, drag a "Button" control from the Toolbox at the right side of your screen onto your Form. Again, we'll rename this. Let's name the button "btnMessage" (I use the btn prefix for Buttons). You can change the "Text" property to whatever you want. Whatever you choose, it'll be displayed on the button.
To run your program now, click the forward-pointing green arrow (or press F5 on the keyboard) to debug. Your Form will appear. You can move it around. You can resize it. You can click the button on it (but nothing happens). When you're done, close the form to get back to editing your program.
Although your Form can actually be seen and moved around, it doesn't actually do anything. Now we need to add an event, which is how your program will interact with your user. Double-click the button on your Form (when you're back in the editor). This will add a "Click" event to your form. Now you're looking at actual code. Whenever your button is clicked, it will run whatever is between the brackets after "private static void btnMessage_Click...". We will add a simple line of code:
The important things will be red so you know exactly what to look for if you don't want to read through this whole post.
The first thing we need to do is download and install C#. Follow this link to get the free Microsoft Visual C# 2010 Express. Select your language and run the file you downloaded (something like vcs_web.exe). Now, just follow the instructions on the screen. Installing it and updating your .NET framework may take a little bit of time, so go have a snack. Hang out with your friends. Play a video game.
When it's finally done installing (maybe even after restarting your computer for the .NET framework), it probably made a shortcut to C# on your desktop. If it didn't, go into your Start Menu > Programs > Microsoft Visual Studio 2010 Express. So, open C#.
It might say it's configuring for your first time. Again, you have to wait. But not that long, so go get a drink of water or something.
When that's done, click the "New Project" button right under the File menu. In the window that pops up, select Windows Forms Application, which should be the default. Name it "HelloWorld" and hit "OK". The window-like thing you see in the middle of your screen is called a "Form" which houses everything you are going to put on it.
Let's keep it simple and create a simple program that displays "Hello World" when a button is clicked. Click on your form and go to the Properties window in the bottom-right of your screen. These are values that change how your Form looks. First, lets change the "Name" property. This is how you will reference your Form in your code. Change the Name field to "frmHelloWorld" (I use the frm prefix for Forms). Now, lets change the "Text" property, which is what will be displayed on the title bar. You can put whatever you like here.
Now that we set up our form, drag a "Button" control from the Toolbox at the right side of your screen onto your Form. Again, we'll rename this. Let's name the button "btnMessage" (I use the btn prefix for Buttons). You can change the "Text" property to whatever you want. Whatever you choose, it'll be displayed on the button.
To run your program now, click the forward-pointing green arrow (or press F5 on the keyboard) to debug. Your Form will appear. You can move it around. You can resize it. You can click the button on it (but nothing happens). When you're done, close the form to get back to editing your program.
Although your Form can actually be seen and moved around, it doesn't actually do anything. Now we need to add an event, which is how your program will interact with your user. Double-click the button on your Form (when you're back in the editor). This will add a "Click" event to your form. Now you're looking at actual code. Whenever your button is clicked, it will run whatever is between the brackets after "private static void btnMessage_Click...". We will add a simple line of code:
MessageBox.Show("Hello World");
You DO need the semicolon at the end because it means that you're ending a line of code. If you didn't already guess, this creates a Message Box that pops up with the message "Hello World" when you click on the button. (I don't know why programmers are so obsessed with "Hello World"... maybe if you wanted to be a rebel, you could say "Greetings Earth")
Run the program again, and click the button. If "Hello World" shows up, congratulations, you have created your first program!
If you're still interested, you should play around with the items in the Toolbox or change the things' properties to see what they do. If not, you should still give yourself a pat on the back because you took the first step in starting to program!
If you're still interested, you should play around with the items in the Toolbox or change the things' properties to see what they do. If not, you should still give yourself a pat on the back because you took the first step in starting to program!
Subscribe to:
Posts (Atom)