tag:blogger.com,1999:blog-24666162846636177772024-03-20T19:23:35.331-07:00ProfectiumProfectium is a blog about software, reviews, and tutorials.Anonymoushttp://www.blogger.com/profile/03711539092424943076noreply@blogger.comBlogger140125tag:blogger.com,1999:blog-2466616284663617777.post-52346189170290669702018-02-06T19:35:00.001-08:002018-02-06T19:35:59.814-08:00ES6, Jest, and Webstorm: Oh My! Or, fixing 'unexpected token import'What happens when society tries to rely on arguably one of the world's worst technologies? Fragmentation.<br />
<br />
Javascript is beyond fragmented. In any given project, you may be piecing together chunks of <b>react</b>, <b>babel, gulp, webstorm, jest, jsx, webpack, less</b>... The list goes on. All of these parts rarely play together nicely, too.<br />
<br />
That led to a giant headache for me and thousands of other <b>Jest</b> users. We wrote up a file in <b>ES6 </b>syntax (to un-worsify the world's worst technology), and wrote an <b>index.test.js</b> file only to find that, oh no:<br />
<br />
<b>UNEXPECTED TOKEN 'import'</b><br />
<b><br /></b>
<span style="font-size: large;">What's Going on?</span><br />
What exactly a module is... is not exactly known. Babel isn't putting it into a format that jest is able to properly test. To fix this issue with a very barebones project structure, you need to:<br />
<br />
<b>yarn add jest-cli babel babel-core babel-plugin-transform-es2015-modules-commonjs </b><br />
<b><br /></b>
This will install everything you need to run Jest, including the babel plugin that turns these modules into a readable format.<br />
<br />
<b>package.json</b><br />
<pre style="background-color: #2b2b2b; color: #a9b7c6; font-family: 'DejaVu Sans Mono'; font-size: 9.8pt;"><span style="color: #9876aa;">"jest"</span><span style="color: #cc7832;">: </span>{
<span style="color: #9876aa;">"testEnvironment"</span><span style="color: #cc7832;">: </span><span style="color: #6a8759;">"jsdom"</span>},</pre>
<pre style="background-color: #2b2b2b; color: #a9b7c6; font-family: 'DejaVu Sans Mono'; font-size: 9.8pt;"><pre style="font-family: "DejaVu Sans Mono"; font-size: 9.8pt;"><span style="color: #9876aa;">"babel"</span><span style="color: #cc7832;">: </span>{
<span style="color: #9876aa;">"presets"</span><span style="color: #cc7832;">: </span>[
<span style="color: #6a8759;">"es2017"</span><span style="color: #6a8759;"> </span>]
}<span style="color: #cc7832;">,</span></pre>
<pre style="font-family: "DejaVu Sans Mono"; font-size: 9.8pt;"><span style="color: #9876aa;">"scripts"</span><span style="color: #cc7832;">: </span>{
<span style="color: #9876aa;">"test"</span><span style="color: #cc7832;">: </span><span style="color: #6a8759;">"jest --no-cache --verbose"</span>}</pre>
</pre>
<br />
<b>.babelrc</b><br />
<pre style="background-color: #2b2b2b; color: #a9b7c6; font-family: 'DejaVu Sans Mono'; font-size: 9.8pt;">{
<span style="color: #9876aa;">"presets"</span><span style="color: #cc7832;">: </span>[<span style="color: #6a8759;">"es2017"</span>]<span style="color: #cc7832;">,</span><span style="color: #cc7832;"> </span><span style="color: #9876aa;">"plugins"</span><span style="color: #cc7832;">: </span>[<span style="color: #6a8759;">"transform-es2015-modules-commonjs"</span>]
}</pre>
Good! You now have everything that you need to do your <b>yarn test</b> or <b>npm test</b> with ES6 modules!<br />
<br />
<span style="font-size: large;">Take it a step further: Debug in Webstorm</span><br />
Wouldn't it be absolutely awful to run a test, and have it say "cannot call function .getName of <b>undefined</b>"? Well, thankfully with this configuration we can properly debug.<br />
<br />
Webstorm comes with a debug configuration called <b>Jest</b>. These are the settings you want:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbq_fH6RzycM8J9uMNh-577hG1Zfr9QiN6GnFQxd9RCY6FY49z2DQYMkV92oMY7lf35Vvu7zLeDRe5ndTLTRm-PLjApOj4pTWCTC7IW0BWmJFCQrEpNaG2UR-aPUR8jQpCsQb0Y4P1gFI/s1600/2018-02-06-223209_1082x692_scrot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="692" data-original-width="1082" height="204" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbq_fH6RzycM8J9uMNh-577hG1Zfr9QiN6GnFQxd9RCY6FY49z2DQYMkV92oMY7lf35Vvu7zLeDRe5ndTLTRm-PLjApOj4pTWCTC7IW0BWmJFCQrEpNaG2UR-aPUR8jQpCsQb0Y4P1gFI/s320/2018-02-06-223209_1082x692_scrot.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
You're all set!</div>
<div class="separator" style="clear: both; text-align: left;">
Just set a breakpoint in your es6 code, and select the bug icon on the main webstorm toolbar.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>babel</b> will turn the <b>es6</b> into an understandable Javascript (<b>es3-5)</b>, the <b>transform-es2015-modules-commonjs</b> will turn those modules into modules that jest and browsers can understand, and the jest run configuration can talk to node over the <b>V8</b> debugging protocol to let you set breakpoints.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
It's kind of amazing what this hodgepodge of technology can accomplish!</div>
<br />shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com5tag:blogger.com,1999:blog-2466616284663617777.post-27500958037817240992017-12-10T21:01:00.002-08:002017-12-10T21:01:11.409-08:00Diesel: How To have struct fields named differently than their columnsDiesel is very good at generating code that reduces the amount of boilerplate you have to write. You can explicitly ask something like<br />
<blockquote class="tr_bq">
.filter(email.like(""))</blockquote>
and it will know how to filter based on the 'email' column, and how to populate a struct based on this.<br />
<br />
For some reason, this falls apart when you're trying to derive the <b>Insertable</b> trait.<br />
<br />
The solution is hidden away in the API documentation, which is currently <a href="https://docs.rs/diesel/1.0.0-beta1/diesel/macro.impl_Insertable.html">at this link</a>.<br />
<br />
<b>The Solution</b><br />
So, you just have to set up mappings between your struct fields and your database column in order to insert your struct as a record. Here's an example:<br />
<b> </b><br />
table:<b></b><br />
<b>Create Table User(EmailAddress text primary key not null, Name text not null)</b><br />
<br />
struct:<br />
<b> </b><br />
<b>#[derive(Queryable, Insertable)]</b><br />
<b>#[table_name="User"] </b><br />
<b>pub struct User {</b><br />
<b> </b><br />
<b> #[column_name(EmailAddress)] </b><br />
<b> pub address: String,</b><br />
<br />
<b> #[column_name(Name)] </b><br />
<b> pub name: String </b><br />
<b>}</b><br />
<br />
There aren't supposed to be quotes around the column names, as it's using the diesel-generated helper structures. As such, you have to make sure that your schema is imported for this to properly work.<b> </b>shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com3tag:blogger.com,1999:blog-2466616284663617777.post-90974376046667067622017-11-22T21:10:00.003-08:002017-11-22T21:10:12.008-08:00Rust: Setting up a Sqlite Database with diesel<b>How does the database stack in Rust work?</b><br />
For a long while, the database ecosystem in Rust was severely lacking. Thankfully, once Rust Stable 1.0.0 was released, the ecosystem has seen nothing but improvement and growth. Now, most users wind up using <b>diesel</b>, a query-builder that helps immensely with designing your data access layer.<br />
<b> </b><br />
<span style="font-size: large;">What you need before you start</span><br />
<span style="font-size: large;"> </span><b></b>You should have <b>sqlite3</b> installed on your system of choice, as well as the latest version of <b>cargo</b> and <b>rustc</b>.<br />
<br />
<span style="font-size: large;">Step 1: Set up your project</span><br />
<span style="font-size: large;"><span style="font-size: small;">As with any Rust project, simply running <b>cargo init {project}</b> will initialize a rust project with the file structure that <b>cargo</b> can understand. This will generate your <b>Cargo.toml</b> file, where we'll tell it what it needs to start using diesel with <b>sqlite3</b>.</span></span><br />
<span style="font-size: large;"><span style="font-size: small;"> </span> </span><br />
<span style="font-size: large;">Step 2: Set up your project's dependencies</span><br />
<span style="font-size: large;"><span style="font-size: small;">In order to use diesel, you'll need the diesel libraries. It's also <b>highly</b> recommended that you include something called <b>dotenv</b>. This will let you specify what your database is per-project, which you really want. Otherwise, your entire system will only find one database. Or, alternatively, you will need to manually specify a database with every session.</span></span><br />
<br />
<span style="font-size: large;"><span style="font-size: small;">Add these lines to the <b>[dependencies] </b>section in your <b>Cargo.toml</b> file:</span></span><br />
<br />
<pre style="background-color: #2b2b2b; color: #a9b7c6; font-family: 'DejaVu Sans Mono'; font-size: 9.8pt;"><span style="color: #cc7832; font-weight: bold;">diesel </span>= { <span style="color: #cc7832; font-weight: bold;">version </span>= <span style="color: #6a8759;">"0.16.0"</span>, <span style="color: #cc7832; font-weight: bold;">features </span>= [<span style="color: #6a8759;">"sqlite"</span>] }
<span style="color: #cc7832; font-weight: bold;">diesel_codegen </span>= { <span style="color: #cc7832; font-weight: bold;">version </span>= <span style="color: #6a8759;">"0.16.0"</span>, <span style="color: #cc7832; font-weight: bold;">features </span>= [<span style="color: #6a8759;">"sqlite"</span>] }
<span style="color: #cc7832; font-weight: bold;">dotenv </span>= <span style="color: #6a8759;">"0.9.0"</span></pre>
<span style="font-size: large;"> </span><br />
<br />
<span style="font-size: small;">Now, you can configure the URL of your database. Create a new file <b>in the same directory as your Cargo.toml</b> file simply called <b>.env</b>. This will be a hidden file, so you may need to enable those to see it.</span><br />
<br />
<span style="font-size: small;">Make the text of this <b>.env</b> file simply </span><br />
<br />
<b><span style="font-size: small;">DATABASE_URL={database}</span></b><br />
<br />
<span style="font-size: small;">So, if you want a sqlite3 database called <b>test.sqlite3</b>, your <b>.env</b> would look like:</span><br />
<br />
<span style="font-size: small;"><b>DATABASE_URL=test.sqlite3</b> </span><b><span style="font-size: small;"> </span></b><br />
<span style="font-size: small;"> </span><br />
<span style="font-size: large;">Step 3: Initialize your database</span><br />
<span style="font-size: large;"> <span style="font-size: small;">Much of the work you'll be doing is done through a command line tool, called<b> </b>simply <b>diesel</b>. First, you need to install this utility globally, with</span></span><br />
<span style="font-size: large;"><span style="font-size: small;"><b>cargo install diesel --no-default-features --features sqlite</b></span></span><br />
<br />
<span style="font-size: large;"><span style="font-size: small;">On Linux, this will place the executable in your <b>$HOME/.cargo/bin/</b> folder. You may need to add this folder to your <b>$PATH</b> in order to use diesel<b>.</b></span></span><br />
<br />
<span style="font-size: large;"><span style="font-size: small;">To create your database, go to the directory where your <b>Cargo.toml</b> is located and run <b>diesel setup</b>. This will initialize a blank sqlite3 database.</span></span><br />
<span style="font-size: large;"><span style="font-size: small;"><b> </b> </span></span><br />
<span style="font-size: large;">Step 4: Start designing your schema </span><br />
<span style="font-size: large;"><span style="font-size: small;">In order to set up an initial schema, and begin using your database, you have to initalize a <b>migration</b>. To do this, run <b>diesel migration generate {migration-name}</b>.</span></span><br />
<br />
<span style="font-size: large;"><span style="font-size: small;">For this first migration, I tend to just do</span></span><br />
<br />
<span style="font-size: large;"><span style="font-size: small;"><b>diesel migration generate initialize</b></span></span><br />
<br />
<span style="font-size: large;"><span style="font-size: small;">This will generate a new directory, with today's date and time, that contains an <b>up.sql</b> and <b>down.sql</b>. As the official guide states, <b>down.sql</b> simply should undo any schema changes you make in <b>up.sql</b></span></span><br />
<br />
<span style="font-size: large;"><span style="font-size: small;"><b><span style="font-size: large;">You're all set!</span></b></span></span><br />
<span style="font-size: large;"><span style="font-size: small;"><span style="font-size: large;"><span style="font-size: small;">I wrote this guide because I ran into a few pitfalls following the official guide. However, the official guide is absolutely fantastic, and describes everything that I summarized here in a clearer, more complete way. I recommend that you go and check it out at</span></span></span></span><br />
<br />
<a href="http://diesel.rs/guides/getting-started/"><span style="font-size: large;"><span style="font-size: small;"><span style="font-size: large;"><span style="font-size: small;">http://diesel.rs/guides/getting-started/ </span></span><b><span style="font-size: large;"> </span> </b> </span> </span></a>shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com5tag:blogger.com,1999:blog-2466616284663617777.post-14347035447864499212017-11-12T16:38:00.000-08:002017-11-12T16:38:10.400-08:00Rust: How to use the latest version of a Cargo Crate<span style="font-size: large;">Why Cargo is so brilliant</span><br />
Cargo is a fantastic tool. From the get-go, it's gotten a lot of things right that package managers like <b>npm</b> and <b>nuget</b> still stumble over. The competitors to these tools, <b>yarn</b> and <b>paket</b> address the issues that, thankfully, Cargo has already solved.<br />
<br />
You know what npm got right, though? It's dead simple to hook a package up. Do you want to use <b>react</b>? You can just type <i>npm install --save react</i>, and it will find the latest version of React, and add it to the <b>packages.json</b> file. Cargo, too, can be <b>abused</b> to have this functionality.<br />
<br />
<span style="font-size: large;">Warning: You really shouldn't do this...</span><br />
By explicitly listing versions in your <b>Cargo.toml</b> file, you know for a fact that a future release of the package won't break your project. Furthermore, you know for a fact that the different dependencies that you're relying on play nicely together.<br />
<br />
One of the goals of dev-ops is minimizing risk. Having an explicit definition of the packages that could break your project is one of the most important ways to do this.<br />
<br />
<span style="font-size: large;">With that said...</span><br />
<b>A quick spiel on Semver</b><br />
Semver, the syntax for identifying the version of the package you want to use, is a widely upheld standard. You can read the full <a href="https://docs.npmjs.com/misc/semver">semver guidelines</a> to grok exactly what's happening when you type a version in. Cargo use's a Rust <b>semver</b> library <a href="https://github.com/steveklabnik/semver">(which can be found here)</a> to parse its dependencies version section.<br />
<br />
By <b>abusing</b> the Greater-Than functionality, we can trick Cargo to installing the latest version of a package.<br />
<br />
<span style="font-size: large;">Example: Installing the latest Serde</span><br />
This line in your <b>Cargo.toml </b>file:<br />
<br />
<blockquote class="tr_bq">
serde = ">0.0.0"</blockquote>
<br />
is all you need for Cargo to install the latest version of Serde. This can be used for any package that you don't care about the version for. Be careful with this trick. There's a reason Cargo doesn't technically support this type of workflow outside of this hack.shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com2tag:blogger.com,1999:blog-2466616284663617777.post-56872047193809677992017-11-12T16:14:00.003-08:002017-11-12T16:14:34.499-08:00How To: Remove part of i3's bar with i3status<div class="tr_bq">
<b>The Problem</b></div>
i3bar is perfectly simple. It's not this gaudy, in-your-face information supernova that Windows has been iterating on for the last ~20 years. It tells you just what you need to know: space left, internet speed, CPU load, and the time. But... what if you don't care about your internet speed? Or the time?<br />
<br />
Thankfully, removing it is dead simple.<br />
<br />
<b>i3status.conf</b><br />
If you're using the default i3status for your i3bar, the fix is simple. A configuration file in your <b>home</b> directory overrides the default in <b>/etc/i3status.conf</b>. (placing one in <b>$HOME/.config/i3status/config</b> will override the one in your home directory).<br />
<br />
<span style="font-size: large;">Setting the Overrides </span><br />
So, you have two options. You can make a NEW file in either of those locations, copying the existing data over. Or, you can edit <b>/etc/i3status.conf</b> directly as root (not recommended).<br />
<br />
Using the documentation in <b>man i3status</b> and your existing file (<b>/etc/i3status.conf</b>), you should be able to find the commands you want. Then, make sure that <b>only the commands you care about are in the order variable</b>.<br />
<br />
For instance, by default, my order looked like this:<br />
<br />
<blockquote>
order += "disk /"<br />order += "ethernet _first_"<br />order += "load"<br />order += "tztime local"</blockquote>
Since I don't care about my ethernet, I struck it. Resulting in this:<br />
<blockquote>
<br />order += "disk /"<br />order += "load"<br />order += "tztime local"</blockquote>
shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0tag:blogger.com,1999:blog-2466616284663617777.post-15345711437055166862017-11-12T16:00:00.001-08:002017-11-12T16:00:19.696-08:00Rust: Returning JSON with Rocket<b>Preamble</b><br />
JSON is one of the technologies that, while very simple at its core, has had a profound impact on the technical landscape. Most modern public API's rely on JSON to transport information between application layers. It's become essential from everything ranging from Web API's, compiler technologies, and even data storage.<br />
<br />
With that said, it's <i>essential</i><b style="font-style: italic;"> </b>for an up-and-coming web tech stack like Rust and Rocket to support it. And support it they do.<br />
<br />
<b>Step 1: Install Dependencies</b><br />
For some reason, the official Rocket documentation hides the fact that you need dependencies outside of <u>rocket_codegen</u> and <u>rocket</u> in order to return JSON.<br />
<br />
You need to have all of the following lines in your <b>Cargo.toml </b>file:<br />
<br />
<blockquote class="tr_bq">
rocket = "0.3.3"<br />rocket_codegen = "0.3.3"<br />rocket_contrib = "0.3.3"</blockquote>
Obviously, these versions will change over time. Without these dependencies, you may find yourself with errors such as:<br />
<br />
"Cannot find macro json!", "Value cannot be found", etc. when following Rocket's documentation.<br />
<br />
<b>Step 2: Start returning JSON</b><br />
Now, the easy part. I'm going to post the single most rudimentary example of a JSON return ever. In real web projects, you'll want to use <b>serde</b> and <b>serde_derive</b> to turn your data-transfer objects / models into a consistent JSON format. For now, we'll use the <b>json!</b> macro and <b>Json</b> struct to hard-return a value on the root route:<br />
<br />
<pre style="background-color: #2b2b2b; color: #a9b7c6; font-family: 'DejaVu Sans Mono'; font-size: 9.8pt;"><span style="color: #bbb529;">#[get("/")]</span><span style="color: #cc7832; font-weight: bold;">fn </span><span style="color: #ffc66d;">index</span>() -> Json<Value> {
Json(<span style="color: #4eade5;">json!</span>({<span style="color: #6a8759;">"value"</span>: <span style="color: #6897bb;">5</span>}))
}
<span style="color: #cc7832; font-weight: bold;">fn </span><span style="color: #ffc66d;">main</span>() {
rocket::<span style="color: #ffc66d;">ignite</span>().<span style="color: #ffc66d;">mount</span>(<span style="color: #6a8759;">"/"</span><span style="color: #cc7832;">, </span><span style="color: #4eade5;">routes!</span>[index]).<span style="color: #ffc66d;">launch</span>()<span style="color: #cc7832;">;</span>}</pre>
shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0tag:blogger.com,1999:blog-2466616284663617777.post-14568787966611953372017-10-29T20:08:00.006-07:002017-10-29T20:08:55.377-07:00Rust: How To Fix "no default toolchain configured" and "the following required arguments were not provided: toolchain"<b>The Problem</b><br />
What's happening here, is that you've installed rust utilities via rustup: cargo, rustc, etc. The problem is, these utilities cannot find the default rust 'toolchain', as it has not been configured yet.<br />
<b> </b><br />
<b>The Fix</b><br />
This is a very simple fix. The following command:<br />
<b> </b><br />
<b> </b><span style="background-color: #f3f3f3;">rustup default stable</span><br />
<span style="background-color: #f3f3f3;"><br /></span>
<span style="background-color: #f3f3f3;"><span style="background-color: white;"><span>In this case, you want to change <i>stable</i> to be whatever release channel you're on. For nightly rust, this would switch to </span></span></span><br />
<br />
<span style="background-color: #f3f3f3;"><span style="background-color: white;"><span> </span></span></span><span style="background-color: #f3f3f3;"><span style="background-color: white;"><span><span style="background-color: #f3f3f3;">rustup default nightly</span></span></span></span><br />
<br />
<br />shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com2tag:blogger.com,1999:blog-2466616284663617777.post-69372234608316962192017-10-07T09:12:00.002-07:002017-10-07T09:12:27.867-07:00[Fix]: No Audio in Linux / Videos Don't Play<b>The Problem</b><br />
There exists an especially frustrating problem on some linux distributions where audio will simply not play. The lack of audio playing can mean that you're also not able to watch videos, even completely without audio! Most recently, I installed Ubuntu 17.04 to find that I was unable to listen to music or even watch Youtube videos with subtitles. That's untenable, and a complete deal-breaker for most people (for obvious reason).<br />
<br />
<b>The Explanation</b><br />
So, what's really happening here is that your user isn't in the <span style="background-color: #f3f3f3;">audio</span><span style="background-color: white;"> group. Because they're not in the audio group, videos which contain audio (i.e all video file formats) are simply not allowed to play! Why users aren't de facto members of the audio group, especially on Linux, is completely lost on me. But, it's enough information to fix the problem thankfully. </span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;"><b>(Optional) A Quick Rundown on Groups</b></span><br />
<span style="background-color: white;">For the uninitiated; Linux has two essential components of its security system: <b>groups</b> and <b>users</b>. <b>Users</b> are added to <b>groups</b> to give them certain <b>privileges</b>. So, since your user is NOT a member of the <b>audio group</b>, you cannot play audio.</span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;"><b>The Fix</b></span><br />
<span style="background-color: white;">The fix for this couldn't be easier. You need to run the following command:</span><br />
<span style="background-color: white;"><br /></span>
<pre style="background-color: #eff0f1; border: 0px; color: #111111; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;">sudo usermod -a -G groupName userName</code></pre>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
<span style="font-family: inherit;"><span style="background-color: white;">Then, we're already half way done! You are now a member of the audio group. </span></span></div>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
<b>To apply this fix, you *need* to shut down and power back up</b></div>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
For me, nothing actually applied this change other than a full shutdown / restart cycle. Even <b>rebooting</b> didn't actually do it for me, strangely enough. That goes against all of my intuition as an avid computer user and programmer. I can't explain it.</div>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
Once you've reboot, you should then be able to run the following command:</div>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
<b>alsamixer</b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSd-6T_1WaX-NTB1hn55Iaz4RgrJxaOPtPe6XbP3bGwgZ_OysAE39zB4lfTm0KW6g0naF_e1B0C4xD4b5552r-XwSRJOS02LAj8_OTfElhjg0iBylpAkW-yC-CP-ZQO1dps6Aet106rtg/s1600/Screenshot_20171007_120607.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="555" data-original-width="1528" height="116" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSd-6T_1WaX-NTB1hn55Iaz4RgrJxaOPtPe6XbP3bGwgZ_OysAE39zB4lfTm0KW6g0naF_e1B0C4xD4b5552r-XwSRJOS02LAj8_OTfElhjg0iBylpAkW-yC-CP-ZQO1dps6Aet106rtg/s320/Screenshot_20171007_120607.png" width="320" /></a></div>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
Then, hover over the columns which read 'MM' and hit 'm' to unmute them. Raise their volume to <b>100%</b>. Your desktop environment will control the actual volume you here, but you don't want the underlying sound system to artificially lower your volume.</div>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
<b>The Last Step</b></div>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
The final thing you have to do is to run the following command:</div>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
<b>pavucontrol</b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGduNue73fObCaajEi4DCoUVBsvHkXpeOUGrm3ARqW1PYk_kUL_moUTQhyphenhyphenHJQXp6rOrsYyjzh26cC5AEVouhq9PRqNSwhCFhQzytDHSNXSXq90XY6DnTL_nTanlduuA8Q3iTDlf7vqv_w/s1600/Screenshot_20171007_120923.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="432" data-original-width="1534" height="90" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGduNue73fObCaajEi4DCoUVBsvHkXpeOUGrm3ARqW1PYk_kUL_moUTQhyphenhyphenHJQXp6rOrsYyjzh26cC5AEVouhq9PRqNSwhCFhQzytDHSNXSXq90XY6DnTL_nTanlduuA8Q3iTDlf7vqv_w/s320/Screenshot_20171007_120923.png" width="320" /></a></div>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
Then, from here, set up whatever audio device you'll be using. In my case, with headphones plugged into the audio jack it wound up being 'Line Out'. Under the <b>configuration</b> tab, I needed to select <b>Audio Stereo Duplex</b> for it to work. I'm also unsure why the <b>Audio Stereo Duplex</b> configuration works, but I know it does.</div>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
<b>You're Done!</b></div>
<div style="border: 0px; color: #111111; font-stretch: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;">
After all of this, you should have working audio. As you can tell, the rumor that Linux audio can be a headache is proven to be true. Videos should already be working. If you are still having trouble with it, leave a comment below and I'll do my best to help out.</div>
shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0tag:blogger.com,1999:blog-2466616284663617777.post-13257837006971173132017-03-07T06:35:00.004-08:002017-03-07T10:58:18.932-08:00[How To]: Not commit when a string is present in git<span style="font-size: large;">The Use Case</span><br />
Howdy! So, I ran into an interesting problem this week. In order to test something, I had to make a change to code that should NEVER be commit... then, I commit it. D'oh!<br />
<br />
If you want to protect yourself from something similar, or prevent data leakage, read on.<br />
<br />
<span style="font-size: large;">The Setup</span><br />
When you clone or initialize a git project, git creates a "./.git" folder for you. This is where it tracks information about the repository, and stores some git metadata and logs.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGXkImImdXV3tqp0oRdCouvJ0h1fLsLf3DWo_kKCcQ4Y2dNkbWLXAdiyt23a790cPU6ZCrkL7-rpLmW5zhowHOqnqa0B438t8Oez9WleREeJdeI3hpuXNXMPMHwg88JjBOcLwNs9RzK2k/s1600/git_folder.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="248" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGXkImImdXV3tqp0oRdCouvJ0h1fLsLf3DWo_kKCcQ4Y2dNkbWLXAdiyt23a790cPU6ZCrkL7-rpLmW5zhowHOqnqa0B438t8Oez9WleREeJdeI3hpuXNXMPMHwg88JjBOcLwNs9RzK2k/s640/git_folder.png" width="640" /></a></div>
<br />
Another thing this folder contains are "hooks", which are run at some point during the git workflow. For instance, if we had a "pre-push" hook, it would run before the push goes up to the remote.<br />
<br />
So, what can we do with these hooks? Anything that BASH lets us. The most common use case for hooks is stopping a commit if something isn't right with the project, which is what we'll be doing in our case. However, you could do things like:<br />
<br />
<br />
<ul>
<li>Print out the total number of lines changed</li>
<li>Check for a string and just give warnings (i,e mispellings, swear words)</li>
<li>Queue a local or remote backup</li>
<li>Package the project</li>
</ul>
<div>
Really, anything.</div>
<div>
<br /></div>
<div>
<span style="font-size: large;">Protecting Ourselves</span></div>
<div>
We would like to not commit if a string is present in the file. Imagine if we wanted to search for //[DANGER]. The presence of [DANGER] in any tracked file would stop the commit, so you could remember to go back and change the reason for it being there.</div>
<div>
<br /></div>
<div>
To do this, open the <b>pre-commit.sample</b> file and save it as <b>pre-commit</b> (with no extension). If there isn't a sample file, simply make the <b>pre-commit</b> file.</div>
<div>
<br /></div>
<div>
Before we write any code, let's look at what we want:</div>
<div>
<br /></div>
<div>
<ul>
<li>If a string is present ANYWHERE in the directory, fail</li>
</ul>
<div>
Alternatively, in large code bases, we want:</div>
</div>
<div>
<ul>
<li>Search the diff for newly added instances of the string</li>
</ul>
<div>
Since searching through every file is going to take too long to do on every commit.</div>
</div>
<div>
<br /></div>
<div>
<span style="font-size: large;">The Steps</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<b>Make the File</b></div>
<div>
You should now have a file called ./.git/hooks/pre-commit. You make need to mark the pre-commit file as executable with <i>chmod + x pre-commit</i>.</div>
<div>
<br /></div>
<div>
<b>Add this code to the file</b></div>
<div>
<br /></div>
<br />
<div>
<span style="background-color: #999999;">printf "[Check]: Searching for commit mollyguard: '%s'..." "$breakingString"</span></div>
<div>
<div>
<span style="background-color: #999999;">sleep 1</span></div>
<div>
<span style="background-color: #999999;"># VVVVVVV YOUR REGEX RIGHT THERE</span></div>
<div>
<span style="background-color: #999999;">if [ $(git diff --word-diff --cached --diff-filter=ACUM -U0 | grep -E "+*\[DANGER\]" | wc -l) -gt 0 ]</span></div>
<div>
<span style="background-color: #999999;">then </span></div>
<div>
<span style="background-color: #999999;"><span class="Apple-tab-span" style="white-space: pre;"> </span>printf "\n"</span></div>
<div>
<span style="background-color: #999999;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cat <<\EOF</span></div>
<div>
<span style="background-color: #999999;">Error: Trying to commit a tree that contains uncommitable changes </span></div>
<div>
<span style="background-color: #999999;"><br /></span></div>
<div>
<span style="background-color: #999999;">Search the projects for $breakingString and figure out why the comment is there</span></div>
<div>
<span style="background-color: #999999;">EOF</span></div>
<div>
<span style="background-color: #999999;"><span class="Apple-tab-span" style="white-space: pre;"> </span>exit 1;</span></div>
<div>
<span style="background-color: #999999;">fi</span></div>
<div>
<span style="background-color: #999999;"><br /></span></div>
<div>
<span style="background-color: #999999;">printf "Good!\n"</span></div>
</div>
<div>
<span style="background-color: #eeeeee;"><br /></span></div>
<div>
<br /></div>
<div>
What this code is doing: </div>
<div>
<ul>
<li>Look at the last diff</li>
<li>Search the diff for "+{string}" (because + means it was ADDED, not removed in the last commit)</li>
<li>Count the lines</li>
</ul>
<div>
If the lines are greater than 0, and instance was found, so we shouldn't commit this branch.<br />
<br />
Of course, this is searching just the latest commit, because searching a large software project is going to take a while. If you're working on a smaller project (or on a very fast machine), you can replace the if statement with simply<br />
<br />
if [ $(grep -R "\[DANGER\]"../../ | wc- l) > 0 ]</div>
</div>
<div>
<br /></div>
<div>
<br /></div>
shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0tag:blogger.com,1999:blog-2466616284663617777.post-79737253045246888672017-03-05T15:09:00.001-08:002017-03-05T15:09:02.204-08:00.NET - "%5C" Showing Up on URLsAre you a developer, who is accepting a file or some string of text and putting it into a cloud? Are you, also, per chance, retrieving its URL, and notcing this pesky "%5C popping up in our URLs? Well, I know recently I was. It was a pretty strange, out of the blue error with an interesting cause. Here are some details for you:<div>
<br /></div>
<div>
<span style="font-size: large;">What Causes This?</span></div>
<div>
The actual causes of this problem are numerous. The bottom line is, '%5C' in a URL means that the backslash '\' got encoded in the URL. Somewhere along the way, either unintentionally or on purpose, a string containing one wound up in the encoding step.</div>
<div>
<br /></div>
<div>
The culprit for many users is using .NET's <b>Path</b> utility for trying to parse URLs. Here's an example:</div>
<div>
<br /></div>
<div>
Let's look at expectation vs Reality</div>
<div>
<br /></div>
<div>
<b>Code: </b>Path.GetDirectoryName("I/want/to/upload/to/this/place")</div>
<div>
<b>Expected: </b>"I/want/to/upload/to/this/"</div>
<div>
<b>Actual: "</b>I\want\to\upload\to\this"</div>
<div>
<br /></div>
<div>
This is because Path uses a field called <b>Path.DirectorySeperatorChar</b>, which on Windows is '\'... A bit backwards that Path can READ forward slashes as directory names, yet only output backslashes in the return value.</div>
<div>
<br /></div>
<div>
<span style="font-size: large;">How Do I Fix This?</span></div>
<div>
There are plenty of good solutions to fix this. However, with so many different causes to the problem, it's hard to say exactly.</div>
<div>
<br /></div>
<div>
<b>To Fix it in a simple string</b></div>
<div>
It's possible that all you need to do is Path.GetDirectoryName(<i>your_string</i>).Replace(Path.DirectorySeperatorChar, Path.AltDirectorySeperatorChar), and you're good to go.</div>
<div>
<br /></div>
<div>
Hopefully this shed some light on what the problem may be in your case. Hopefully, moving forward, Microsoft is not afraid to add a .NET feature like PathFlags or something so that this doesn't crop up as much as it currently does.</div>
shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0tag:blogger.com,1999:blog-2466616284663617777.post-34325127302330123262016-11-12T08:38:00.001-08:002016-11-12T08:38:06.526-08:00Installing Racer<span style="font-size: large;">Prologue </span><br />
Let's talk about Rust for a moment, folks. If C is akin to the Bourgeoise, then Rust is kind of like Robin Hood. It takes ideas from C, and implements them in safe and better ways. In my opinion, it's almost foolish to start a new C project today, with all the extensibility of the High-level languages today and the safety and relative ease-of-use of languages like Rust and Go. One front where Rust is lacking, however, is IDE integration. At the time of writing, there is an <a href="https://github.com/rust-lang/rfcs/pull/1317">Active RFC</a> for features in the Rust compiler that will make it easier for IDE plugin authors to add Rust integration. Thankfully, in the interim, there's the <a href="https://github.com/phildawes/racer">Racer</a> project which does something similar.<br />
<br />
<span style="font-size: large;">What does Racer do?</span><br />
Racer provides automcompletion for Rust code. It does this by sending incomplete symbols in your Rust source file to racer, searching the standard library for a candidate, and providing the name and type information as you go.<br />
<br />
So, in order for Racer to work, we need the Rust source code.<br />
<br />
<span style="font-size: large;">How do I install Racer?</span><br />
The easiest way is with <a href="http://doc.crates.io/">Cargo</a>, Rust's package manager. The following commands should get you up and running. You need to have <b>cargo, rustc, </b>and <b>git</b> installed for these to work.<br />
<br />
<b>**NOTE FOR ZSH USERS**</b><br />
In the following commands, simply replace .bashrc with .zshrc. Everything else should stay the same.<br />
<br />
<b>Install racer from crates.io</b><br />
cargo install racer<br />
<br />
<b>Add the cargo directory to your $PATH variable</b><br />
<b></b><br />
echo "export PATH=\"\$PATH:$HOME/.cargo/bin\"" >> .bashrc<br />
<div>
<br /></div>
<div>
<b>Download the rust source code </b></div>
<div>
<div>
git clone --depth 1 https://github.com/rust-lang/rust.git $HOME/.rustsrc</div>
<div style="font-weight: bold;">
<br /></div>
</div>
<div>
<b>Set your RUST_SRC_PATH environment variable to look for your rust src checkout</b></div>
<div>
<div>
echo "export RUST_SRC_PATH=\"$HOME/.rustsrc/src\"" >> .bashrc</div>
</div>
<div>
<br /></div>
shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0tag:blogger.com,1999:blog-2466616284663617777.post-45888887338609663892016-07-31T16:06:00.004-07:002016-07-31T16:06:57.548-07:00Setting up Emacs for HaskellHaskell is a bit of a quirky language. It has been around for a very long time, yet hasn't nearly received the professional love that languages like Java, C#, or even F# have gotten. Professional IDE's for the language doesn't exist; good IDE plugins for the languages barely do. So, it has become standard within Haskell community that either Emacs or Vim be used. In this article we'll be examining how to start working with Emacs and Haskell effectively.<br />
<br />
<span style="font-size: x-large;">First Things First</span><br />
<span style="font-size: large;">Prerequisites </span><br />
We have to get Emacs and Haskell installed, if they're not already. If you already have <b>emacs</b> and <b>ghc</b> installed, then you can safely skip this step. Otherwise, you need to install the following packages:<br />
<br />
<b>emacs</b> (Version 24 or greater)<br />
<b>ghc</b> (Version 7.5 or greater)<br />
<br />
<b>Ubuntu</b><br />
<blockquote class="tr_bq">
sudo apt-get install ghc emacs</blockquote>
<b>Fedora</b><br />
<blockquote class="tr_bq">
sudo dnf install ghc emacs</blockquote>
<b>Arch</b><br />
<blockquote class="tr_bq">
sudo pacman -S ghc emacs</blockquote>
<span style="font-size: large;">Melpa</span><br />
The next steps are much easier to perform if you already have Emacs set to look at the <a href="https://melpa.org/#/">MELPA</a> repositories. If you'd like instructions on how to set up MELPA, I've written a guide about it <a href="http://profectium.blogspot.com/2013/07/how-to-install-melpa-in-gnu-emacs.html">Here</a>.<br />
<br />
<span style="font-size: large;">Emacs Packages</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjipWt5yXdd6N2CiLLKeiwx1Oued7ERWJaCgH6_vUhMmKemDbcmS2Ak4uFS4zD8EAzpFk1-xESx_DHdV-0JN6GHkxLaVCYUiTmragcIpave6eKOoRGVeaZMkYTkT4WCXPpsES2HSE1A28w/s1600/Screenshot+from+2016-07-31+18-08-17.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="34" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjipWt5yXdd6N2CiLLKeiwx1Oued7ERWJaCgH6_vUhMmKemDbcmS2Ak4uFS4zD8EAzpFk1-xESx_DHdV-0JN6GHkxLaVCYUiTmragcIpave6eKOoRGVeaZMkYTkT4WCXPpsES2HSE1A28w/s640/Screenshot+from+2016-07-31+18-08-17.png" width="640" /></a></div>
<span style="font-size: large;"><br /></span>
The Emacs package which controls Haskell can be found in the "haskell-mode" package. The two other helpful packages that are also in the MELPA repositories are <b>haskell-emacs</b>, which lets you make Emacs extensions in Haskell, and <b>haskell-snippets</b>, which will present a certain type of code completion into Emacs for haskell by the use of <b>yasnippet</b>.<br />
<br />
To install the necessary packages, do:<br />
<br />
<blockquote class="tr_bq">
M-x package-install [ret] haskell-mode [ret]<br />M-x package-install [ret] yasnippet<br />M-x package-install [ret] haskell-snippets [ret]</blockquote>
haskell-snippets and yasnippet are completely optional, but they will make your experience far better.<br />
<br />
<span style="font-size: x-large;">Configuration</span><br />
A bit of a frustrating trend with haskell-mode is that it's making more and more features opt-in, in order to reduce the memory overhead of using haskell mode. What this means for the average user is inconvenience in configuring haskell-mode.<br />
<br />
In your ~/.emacs file (or wherever you prefer to extend Emacs from), put in the following lines:<br />
<br />
<blockquote class="tr_bq">
(add-hook 'haskell-mode-hook 'haskell-indentation-mode)<br />(add-hook 'haskell-mode'hook 'interactive-haskell-mode)<br />(add-hook 'haskell-mode-hook 'yas-minor-mode)</blockquote>
Or, if you plan to use all of these features:<br />
<blockquote class="tr_bq">
(add-hook 'haskell-mode-hook (lambda () (interactive) (haskell-indentation-mode) (interactive-haskell-mode) (yas-minor-mode)))</blockquote>
This makes it so that when you enter haskell-mode (which you do when you open any .hs file), the haskell indentation mode, interactive haskell mode, and the yas minor mode are all enabled.<br />
<br />
<b>haskell-mode</b> is what provides syntax highlighting for haskell, amongst a few other features.<br />
<b>haskell-indentation-mode</b> is what allows you to automatically indent haskell source with text<br />
<b>interactive-haskell-mode</b> is what lets you run Haskell code right in Emacs to check for errors, make tests, etc.<br />
<b>yas-minor-mode</b> lets you insert snippets of Haskell code into the file you're in, which makes working with Haskell <u>far</u> easier, due to the immense amount of syntax sugar that Haskell makes use of.<br />
<br />
<span style="font-size: x-large;">Using Emacs for Haskell</span><br />
Let's make sure that we have everything working. In Emacs, open up a file called <b>"test.hs" </b>and add the following lines:<br />
<blockquote class="tr_bq">
<br />myFunction :: (a -> b) -> a -> b<br />myFunction f a = f a<br />myFunction2 :: Int -> Int<br />myFunction2 a = myFunction (+ 2) a</blockquote>
Now, do <b>C-c C-l </b>(hitting c and l while holding control). If everything is installed correctly, it should show you a lambda and a greater-than symbol. This is a <b>ghci prompt</b>, which will evaluate your current file and let you interact with the functions and data types you've defined in this file or any that are imported into it.<br />
<br />
Just to see what would happen when there's an error, change the first line to this:<br />
<blockquote class="tr_bq">
myFunction :: (a -> b) -> a -> c </blockquote>
And try to run <b>C-c C-l</b> again. Notice that it leaves a white exclamation point to the right of the problem in the source code, and underlines exactly where the error is in red.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3KSACSCddlpMZdl-m16yUBEhCwXcwhzwC7G9J9WIuENnOhElk8-GZ0xG1fVgv6M79_L2RGNkMC51asJ0nnzlAPn2L_bxeTiTM8_HJ-2nll0jbKToVl_8_B1frKFc_mhyphenhypheni62uxy60q5dg/s1600/Screenshot+from+2016-07-31+18-45-29.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3KSACSCddlpMZdl-m16yUBEhCwXcwhzwC7G9J9WIuENnOhElk8-GZ0xG1fVgv6M79_L2RGNkMC51asJ0nnzlAPn2L_bxeTiTM8_HJ-2nll0jbKToVl_8_B1frKFc_mhyphenhypheni62uxy60q5dg/s1600/Screenshot+from+2016-07-31+18-45-29.png" /></a></div>
as well as showing you the error in the bottom part of the window<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPqtYtDZuaLXo1GwPg4rJBXETOpq49z3hix3lXU8XwOfo59cDTfmVwefrh-6Xm4I9ZueaRLMKSxrwoF2_SFsDuCxO6qX-QNZZpDK1weg2v7790c98RJcq4RFPW6cHYVXyUQABU33eQfAQ/s1600/Screenshot+from+2016-07-31+18-46-02.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="129" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPqtYtDZuaLXo1GwPg4rJBXETOpq49z3hix3lXU8XwOfo59cDTfmVwefrh-6Xm4I9ZueaRLMKSxrwoF2_SFsDuCxO6qX-QNZZpDK1weg2v7790c98RJcq4RFPW6cHYVXyUQABU33eQfAQ/s320/Screenshot+from+2016-07-31+18-46-02.png" width="320" /></a></div>
This is how your Emacs workflow will go.<br />
<br />
<span style="font-size: x-large;">Further Reading</span><br />
There is plenty more to do with Emacs and Haskell, but this will get you started. You can activate true code completion, get linting messages, etc. through the use of an extra extension called <b>ghc-mod. </b>However, ghc-mod is currently broken in cabal... Whenever the version in the cabal repositories is fixed, I will add information about ghc-mod to the guide.<br />
<br />
If your distribution has ghc-mod, it's would betroth you to read about installing it in Emacs <a href="http://www.mew.org/~kazu/proj/ghc-mod/en/preparation.html">here</a>.shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com1tag:blogger.com,1999:blog-2466616284663617777.post-80244820995604691812016-07-31T14:49:00.000-07:002016-07-31T14:49:04.497-07:00How To: Change your desktop background in BSPWMHowdy! So, you've installed <b>bspwm</b> and you noticed that it's not as fancy as what you're used to. No fancy settings for changing your desktop environment, no 'settings', nothing. We're left to our own devices.<br />
<br />
Thankfully, Linux is full of devices for us to use. One of which, <b>feh</b>, will let us change what wallpaper is used by bspwm.<br />
<br />
<span style="font-size: large;">Install feh</span><br />
<span style="font-size: large;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis8A3G2_uS6VF73NxmPhW2OfPNzhRzTLcGlR9f78uSuPNB4oRcZ_wl67dx7xl49_BW7Hwflqn8opvj-MBspSnc6a5FGY9kqCYsurQyh_I7iJGtxzvSaR304uGoOKgJQu204YrIEUjIuXs/s1600/Screenshot+from+2016-07-31+17-29-15.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="128" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis8A3G2_uS6VF73NxmPhW2OfPNzhRzTLcGlR9f78uSuPNB4oRcZ_wl67dx7xl49_BW7Hwflqn8opvj-MBspSnc6a5FGY9kqCYsurQyh_I7iJGtxzvSaR304uGoOKgJQu204YrIEUjIuXs/s320/Screenshot+from+2016-07-31+17-29-15.png" width="320" /></a></div>
The first step is to install feh. Feh is small program used to view images without using a ton of resources. Luckily, feh has been adapted to work as a background setter.<br />
<br /><b>Ubuntu</b><div>
sudo apt-get install feh<br /><b>Fedora</b><br /> sudo dnf install feh<br /><b>Arch</b><br /> sudo pacman -S feh</div>
<div>
<br /></div>
<div>
<span style="font-size: large;">Use Feh</span></div>
<div>
In order to simply use feh as a photo viewer, you can call "<b>feh picture.jpg</b>", where "<b>picture.jpg</b>" is any image file that ImageMagick can open. In order to use feh to create a desktop background, call this command:</div>
<div>
<br /></div>
<blockquote class="tr_bq">
<b>feh --bg-center picture.jpg</b></blockquote>
Once again, where picture.jpg is just about any image file.<br />
<br />
And there you have it! A desktop background... for now. The thing is, after this session, the background will revert to normal. In case you want this to remain your desktop background, we need to edit out <b>bspwmrc file.</b><br />
<br />
<span style="font-size: large;">Configure feh</span><br />
In your bspwmrc file, which is usually located in <b>~/.config/bspwm/bspwmrc</b>, we need to call feh on startup. On mostly any line, preferably towards the end of the file, add this line:<br />
<blockquote class="tr_bq">
<b>feh --bg-center ~/Pictures/background.jpg</b></blockquote>
where the filepath is the path to the file you plan to use for your background. Now, when you start bspwm, it should set up the background for you automatically.<br />
<br />
<b>Further Configuration</b><br />
<b><br /></b>
Now, there are further ways that you can configure feh. Right now it's set to center the image in the middle of the desktop, surrounding it with a black border. If you'd prefer to have it stretch, or tile, you can use these flags in place of --bg-center:<br />
<br />
<b>--bg-fill </b>: This will preserve the aspect ratio of the file, and optionally cut off whatever part of the image doesn't scale.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUZZOxELH-h8wQV63c9jd-fsTF3WRLSspQfdELcrKjqDXpth99lUaRzae8OvqnLXI_m9rXKeK9q99Kcupg4LufLv6VPJfHDbVsmh091n-edvkLGWuH_0v1LQlK1THocsKWpoZVjPiXaMs/s1600/Screenshot+from+2016-07-31+17-39-39.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUZZOxELH-h8wQV63c9jd-fsTF3WRLSspQfdELcrKjqDXpth99lUaRzae8OvqnLXI_m9rXKeK9q99Kcupg4LufLv6VPJfHDbVsmh091n-edvkLGWuH_0v1LQlK1THocsKWpoZVjPiXaMs/s320/Screenshot+from+2016-07-31+17-39-39.png" width="320" /></a></div>
<br />
<b>--bg-max </b>: this will scale the image to its maximum size, and put black borders on one side.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4s82Oqp_um_rtDIS503dCXDVj_g79WMZM7_rN9lgCyiybe31NJ2xpU4sWVVE73MufYCbIPzKNCJXDs_OnUcaqA7YhRcosDoqD8ChbVdc4voC4b8-Kx-fE_O7N60rtmeCQ9rCXAWb2XFA/s1600/Screenshot+from+2016-07-31+17-40-17.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="283" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4s82Oqp_um_rtDIS503dCXDVj_g79WMZM7_rN9lgCyiybe31NJ2xpU4sWVVE73MufYCbIPzKNCJXDs_OnUcaqA7YhRcosDoqD8ChbVdc4voC4b8-Kx-fE_O7N60rtmeCQ9rCXAWb2XFA/s320/Screenshot+from+2016-07-31+17-40-17.png" width="320" /></a></div>
<br />
<br />
<b>--bg-scale </b>: Will distort the image to fit exactly within the confines of the desktop. Since this doesn't preserve the aspect ratio, stretching may be a result.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgspC70rn6Smn9q52mhRTJk0761Jh2HQ_LhwA6vuhICSwTHfJ6vI1HmAKznATvuXL8c6csFNO8xrwmBevR6kAEOpICoL7Th7_p5-wQ5GnqqHc5Q3SaWOoLTxBAUWy2qNakiDtUt0XEFf2Y/s1600/Screenshot+from+2016-07-31+17-40-57.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgspC70rn6Smn9q52mhRTJk0761Jh2HQ_LhwA6vuhICSwTHfJ6vI1HmAKznATvuXL8c6csFNO8xrwmBevR6kAEOpICoL7Th7_p5-wQ5GnqqHc5Q3SaWOoLTxBAUWy2qNakiDtUt0XEFf2Y/s320/Screenshot+from+2016-07-31+17-40-57.png" width="320" /></a></div>
<br />
<b>--bg-tile </b>: Will repeat the image until it fits within the monitor.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9kUBQnlo9IpfsuifZuSgE0eTaRbA-vgzNuIGpyYL6eWmoAXUTMPGmYVHM26lQ9VFmbJygrNvUkNGTteyU64RY0thZAhfrwzbXxazzxn42z7_eai-mASlRnzfUgEBIMYPGj2Fm0vC0pBs/s1600/Screenshot+from+2016-07-31+17-41-41.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9kUBQnlo9IpfsuifZuSgE0eTaRbA-vgzNuIGpyYL6eWmoAXUTMPGmYVHM26lQ9VFmbJygrNvUkNGTteyU64RY0thZAhfrwzbXxazzxn42z7_eai-mASlRnzfUgEBIMYPGj2Fm0vC0pBs/s320/Screenshot+from+2016-07-31+17-41-41.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Advanced Configuration</span></div>
<div class="separator" style="clear: both; text-align: left;">
So, now you know how to get the desktop set up in bspwm. But, bspwm "configurability" is a bit more than your average configurability. We can do some pretty cool stuff with the fact that we're using a shell to set the desktop background.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
How about instead of the earlier command, we put this in the configuration file:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<blockquote class="tr_bq" style="clear: both; text-align: left;">
feh --bg-center $(find ~/Pictures/Backgrounds -type f | shuf -n 1)</blockquote>
So that it randomly chooses a background out of a "Backgrounds" folder in your Pictures directory?<br />
<br />
Anything like this is possible in bspwm. You can have it change based on the time of day, or the type of music playing, or... anything really. The choice is always yours with BSPWM!<br />
<br />shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com3tag:blogger.com,1999:blog-2466616284663617777.post-92048490454695952852016-07-31T14:05:00.002-07:002016-07-31T14:37:11.207-07:00How To: Install bspwmAre you a Gnome or KDE user who is tired of the ordinary? Are you an i3 or herbstluftwm user who has heard the benefits of using bspwm? If you are, you have probably looked into it. And, furthermore, when you looked into it you may have found that it's a bit more involved than you had hoped. No worries! Following this guide should get you up and running with your very own bspwm configuration.<br />
<br />
<span style="font-size: x-large;">Install the Packages</span><br />
Installing the packages is, unfortunately, a little but harder than just calling apt-get. We have to compile them. Now, a bit more fortunately, all of the dependencies for bspwm are readily available in your repositories.<br />
<br />
<span style="font-size: large;">Dependencies</span><br />
<b>On Ubuntu:</b><br />
<div class="highlight highlight-source-shell" style="box-sizing: border-box; margin-bottom: 16px;">
<blockquote class="tr_bq">
sudo apt-get install xcb libxcb-util0-dev libxcb-ewmh-dev libxcb-randr0-dev libxcb-icccm4-dev libxcb-keysyms1-dev libxcb-xinerama0-dev libasound2-dev libxcb-xtest0-dev<br />
<br /></blockquote>
<div>
<div style="background-color: white; color: #333333; font-size: 16px; line-height: 24px;">
<b>On Fedora:</b></div>
<blockquote class="tr_bq">
sudo dnf install xcb-util-devel xcb-util-keysyms-devel xcb-util-wm-devel alsa-lib-devel dmenu rxvt-unicode terminus-fonts</blockquote>
<br />
<br />
<div style="background-color: white; color: #333333; font-size: 16px; line-height: 24px;">
Not too bad. What these commands do is install the dependencies that will be needed when we're building bspwm.</div>
<div style="background-color: white; color: #333333; font-size: 16px; line-height: 24px;">
<br /></div>
<div style="background-color: white; color: #333333; line-height: 24px;">
<span style="font-size: large;">Build Tools</span></div>
<div style="background-color: white; color: #333333; line-height: 24px;">
Since we're manually building bspwm, we need certain build tools. Libraries, compilers, etc. </div>
<div style="background-color: white; color: #333333; line-height: 24px;">
<b>Ubuntu</b></div>
<blockquote class="tr_bq">
sudo apt-get install gcc make</blockquote>
<div style="background-color: white; color: #333333; line-height: 24px;">
<b>Fedora</b></div>
<blockquote class="tr_bq">
sudo dnf groupinstall "Development Tools"</blockquote>
<div style="background-color: white; color: #333333; line-height: 24px;">
Alrighty. So, we have the dependencies and the build tools. Now, we need to download BSPWM.</div>
<div style="background-color: white; color: #333333; line-height: 24px;">
<br /></div>
<div style="background-color: white; color: #333333; line-height: 24px;">
<span style="font-size: large;">The Packages</span><br />
<span style="font-size: large;"><br /></span></div>
<div style="background-color: white; color: #333333; line-height: 24px;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1g7HUWPkFi332h7y5LPhEy0Ihwj5us0T__RPP3zIxatLAU25gzrZau4fY1Vxs6R9TRWGKujIFWdw2qaSpgwbueo1f5eLZUi7pvlnrkItEm4-Od0SGHZu7Q9vc46Jjxar67ZXbNcj0S4Q/s1600/bspwm_sxhkd.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1g7HUWPkFi332h7y5LPhEy0Ihwj5us0T__RPP3zIxatLAU25gzrZau4fY1Vxs6R9TRWGKujIFWdw2qaSpgwbueo1f5eLZUi7pvlnrkItEm4-Od0SGHZu7Q9vc46Jjxar67ZXbNcj0S4Q/s200/bspwm_sxhkd.png" width="200" /></a>Let's download the two packages using git, now.</div>
<blockquote class="tr_bq">
cd Downloads<br />
git clone https://github.com/baskerville/bspwm.git<br />
git clone https://github.com/baskerville/sxhkd.git</blockquote>
</div>
<div>
<div style="background-color: white; color: #333333; line-height: 24px;">
If all went well, you should have two folders in your 'Downloads' folder - "bspwm" and "sxhkd"</div>
<div style="background-color: white; color: #333333; line-height: 24px;">
<br /></div>
<div style="background-color: white; color: #333333; line-height: 24px;">
<span style="font-size: x-large;">Compilation</span></div>
<div style="background-color: white; color: #333333; line-height: 24px;">
The final step to installing the bspwm system itself is compiling it. To do this, go into the Downloads folder and type </div>
<br />
<blockquote class="tr_bq">
cd bspwm<br />
make<br />
sudo make install</blockquote>
</div>
<div>
<br />
Now, if you're not used to compiling things, this process probably looks a tad scary. There should be a lot of text scrolling along in the terminal - that is okay. Unless you see "Error, exiting" during this step, everything is working fine.<br />
<br />
After this, issue:<br />
<br />
<blockquote class="tr_bq">
cd ..<br />
cd sxhkd<br />
make<br />
sudo make install</blockquote>
If everything went well, we're ready to start doing some of the initial configuration. Awesome!<br />
<br />
<span style="font-size: x-large;">Configuration</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy1WM1lU9XeJLN7GyYEv0XCh2IMnF9ze3VTcGj3ghBmyepJ5pXXakG_EwJDPkDugl7gJYjjdPkV5HGLIRVKz6ZmCwzc1no6j0Jyxz1xcGjuwi_K2-E_T-lnKexpFjw4DHLRv6gbPeG3l0/s1600/bspwm_stack.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy1WM1lU9XeJLN7GyYEv0XCh2IMnF9ze3VTcGj3ghBmyepJ5pXXakG_EwJDPkDugl7gJYjjdPkV5HGLIRVKz6ZmCwzc1no6j0Jyxz1xcGjuwi_K2-E_T-lnKexpFjw4DHLRv6gbPeG3l0/s320/bspwm_stack.png" width="320" /></a></div>
<span style="font-size: x-large;"><br /></span>
Since bspwm and sxhkd are both installed, let's take a minute to analyze exactly where we are. We've installed bspwm, the window manager, and sxhkd, the keyboard daemon. How bspwm works this:<br />
<br />
<b>bspwm</b> manages your windows. Where they're placed, their layout on your desktop, etc. It doesn't handle anything else, unlike traditional window managers.<br />
<br />
<b>bspc </b>tells <b>bspwm</b> what to do. When you see bspwm moving windows, closing windows, etc. it's because <b>bspc</b> told <b>bspwm</b> over its socket file.<br />
<br />
<b>sxhkd </b>listens to the keyboard for keyboard shortcuts. These keyboard shortcuts can execute any arbitrary command, although they are commonly used to issue <b>bspc</b> commands, such as the command that tells <b>bspc</b> to close a window, etc.<br />
<br />
<span style="font-size: large;">Running - With a display manager</span><br />
Display managers control your X11 / Wayland (what makes your computer graphical, instead of all commands) sessions, as well as logging in. When you start your computer and see "username" and "password", you're looking at your display manager. Some common display managers on Linux are <b>lightdm </b>(commonly ubuntu), <b>gdm</b> (commonly gnome), <b>lxdm </b>(commonly lxde), and <b>kdm</b> (commonly kde).<br />
<br />
bspwm comes with the files necessary to add the window manager to the display manager you already use. In order to use your display manager to log in, you need to copy the "<b>bspwm.desktop</b>" file (from bspwm/contrib/freedesktop). In the Downloads folder:<br />
<br />
<blockquote class="tr_bq">
sudo cp bspwm/contrib/freedesktop/bspwm.desktop /usr/share/xsessions</blockquote>
Now, you can restart your display manager, or choose to reboot. bspwm should be an option in your display manager. You can skip the "Without a display manager" section and move onto configuration.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6Z57GEiohacUZVIBo8pOAFRUo5zJk3aedzBoFwQWQ2b1BBA9XTyYc-Fb_G3bs17F4VBDAmz9g7CTTxs0XrRwBy0RmtsUJOD9tAI-yBSkSXmcL-q7XDDUp9jxa2aRMCpshano7Te1ULmc/s1600/Screenshot+from+2016-07-31+15-39-32.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="141" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6Z57GEiohacUZVIBo8pOAFRUo5zJk3aedzBoFwQWQ2b1BBA9XTyYc-Fb_G3bs17F4VBDAmz9g7CTTxs0XrRwBy0RmtsUJOD9tAI-yBSkSXmcL-q7XDDUp9jxa2aRMCpshano7Te1ULmc/s320/Screenshot+from+2016-07-31+15-39-32.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Running - Without a display manager</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
Without a display manager, things are a bit more advanced. I'm assuming that if you're choosing to forego using a display manager, that you're a fairly advanced user, so I'll keep it short. Change the contents of your <b>~/.xinitrc </b>file to say<br />
<blockquote class="tr_bq">
exec bspwm</blockquote>
And you'll be good to go. But wait! We have to configure the keybindings.<br />
<br />
<span style="font-size: large;">Keybindings and Autostart</span><br />
Now, you should have bspwm completely installed on your system. However, if you tried to log into bspwm right now you would be greeted with... well, nothing. And, for the moment, that's fine. But the bad part is you won't be able to <b>do anything</b> either. In order to fix this, we need to set ourselves up some keybindings.<br />
<br />
Bspwm comes with files with default configurations. Let's get started with the window manager by copying these default keybindings and behavior's over to their respective directories. First, we must create those directories.<br />
<br />
<blockquote class="tr_bq">
mkdir ~/.config/bspwm<br />
mkdir ~/.config/sxhkd</blockquote>
<br />
<b>bspwm's configuration:</b><br />
<blockquote class="tr_bq">
<br />
cp ~/Downloads/bspwm/examples/bspwmrc ~/.config/bspwm/<br />
chmod +x ~/.config/bspwm/bspwmrc </blockquote>
<b>sxhkd's configuration:</b><br />
<b><br /></b>
<br />
<blockquote class="tr_bq">
cp ~/Downloads/bspwm/examples/sxhkdrc ~/.config/sxhkd</blockquote>
<b>Further configuration</b><br />
Now, it may be preferable to edit either of these files. The function of <b>bspwmrc</b> in <b>.config/bspwm</b> is essentially an "autostart" file. It lists commands that bspwm should run when it starts up. Now, remember, bspwm is controlled via commands, so rules which govern how bspwm behaves are located in this file.<br />
<br />
Things such as how monitors should be handled, window borders, rules for allowing certain windows to float, etc. are all configured here, as well as any programs you want to run when bspwm starts up (like, say, your bluetooth daemon).<br />
<br />
<b>sxhkdrc </b>in <b>.config/sxhkd </b>controls keybindings. Keybindings for bspc are common, and important to make note of. By default, some of the most important default commands are:<br />
<br />
<b>super + return | urxvt</b><br />
<b>super + space | dmenu_run</b><br />
<b>super + escape | [reload sxhkd configuration]</b><br />
<b>super+alt+Escape | logout of bspwm</b><br />
<b>super+m | Change the desktop mode</b><br />
<b><br /></b>
These commands, especially <b>super+return </b>should get you started.<br />
<blockquote class="tr_bq">
<span style="font-size: x-small;">Note: super is the mod4 key on the keyboard, commonly called the "Windows" key as it usually dons the Windows logo</span></blockquote>
Now, with all of these files in place, we should be ready to start bspwm for the first time. If you don't have urxvt already installed, it's important to issue:<br />
<br />
<b>Fedora</b><br />
<blockquote class="tr_bq">
sudo dnf install rxvt-unicode</blockquote>
<b>Ubuntu</b><br />
<blockquote class="tr_bq">
sudo apt-get install rxvt-unicode</blockquote>
So that you're able to use the terminal when you start using bspwm. The terminal is essential, as it will allow you to modify your sxhkd configuration once you're in bspwm.<br />
<br />
If you'd like dmenu (it's an application launcher), issue:<br />
<br />
<b>Fedora</b><br />
<blockquote class="tr_bq">
sudo dnf install dmenu</blockquote>
<br />
<b>Ubuntu</b><br />
<blockquote class="tr_bq">
sudo apt-get install suckless-tools</blockquote>
<blockquote class="tr_bq">
</blockquote>
<span style="font-size: x-large;">Using bspwm</span><br />
Now, start bspwm. If you installed bspwm into your display manager, you can select it from the menu there. If you chose to use <b>.xinitrc</b>, then use "startx" at a tty.<br />
<br />
It may seem like it's not working when you start it. It will either show a black screen or the "splash screen" of the display manager when you first log into it.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5smQuufvrzFptBW078j5Mzu6HkkrEG_qzMJKAfQWd_YfPhpLSCEzoJgn82hG3GyK1RMpX85wCqbWPVlQRPFQLyISE2TdEKSPeGx2752PoG4qsEdpozqI1qBzYKj1yoQgEikdC2axRXjY/s1600/Screenshot+from+2016-07-31+16-27-09.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="239" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5smQuufvrzFptBW078j5Mzu6HkkrEG_qzMJKAfQWd_YfPhpLSCEzoJgn82hG3GyK1RMpX85wCqbWPVlQRPFQLyISE2TdEKSPeGx2752PoG4qsEdpozqI1qBzYKj1yoQgEikdC2axRXjY/s320/Screenshot+from+2016-07-31+16-27-09.png" width="320" /></a></div>
<br />
<div style="text-align: center;">
<span style="font-size: x-small;">This is how it looks on Ubuntu</span></div>
<div style="text-align: left;">
<span style="font-size: x-small;"><br /></span></div>
Since we installed urxvt, we can launch the terminal with <b>super+enter</b>, or whatever you changed it to.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV8QaPFReOH7CFR4w_Sy-0ayUg6JmZ4rGkApDz_LWCjmN8UQFa6GubmkuBN5hcudfT_ufJWykt6kvTV47ZXb5YS8wJ4KPdHUyd8imUpT4Ehf2AOxER5TetPfENe6IGFqtHo4nQ0eRefr4/s1600/Screenshot+from+2016-07-31+16-28-31.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="239" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV8QaPFReOH7CFR4w_Sy-0ayUg6JmZ4rGkApDz_LWCjmN8UQFa6GubmkuBN5hcudfT_ufJWykt6kvTV47ZXb5YS8wJ4KPdHUyd8imUpT4Ehf2AOxER5TetPfENe6IGFqtHo4nQ0eRefr4/s320/Screenshot+from+2016-07-31+16-28-31.png" width="320" /></a></div>
By default, it takes up the entire screen like this. But, notice that when you open another program, it will split the total space in half.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcAuHetQ80dSiGwHgy-uElpGmG-swWiLsWvJUP2jxALWoaeYt6JcaixmrEph-IkIc7SsY7uu2hnUljGnnuvnUJaLi2RuFMiHNDOHPv7LQQlyA8N2inpOdlUDTHBDyJMf9vmtpl7GHycFU/s1600/Screenshot+from+2016-07-31+16-31-32.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="239" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcAuHetQ80dSiGwHgy-uElpGmG-swWiLsWvJUP2jxALWoaeYt6JcaixmrEph-IkIc7SsY7uu2hnUljGnnuvnUJaLi2RuFMiHNDOHPv7LQQlyA8N2inpOdlUDTHBDyJMf9vmtpl7GHycFU/s320/Screenshot+from+2016-07-31+16-31-32.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
This is showcasing bspwm's tiling ability. However, bspwm can do so much more than the default sxhkd and bspwmrc files allow you to do.<br />
<br />
<span style="font-size: x-large;">Conclusion</span><br />
Well, there we have it. We now have a working bspwm configuration, and we're ready to get tinkering! Typing "man bspc" at a terminal will show you all of the awesome things that you can do with bspwm, so there's plenty to try out in the new desktop.<br />
<br />
This is the beginning of a series of articles about bspwm and sxhkd on this blog. For more, see below, where I'll be adding additional content as it is made:<br />
<br />
<b>Modifying keybindings in bspwm : [In Progress]</b><br />
<b><br /></b>
Happy hacking!<br />
<br />
<span style="font-size: x-small;">Huge thanks to <a href="https://github.com/windelicato/dotfiles/wiki/bspwm-for-dummies">https://github.com/windelicato/dotfiles/wiki/bspwm-for-dummies</a> by windelicato, where most of this guide was sourced from. I paraphrased much of this guide from his original writeup here for the purpose of clearing up the process, and fixing one mistake he made in the original guide.</span></div>
</div>
shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com2tag:blogger.com,1999:blog-2466616284663617777.post-9784545397997652352016-07-31T08:26:00.001-07:002016-07-31T08:26:24.516-07:00What is a Monad? What is a Higher Kinded type?If you're stumbling upon this document, I'm guessing that you're just getting into a statically typed programming language and are (rightfully) confused about what all the kerfuffle regarding Monads and Higher-Kinded types are. This blog article will clear all the confusion you have about what monads and higher kinded types really <b>are</b>, but how to <b>use</b> higher kinded types (in, say, Haskell) is not covered here.<br />
<br />
<span style="font-size: large;">Background - Static Types</span><br />
<span style="font-size: large;"><span style="font-size: small;">Before we can really talk about what a monad is, let's take a step back. In terms of programming, monads only exist in programming langauges which support <b>strong static typing</b>. That means, that the type system of the programming language follows a mathematical type system. See: <a href="https://en.wikipedia.org/wiki/Type_theory">Wikipedia</a>.</span> </span> The reason that this is so neat is that Type Theory is the basis of all of mathematics. Every other branch, including Calculus, Algebra, Trigonometry, Statistics, etc. can all be defined in terms of Type Theory operations.<br />
<br />
In programming languages, types denote the type of data you're working with. Numbers may be classified as "int" or "double" in a lot of languages, which are different types which represent numbers. Text may be of type "string", etc. Languages that have "strong" static types take this a step further, being a direct representation of their type-theory counterparts.<br />
<br />
<span style="font-size: large;">Background - Type Theory</span><br />
Types in type theory work as such: there are two variations of information. 'Types' and 'Kinds'. Kinds are, in a way, the father of types.<br />
<br />
The kind, denoted "*", is literally pronounced "type". It is used to describe any type that doesn't take a type argument (more on this later). This can include things like functions, ints, doubles, strings... pretty much every type that you're experienced with, outside of generics.<br />
<br />
The kind * -> * is where things begin to be interesting. This is about as far as Haskell and many other strongly-typed languages truly go (with the exception of kind (* -> *) -> *, the higher-order kind). This is the kind of any type that takes one type parameter... a little unclear? Read on.<br />
<br />
<span style="font-size: large;">Higher Kinded Types and Monads</span><br />
* -> * you can think of as a "template template". Think of, in Java, this class:<br />
<br />
<b style="background-color: white;">class myClass<T>{</b><br />
<b style="background-color: white;"> T myItem;</b><br />
<b style="background-color: white;">}</b><br />
<span style="background-color: #eeeeee;"><br /></span>
<span style="background-color: white;">In this case, the type "myClass" is the first * and the type "T" is the second *. In Haskell, which is strongly statically typed, a data type declaration, such as</span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;"><b>data List a = Node a | Rest (List a)</b></span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;">In this case here, List a has the kind "* -> *" because it takes one type parameter (a). </span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;">The important thing to realize about this, is that kinds of this type can be generecized within the type declarations of other functions. As an example of exactly what that means:</span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;">myFunction :: l a -> [a]</span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;">would take any * -> * that takes 'a' as a type paramter, and returns an array of that type from it.</span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;"><span style="font-size: large;">Where do Monads fit into the equation?</span></span><br />
<span style="background-color: white;">Monads are a concept from category theory. There, monads are an endofunctor paired with two natural operations. The details of this are interesting, but outside the scope of this quick run-down of HKT's and monads. Check out <a href="https://en.wikipedia.org/wiki/Category_theory">Category Theory</a> if you'd like to know more.</span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;">The function declaration of monad's function is as such:</span><br />
<span style="background-color: white;"><br /></span>
<a class="dull" href="http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:-62--62--61-" style="background-color: #ffffbb; color: black; font-family: sans-serif; font-size: 16px; text-decoration: none;">Monad m => m a -> (a -> m b) -> m b</a><br />
<br />
So, as you can see, Monads are only possible with the use of Higher-Kinded types ((m a) and (m b), make the kind * -> *). Monads also define particular functions which follow the 'monadic laws', however, these are unrelated to their basis in the type system.<br />
<br />
<span style="font-size: large;">Conclusion</span><br />
Type theory is a gigantic branch of mathematics, and this quick run-down of how types work in statically typed languages does not even closely begin to scratch the surface. Hopefully you've taken away a bit more about what it means to be "higher kinded", and a bit how monads use the type system to exist.<br />
<br />
If you'd like to learn more or correct me on something I said wrong up above, by all means feel free to comment!<br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;"><br /></span>shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0tag:blogger.com,1999:blog-2466616284663617777.post-14445450925426311102016-07-28T12:28:00.001-07:002016-07-31T17:24:09.063-07:00Comparison of Java IDEs<span style="font-size: x-large;">Why use an IDE?</span><br />
If you're writing Java programs, you are without a doubt using a Java IDE of some sort. The way that Java runs, that is, using managed bytecode on a virtual machine means that the compilation step is a bit more rigorous than a call to <b>gcc</b> as you would do for a C source file. In any given Java program, you go through so many steps to compile and run the bytecote that it's nearly nonsensical to use the language without an IDE.<br />
<br />
Additionally, the language's complex foundation (meaning, it's extensive standard library, OO model, and verbose nature) make it even more perfect of a fit for a language to use along with an IDE. So, you can't be too informed about what IDE is good for you.<br />
<br />
<span style="font-size: x-large;">Personal IDE Ranking</span><br />
Quickly, here are the IDE's that I've used and most like for Java development:<br />
<br />
<b>#1 - IntelliJ</b><br />
<a href="https://www.jetbrains.com/idea/download/">Download</a><br />
<br />
<b>#2 - Eclipse</b><br />
<a href="https://eclipse.org/downloads/">Download</a><br />
<br />
<b>#3 - Netbeans</b><br />
<a href="https://netbeans.org/downloads/">Download</a><br />
<br />
These are the basic Java IDE's. For a more in-depth look, check out this list <a href="https://blog.idrsolutions.com/2015/03/the-top-11-free-ide-for-java-coding-development-programming/">here</a>.<br />
<br />
<span style="font-size: x-large;">Strengths and Weaknesses</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">IntelliJ</span><br />
IntelliJ, Jetbrain's Java IDE, has become the de-facto Java IDE in the industry. As a matter of fact, many of Jetbrain's products are used all across the software industry (most famously, their Resharper plugin for the Visual Studio ecosystem).<br />
<br />
Its strength lies in a very strong out-of-the box experience with heaps of features missing from the other two popular Java IDE's. Some of these features include:<br />
<br />
<b>Out-of-the-box experimental technologies</b><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYn3FKD6Yl-RfjogvxHUuDgPQWPiXS4Sswkj2jgRQ54NBsWRy0pSDMiOPSuTpW_6kAqMg5SzRZ9k_rDXDbtC8R44m0Z3Z4VdPOTI7doXNwz1-ybZLcCclV2ikkKV-HHndpHUkPOPJlbNg/s1600/Screenshot+from+2016-07-28+13-54-38.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="205" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYn3FKD6Yl-RfjogvxHUuDgPQWPiXS4Sswkj2jgRQ54NBsWRy0pSDMiOPSuTpW_6kAqMg5SzRZ9k_rDXDbtC8R44m0Z3Z4VdPOTI7doXNwz1-ybZLcCclV2ikkKV-HHndpHUkPOPJlbNg/s320/Screenshot+from+2016-07-28+13-54-38.png" width="320" /></a></div>
<b><br /></b>
With Netbeans or Eclipse, you can feasibly use technologies such as groovy and maven. With Eclipse, you can integrate Scala, Clojure, kotlin, etc. into the IDE with the use of addons. However, IntelliJ IDE comes with support for these supplemental JVM languages out of the box. Support includes first-party support, syntax highlighting, code completion, etc. They are first class members of the IntelliJ ecosystem.<br />
<br />
<b>Unbelievable code completion and Linting</b><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3kGf95Rl-FE0sTu6PFga48buC6FWQC0RPJXBPtV8OhUBs9-sLofO57A_E4vO50ezeMSr_k1-fUitsyx0kvScjwK1a2MIm1zJnmlW6edWzYlHMtH-B1jbHnOuOx7FJHArTRbka6xyF2q4/s1600/Screenshot+from+2016-07-28+13-55-51.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="51" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3kGf95Rl-FE0sTu6PFga48buC6FWQC0RPJXBPtV8OhUBs9-sLofO57A_E4vO50ezeMSr_k1-fUitsyx0kvScjwK1a2MIm1zJnmlW6edWzYlHMtH-B1jbHnOuOx7FJHArTRbka6xyF2q4/s320/Screenshot+from+2016-07-28+13-55-51.png" width="320" /></a></div>
<b><br /></b>
IntelliJ's code completion is good. Creepily good. It will never fail to resolve the name of some class's methods, if it's your class or some other library's class. It supports sensible completion for the newest of Java features, such as generating lambdas.<br />
<br />
Speaking of lambdas, IntelliJ's linting process will often tell you to replace lines of code. It will automatically transform uncessary loops into lambda calls to tidy up your source, or report sources of possible error as you write them.<br />
<br />
<b>Stellar Android support</b><br />
Android Studio, the de-facto IDE for creating Android programs at the moment, is based on IntelliJ. So, in order to install Android Studio, you need only install one plugin for this IDE, retaining all of your other settings you have within it.<br />
<br />
The Android plugin includes a drag-and-drop GUI designer, cached emulation for fast in-pc testing of android apps, and the same great code completion that it has for all java source files, which is even more important for Android.<br />
<br />
Unlike some other IDE's which support Android, IntelliJ's XML editing leaves almost nothing to be desired.<br />
<b><br /></b>
<b>Next-level debugging</b><br />
To emphasize just how good the built-in debugger in IntelliJ is, understand that I am no stranger to debugging, inside and outside of IDE's. I've been mucking around with debuggers since it meant crawling through assembly outputs to identify your issue. In that time, I have never come across an IDE as featureful and powerful as IntelliJ's. The debugger is my personal favorite feature of this IDE.<br />
<br />
Breakpoints support more feature's than a lot of other IDE's.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnWR5XUQ12sEP4rxTwijth3UfMYcVVg2He3Vgonm3VIM_CcBxzR8M9zwlgBX0R2XY7j-t4ghMlPGv_b4Xvd60hLDdQ10IuR0pfiWhFX9A6kS9IF7dfLwXr-IzwrYfJ7-hvnz5I89qS5Nk/s1600/2016-07-28-132140_413x194_scrot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnWR5XUQ12sEP4rxTwijth3UfMYcVVg2He3Vgonm3VIM_CcBxzR8M9zwlgBX0R2XY7j-t4ghMlPGv_b4Xvd60hLDdQ10IuR0pfiWhFX9A6kS9IF7dfLwXr-IzwrYfJ7-hvnz5I89qS5Nk/s320/2016-07-28-132140_413x194_scrot.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
You can choose to sleep just the thread where the breakpoint is set, or the entire thing. You can choose to not even suspend execution on your breakpoints. And, most importantly, you can set a condition for the breakpoint to break on. Even cooler is the fact that the condition line supports code completion.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
The debugging process itself is just as featureful as the breakpoints are. It supports all the standard features that a debugger should have, such as "Step Into", "Step out", "Step Over", etc. But it also has some advanced features like "Drop Frame" (for recursive functions), and "Force Step" for situations resistant to debugging... which, surpirsingly, do come up from time to time for some reason or another.<br />
<br />
As you debug, the values of local variables are displayed alongside of your code as gray text.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEje7su287NBzjvirnf19Xf-cfSw0lBIx_8CZKvXhyFObUWcyWOvOObGlQadp-z-DRzBVMJ7LqvXQhtM9vGlzSH3SG9WBn6F63Hjg8f92XIpf_SNwU-YRmVVT4LJfOqkhSkZv14e6RE0B6U/s1600/Screenshot+from+2016-07-28+13-23-05.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEje7su287NBzjvirnf19Xf-cfSw0lBIx_8CZKvXhyFObUWcyWOvOObGlQadp-z-DRzBVMJ7LqvXQhtM9vGlzSH3SG9WBn6F63Hjg8f92XIpf_SNwU-YRmVVT4LJfOqkhSkZv14e6RE0B6U/s1600/Screenshot+from+2016-07-28+13-23-05.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
As is the case with many IDE's, IntelliJ supports evaluating expressions at any point during the debugging process.</div>
<br />
<b>Integrated VCS management</b><br />
IntelliJ has top-notch VCS integration. You can pull changes, push changes, edit commit logs, and even apply patches from diff to your project directly.<br />
<br />
<b>Other</b><br />
A feature that, for me, sums up the type of IDE IntelliJ is is "Create gist"<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRr6gBrUBQuIUxDFR9fYfRms5zSnWCoGpjXwWJLTIeVfspGqlhi60HouhvQ8on1dewBCwyzlRDFB_p8SpyxNHGMoI-kwK_hfY8aY439JxS-VaXr4BLcZO1gYqPenEwX8ZRk6jHDl2DwJo/s1600/c_gist.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRr6gBrUBQuIUxDFR9fYfRms5zSnWCoGpjXwWJLTIeVfspGqlhi60HouhvQ8on1dewBCwyzlRDFB_p8SpyxNHGMoI-kwK_hfY8aY439JxS-VaXr4BLcZO1gYqPenEwX8ZRk6jHDl2DwJo/s320/c_gist.png" width="189" /></a></div>
When I saw that the context menu had an option to paste to gist, I was excited. Partly because it makes it easier to ask for help via IRC, but mostly because it shows the type of IDE that IntelliJ is. It is truly the frontrunner in keeping up with the latest in the software industry.<br />
<br />
<b>Weaknesses</b><br />
As biased as I may be for this IDE, I truly feel that IntelliJ doesn't have anything wrong with it as far as the software itself is concerned. I've used this IDE for a bit over one year, at one point for a pretty major project (hundreds of thousands of lines of source, 100+ files). In that year, it has never crashed for me, or behaved in a way that it would not allow me to accomplish my work.<br />
<br />
The IDE itself, or some addon, always had whatever feature I was looking for in the Java IDE.<br />
<br />
The only problem with the product, in my opinion, is the fact that the non-community edition (which has features that do make it worth it) costs quite a bit of money, and the subscription doesn't particularly make sense. In addition, Jetbrains products are not Open Source or Free, so you can't modify them if you do need to integrate deeply with the IDE, fix some bug, or just see how it's running.<br />
<br />
<span style="font-size: large;">Eclipse</span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
Eclipse, for many years, was considered the "professional" Java development environment. Interestingly, Eclipse is as much a plugin framework as it is a desktop environment. Behind Firefox, it is the second most extensible desktop application ever created. Quite literally, "eclipse" is just a plugin framework that has a lot of good Java editing addons pre-installed. Or C++ editing addons. Or brainfuck editing addons. Or, really, anything you can conceive.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKviFKHoergEYC1ZfET0cbgauTspZbmPfitCg5gC-RBHLgudIuzFMPmb5YPQbw46hVzrvFxyc4DrRSLHDJBSmWtjFYp0I6P7nFovfEkuOIF_AUn2L_xxZpM5b_XDVpWEJi7l_bI8EOZhA/s1600/Screenshot+from+2016-07-28+14-00-03.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKviFKHoergEYC1ZfET0cbgauTspZbmPfitCg5gC-RBHLgudIuzFMPmb5YPQbw46hVzrvFxyc4DrRSLHDJBSmWtjFYp0I6P7nFovfEkuOIF_AUn2L_xxZpM5b_XDVpWEJi7l_bI8EOZhA/s320/Screenshot+from+2016-07-28+14-00-03.png" width="320" /></a></div>
<span style="font-size: large;"><br /></span>
<b>Extensibility</b><br />
Extensibility within Eclipse is no joke. It gives you the tools to fine-tune everything about the IDE. You can transform the IDE to do anything you want to. It has very good "official" addons for it, such as Android, C++, and Java. On top of that, there are tens of thousands of community plugins, which can turn Eclipse from a Java development environment to, say, a Lisp environment, a Ruby environment, a D environment, or a development environment for just about any language imaginable.<br />
<br />
It's rather easy to create a plugin for Eclipse. You do so with plain Java and XML, and you're able to install plugins that you make yourself to fine tune anything about Eclipse that you would like.<br />
<br />
<b>Featureful Project management</b><br />
Eclipse, would like to make sure that it has every possible use-case covered. The user should barely have to do anything with setting their project up manually. This includes things like inheritance and interface implementation. Take a look at the "New Class" dialog box:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLouemGSohjoRY0FFSDzUZO_6lbvzfMGZgb7SELYvDZdgZ0Of5JwhNsjK5ZkXIZBu1fdAPgYSBtyGQ5XE-1IExIFg75h8RXLKHSqccGHSaxIdAdWCSnCdOhRBexQhLstaJYkGJp2pdDVg/s1600/Screenshot+from+2016-07-28+14-23-50.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLouemGSohjoRY0FFSDzUZO_6lbvzfMGZgb7SELYvDZdgZ0Of5JwhNsjK5ZkXIZBu1fdAPgYSBtyGQ5XE-1IExIFg75h8RXLKHSqccGHSaxIdAdWCSnCdOhRBexQhLstaJYkGJp2pdDVg/s320/Screenshot+from+2016-07-28+14-23-50.png" width="253" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
This makes it very simple for somebody new to Java to generate a ton of code. Or, if you're extending a large class or implementing a large interface, it streamlines the experience by quite a bit.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Other</b></div>
<div class="separator" style="clear: both; text-align: left;">
Like IntelliJ, Eclipse supports code completion very well (not quite as well as IntelliJ, mind you). It supports debugging, but, once again, not as well as IntelliJ can debug.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
However, one key advantage that Eclipse has over IntelliJ is the fact that it is Open Source and completely free to use. You can edit it, or add one plugin to the tens of thousands that already exist. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
If you're a programming multiglot, you should seriously consider Eclipse, since it could become your environemnt for all of your programming languages if you choose for it too. However, if you're looking to purely write Java programs, IntelliJ may be the better option.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Weaknesses</b></div>
<div class="separator" style="clear: both; text-align: left;">
Eclipse has quite a few weaknesses. As it is so extensible, you will often get the feeling that the IDE is "held together with duct tape", as I heard my professor say about Eclipse. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
It uses something called "Perspectives" to display information to the user. These perspectives are essentially windows, and Eclipse is the window manager. That leads to odd behavior like this: </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgab8t6hms3vyl_gMcFsPWzcEvTga5gveb1PqW0jNuhn2alRDEnEl2I2H-6D1heDikcRVqF5pcreNy-inE9pLWgM6OLOd5grRSW9RfUqXI36gEjnR-lEAz4tUcwmRXy0N9XStpKyOV1Fjw/s1600/Screenshot+from+2016-07-28+14-31-10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="173" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgab8t6hms3vyl_gMcFsPWzcEvTga5gveb1PqW0jNuhn2alRDEnEl2I2H-6D1heDikcRVqF5pcreNy-inE9pLWgM6OLOd5grRSW9RfUqXI36gEjnR-lEAz4tUcwmRXy0N9XStpKyOV1Fjw/s320/Screenshot+from+2016-07-28+14-31-10.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
where you may have to resize your IDE to fit the entire Eclipse window, since the IDE features are themselves plugins. This is a good display of just how truly extensible Eclipse is, however, it's a bit cumbersome to work with if all you're looking to do is edit some Java.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The fact that Eclipse is so extensible also makes the memory usage quite high, even by Java program standards. This is not a problem on most systems, but on slower computer the overhead of being so extensible can really slow things down.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Unlike IntelliJ, there is no baked-in support for version control. However, there are many git / subversion plugins available in the Eclipse repositories to fit these needs.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Netbeans</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkLB0jre-RcYcBknjnI1MYT4uGrZi-UHEngq462Z4cvCG7B0t4LR3GYuU_ioD6HcBaJdQ4oCBfVnzJmhn5KrPLiOTaZ39Lktd7iuz3yqXdcxSyAaul3xgGQv73-JVaiJwUHppp8wM7_Y0/s1600/Screenshot+from+2016-07-28+15-02-24.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="173" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkLB0jre-RcYcBknjnI1MYT4uGrZi-UHEngq462Z4cvCG7B0t4LR3GYuU_ioD6HcBaJdQ4oCBfVnzJmhn5KrPLiOTaZ39Lktd7iuz3yqXdcxSyAaul3xgGQv73-JVaiJwUHppp8wM7_Y0/s320/Screenshot+from+2016-07-28+15-02-24.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Netbeans is another traditional Java IDE, like IntelliJ. It's been around for years, and is the default Java IDE (meaning, that Oracle develops it and bundles it with their Java downloads). Despite Oracle having control over Netbeans, the IDE is completely open source.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
And, although it is most comparable to IntelliJ, it shares some similarities with Eclipse, including its numerous addons. However, most of the features that you would end up using Netbeans for are pre-installed.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Simplicity</b></div>
<div class="separator" style="clear: both; text-align: left;">
Something can be said about Netbeans that cannot be said about Eclipse. It's dead-simple. It's a traditional editor, reminiscent of code::blocks and the like. Its RAM usage tends to be quite low, and the learning curve for Netbeans is high, making it a great instructional or introductory IDE.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
When you create a Java project, it will create a default package and the main class automatically. Unlike IntelliJ and Eclipse, you are ready to execute your java program the second you create it.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Enterprise Support</b></div>
<div class="separator" style="clear: both; text-align: left;">
When you think of Oracle, you think "Enterprise", and Netbeans has features that back this up. It has features, such as allowing you to automatically Globalize your applications with international strings. It allows you to do most things you may need to do in Java through the IDE in pre-defined ways as well. Inheritance, encapsulation, code formatting, comment generation, etc. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Code Completion</b></div>
<div class="separator" style="clear: both; text-align: left;">
Netbeans has powerful code completion, but it falls short of both Eclipse and IntelliJ. It can automatically fix issues from the context menu, but it won't provide this option as well as Eclipse or IntelliJ does, and it will mostly be able to fix warnings and errors only; it won't improve already working code like IntelliJ. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The downside with the code completion is that many times it incorrectly assumes what you want. If you put the line <span style="background-color: #eeeeee;">import javax.swing.UIManaer;</span><span style="background-color: white;"> where you actually want <b>javax.swing.UIManager</b>, it will suggest that you create a new local package called <b>javax.swing.UIManaer </b>and write the class yourself.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><b>VCS support</b></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;">Netbeans has support for all of the major Version Control systems out of the box, including <i>mercurial, git, </i>and <i>subversion.</i><b style="font-style: italic;"> </b>This is one clear advantage it has got over Eclipse, however, the VCS integration doesn't offer all of the features that IntelliJ's does.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;"><b>Multi-Project support</b></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;">Netbeans has my favorite multi-project support out of any IDE. It lets you quickly zip back and forth between various projects from the project browser. </span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaT6FXoLFq8DchtvsKUigG_fbMEadQUJ8oQWu06hh0lRIEgqQhy4Vmi1CeC5hyphenhyphenNvqBt08u4NuI-w8sbGkoU-iy8mAUzIgfWwZsfjkQCq9G2Riopgv50DfyJvSUXdRxUQL4qM9Pw7Dvs9k/s1600/Screenshot+from+2016-07-28+15-06-09.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaT6FXoLFq8DchtvsKUigG_fbMEadQUJ8oQWu06hh0lRIEgqQhy4Vmi1CeC5hyphenhyphenNvqBt08u4NuI-w8sbGkoU-iy8mAUzIgfWwZsfjkQCq9G2Riopgv50DfyJvSUXdRxUQL4qM9Pw7Dvs9k/s320/Screenshot+from+2016-07-28+15-06-09.png" width="267" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Weaknesses</b></div>
<div class="separator" style="clear: both; text-align: left;">
Netbeans is, in my opinion, the weakest of all the 3 major Java IDE's. It will allow a beginner to get started in Java, but it lacks so many features that Eclipse and IntelliJ have that it's not worth trying to work around it. The linting is non-existant. The code completion doesn't work 100% of the time. The interface is surprisingly error-prone in contrast with Eclipse, which, since everything is a perspective, you may imagine that it would have a lot of errors.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
I stopped using Eclipse a few versions ago, but at one point it crashed and refused to open the project I was working on again. I recall this happening twice during one semester of a java course, which means that it may be common with the IDE. At the time, we were just working with classes for educational purposes. That is, no external libraries or unit tests, which may increase the chances of it crashing.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Other Java IDE's</span></div>
<div class="separator" style="clear: both; text-align: left;">
The only other Java IDE that I have experience with is <a href="http://www.bluej.org/">BlueJ</a>, which I have nothing good to say about. The interface is built around the idea that a problem that literally does not exist should be solved (that using user-defined classes is too difficult). It provides syntax highlighting and rudimentary code completion / debugging / unit test generation, but that is literally all. It isn't worth it to look into BlueJ unless you're going to do so for the novelty of the experience.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: x-large;">Comparison</span></div>
<div class="separator" style="clear: both; text-align: left;">
Here, I will list the scores for some goals you may have for your Java IDE.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Extensibility</b></div>
<div class="separator" style="clear: both; text-align: left;">
Eclipse - 10</div>
<div class="separator" style="clear: both; text-align: left;">
IntelliJ - 8</div>
<div class="separator" style="clear: both; text-align: left;">
Netbeans - 5</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Stability</b></div>
<div class="separator" style="clear: both; text-align: left;">
IntelliJ - 9</div>
<div class="separator" style="clear: both; text-align: left;">
Eclipse - 7</div>
<div class="separator" style="clear: both; text-align: left;">
Netbeans - 4</div>
<br />
<br />
<b>Code Completion</b><br />
IntelliJ - 8<br />
Eclipse - 6<br />
Netbeans - 5<br />
<br />
<b>Code Generation</b><br />
Eclipse - 9<br />
IntelliJ - 8<br />
Netbeans - 4<br />
<br />
<b>Debugging</b><br />
IntelliJ - 10<br />
Eclipse - 5<br />
Netbeans - 3<br />
<br />
<b>Unit Tests</b><br />
IntelliJ - 8<br />
Eclipse - 6<br />
Netbeans - 4<br />
<br />
<b>Version Control</b><br />
IntelliJ - 8<br />
Netbeans - 7<br />
Eclipse - 2 (must be used via addon)<br />
<br />
<b>Open Source</b><br />
Eclipse - 10<br />
Netbeans - 5<br />
IntelliJ - 1<br />
<br />
<b>Android</b><br />
IntelliJ - 10<br />
Eclipse - 8<br />
Netbeans - 4<br />
<br />
<b>HTML, CSS, Javascript</b><br />
IntelliJ - 9<br />
Eclipse - 9<br />
Netbeans - 3<br />
<br />
<b>Kotlin, Scala, Clojure</b><br />
IntelliJ - 10<br />
Eclipse - 9<br />
Netbeans - 0<br />
<br />
<b>Learning Curve</b><br />
Netbeans - 8<br />
IntelliJ - 7<br />
Eclipse - 5<br />
<br />
<b><u>Totals</u></b><br />
IntelliJ: <b>96 / 215</b><br />
Eclipse: <b>67 / 215</b><br />
Netbeans: <b>52 / 215</b><br />
<b><br /></b>
<span style="font-size: large;">You should use IntelliJ if...</span><br />
You just straight-up want to edit Java source. You don't need insane amounts of extensibility or the ease and official support of using Netbeans. Additionally, if you're going to be working with Android, you want IntelliJ.<br />
<br />
<span style="font-size: large;">You should use Eclipse if...</span><br />
You need an open-source IDE that is as extensible as it is deep. If your project using many languages and technologies, Eclipse may also be the best bet for you.<br />
<br />
<span style="font-size: large;">You should use Netbeans if...</span><br />
You are just starting out in the world of Java, or, for some reason, you're not comfortable with IntelliJ or Eclipse. If you are an instructor, you may also want to use Netbeans for your students.<br />
<br />
<span style="font-size: large;">You should use BlueJ if...</span><br />
You have a mental defect, but don't want it to get in the way of your programming fun.<br />
<br />
Hopefully this article helped you make your choice. Good luck!<br />
<br />
<br />shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com3tag:blogger.com,1999:blog-2466616284663617777.post-65417009137407580192016-07-01T09:52:00.001-07:002016-07-01T09:52:07.521-07:00How to Fix: No Audio with a bluetooth headset in LinuxHopefully I can help some of your with this problem that I had a few months ago. Here was the scenario: everything seemingly worked fine with my bluetooth headset. It connected, played music flawlessly and everything on first connect... but as soon as I rebooted the headphones, nothing.<br />
<br />
They still connected as a media device. The volume control on the computer still worked. But no sound at all would transfer between my computer and the headphones. Weird.<br />
<br />
<span style="font-size: large;">First Things First</span><br />
Let's make sure they're configured in the first place. Consult your manual on how to sync your device. Then, from your desktop environment's settings (if you're not using a Desktop Environment, check out <a href="https://github.com/blueman-project/blueman">blueman</a>), click "Bluetooth"<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmwNf4KmacNYMG3UsUzJoNTJ9yLylj2ZESfw8MikvyM0-mRRThbC2GbfIvBpaDM1a5-6lR3jE5fxkmyjVr362Ba-Ak1xGAIomi609NCTEB2UwfPdn5h3uNXJjeT_gyfi1pMGMa06bBzgc/s1600/2016-07-01-123911_736x534_scrot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="232" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmwNf4KmacNYMG3UsUzJoNTJ9yLylj2ZESfw8MikvyM0-mRRThbC2GbfIvBpaDM1a5-6lR3jE5fxkmyjVr362Ba-Ak1xGAIomi609NCTEB2UwfPdn5h3uNXJjeT_gyfi1pMGMa06bBzgc/s320/2016-07-01-123911_736x534_scrot.png" width="320" /></a></div>
<br />
<span style="text-align: center;">It should say "Connected". This is a sign that the bluetooth device is properly connecting to your Linux box, </span><span style="text-align: center;">but not that audio is properly being transmitted.</span><span style="text-align: center;"> </span><br />
<span style="text-align: center;"><br /></span>
<span style="text-align: center;"><span style="font-size: large;">A Lesson in Linux Audio</span></span><br />
<span style="text-align: center;">Linux Audio is notirously painful to configure. There are 3 sound systems that distributions tend to use. These are Alsa, PulseAudio, and OSS, which really isn't used all that much.</span><br />
<span style="text-align: center;"><br /></span>
<div style="text-align: left;">
<span style="font-size: large;">How To fix</span></div>
<div style="text-align: left;">
Okay, so now you have to install a package called <b>pavucontrol</b>, which is short for Pulse Audio Volume Control. It's not installed by default on most Linux distributions because it provides some more advances facilities for managing your audio. Once it's installed, run "pavucontrol" from a terminal to open it.</div>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQrD1tzD0GQ99mmuwM37FBc4ZFJ3ijTjmgOi2KEYPLiFNEkNJd8BNBvUr-AsgyKbQZL1_5QlWQM2rZOZGI121K6X8yyblpvs03Ku7iMHlaTMlAgViq7jMqfEIizM05G_pEmWIsH31OM7g/s1600/2016-07-01-124432_494x430_scrot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="278" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQrD1tzD0GQ99mmuwM37FBc4ZFJ3ijTjmgOi2KEYPLiFNEkNJd8BNBvUr-AsgyKbQZL1_5QlWQM2rZOZGI121K6X8yyblpvs03Ku7iMHlaTMlAgViq7jMqfEIizM05G_pEmWIsH31OM7g/s320/2016-07-01-124432_494x430_scrot.png" width="320" /></a></div>
<div style="text-align: left;">
First, make sure that the audio isn't muted on your headset here (either on the bar or the speaker mute button). You should have your channels locked together, and it should be a fallback. Now, if all of this is set up (it was for me), there is one last step you need to do to fix your audio.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
In the "configuration" tab at the top, go down to your headset. As misleading as it is, change your headset from either "Off" or "Headset head unit" to "High Fidelity Playback (A2DP Sink)"</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnYnsp7iV6voL-5O86WOoiVkkiW1-DOXEWUFIzVGWGbr7KFRv8oAphE2rCPVIP0fHTMtdVhM8BZPs5_h6v343yo9eS5fUFAkw7DP4jD1zbvuNqsqbMxMXoKMPGMZtoTRz6ADAWpKwUoZk/s1600/2016-07-01-124821_500x436_scrot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="279" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnYnsp7iV6voL-5O86WOoiVkkiW1-DOXEWUFIzVGWGbr7KFRv8oAphE2rCPVIP0fHTMtdVhM8BZPs5_h6v343yo9eS5fUFAkw7DP4jD1zbvuNqsqbMxMXoKMPGMZtoTRz6ADAWpKwUoZk/s320/2016-07-01-124821_500x436_scrot.png" width="320" /></a></div>
<div style="text-align: left;">
Now, after changing that, you should be good to go. If you're not, there is one last thing you can try.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Install <b>alsamixer</b> if you don't already have it and run it in a terminal. If you see "MM" at the bottom, hit "M" to unmute that channel, and use the up arrow to turn the volume of it all the way to 100%. If it's possibly reading your sound card wrong, you can use "F6" here to change that.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Good luck. Audio issues are a true pain to work through, and are seemingly impossible to fix. Hopefully these steps solve your audio problems as they did mine.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com17tag:blogger.com,1999:blog-2466616284663617777.post-43302957759090597292016-07-01T09:20:00.001-07:002016-07-01T09:20:56.810-07:00Installing Minecraft in Fedora 23 and 24Minecraft on Fedora can be a bit of a pain. You may even have experience working with .jar files, download Minecraft, and it still doesn't work! This post will explain why that is, and how to get the game installed on your computer. You'll be minin' and craftin' before you know it.<br />
<br />
Installing Minecraft is as easy as these steps:<br />
<br />
<br />
<ul>
<li>Download Minecraft</li>
<li>Install Java</li>
<li>Run</li>
</ul>
and has one optional step that I highly recommend<br />
<br />
<ul>
<li>Create a Desktop file</li>
</ul>
<br />
I've tried to put together a small script to do this for you. If it doesn't work, then follow along with the steps below and tell me which part is giving you trouble:<br />
<br />
<b>x86: </b><span style="background-color: #eeeeee;">wget "http://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.jar" -O ~/Downloads/Minecraft.jar; wget "http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jre-8u91-linux-i586.rpm" -O ~/Downloads/jre.rpm; sudo dnf install ~/Downloads/jre.rpm; wget "https://raw.githubusercontent.com/natepisarski/tutpi-sources/master/install-minecraft-fedora-23-24/Minecraft.desktop" -O ~/Downloads/Minecraft.desktop; sudo cp ~/Downloads/Minecraft.desktop /usr/share/applications/;wget "https://github.com/natepisarski/tutpi-sources/blob/master/install-minecraft-fedora-23-24/minecraft.png" -O ~/Downloads/minecraft.png</span><br />
<br />
<b>x86_64: </b><span style="background-color: #eeeeee;">wget "http://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.jar" -O ~/Downloads/Minecraft.jar; wget "http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jre-8u91-linux-x64.rpm" -O ~/Downloads/jre.rpm; sudo dnf install ~/Downloads/jre.rpm; wget "https://raw.githubusercontent.com/natepisarski/tutpi-sources/master/install-minecraft-fedora-23-24/Minecraft.desktop" -O ~/Downloads/Minecraft.desktop; sudo cp ~/Downloads/Minecraft.desktop /usr/share/applications/; wget "https://github.com/natepisarski/tutpi-sources/blob/master/install-minecraft-fedora-23-24/minecraft.png" -O ~/Downloads/minecraft.png</span><br />
<div>
<br /></div>
<span style="background-color: white;">After using these scripts, you should be able to play Minecraft by typing:</span><br />
<br class="Apple-interchange-newline" />
<span style="background-color: #eeeeee;">cd /usr/java/jre*; bin/java -jar ~/Downloads/Minecraft.jar </span><br />
<span style="background-color: #eeeeee;"><br /></span>
<span style="background-color: white;">at the terminal, or by rebooting and selecting "Minecraft" from your applications menu.</span><br />
<span style="background-color: white;"><br /></span>
<span style="font-size: large;">Download Minecraft</span><br />
This is probably the easiest step. Assuming you already have a Minecraft account, you can just download the game to get started with this command:<br />
<br />
<span style="background-color: #eeeeee;">wget "http://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.jar" -O ~/Downloads/Minecraft.jar </span><br />
This will put Minecraft inside of your "Downloads" folder in your home directory.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsaOdWbIBCxC7FSWsh3jxAnB1TrNKI0LbbnocvVWfQ6LF6CT4cP4RhR_045mf_Dq5MBtMmeumBPgT9qXjtF-F7R6zLeobb5j95QVm7xvcQcvZQBxdJtVJ93_-3uP7rmIM6d7j3ReWUmPc/s1600/Screenshot+from+2016-07-01+11-14-57.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsaOdWbIBCxC7FSWsh3jxAnB1TrNKI0LbbnocvVWfQ6LF6CT4cP4RhR_045mf_Dq5MBtMmeumBPgT9qXjtF-F7R6zLeobb5j95QVm7xvcQcvZQBxdJtVJ93_-3uP7rmIM6d7j3ReWUmPc/s320/Screenshot+from+2016-07-01+11-14-57.png" width="320" /></a></div>
<br />
<span style="font-size: large;">Download and Install Java</span><br />
Thankfully, because you run Fedora, Java provides a <b>.rpm</b> file for their JRE. This makes the installation far easier.<br />
<br />
<span style="font-size: x-small;">Also note that we <u style="font-weight: bold;">must</u> install Oracle's propriety JRE in order to run Minecraft, as there is (at least at the time of writing) an incompatbility between swing on OpenJDK and the official JDK.</span><br />
<br />
x86 (32-bit) system users can download their rpm from <a href="http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jre-8u91-linux-i586.rpm">this</a> link.<br />
x86_64 (64-bit) system users can download their rpm from <a href="http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jre-8u91-linux-x64.rpm">this</a> link.<br />
<br />
By downloading either file you are accepting Oracle's <a href="http://www.oracle.com/technetwork/java/javase/terms/license/index.html">license</a>. If those links don't work or are outdated, visit the website directly here: <a href="http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html">http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html</a><br />
<br />
<span style="font-size: large;">Find where Java was Installed and Run Minecraft</span><br />
The <b>.rpm</b> will automatically install Java. But... where. If you tried to do "java -jar Minecraft.jar" right now it would fail still, because it's still using the OpenJDK version of java. In order to launch Minecraft, you have to do this:<br />
<br />
<span style="background-color: #eeeeee;">cd /usr/java/jre*; bin/java -jar ~/Downloads/Minecraft.jar </span><br />
<span style="background-color: #eeeeee;"><br /></span>
<span style="background-color: white;">because Java is installed in <b>/usr/java/</b> in a directory name that corresponds to its version, which is bound to change. If you're comfortable with leaving it at this, you can. However, having to use that command every time you want to play Minecraft is a bit cumbersome, so we're going to make a .desktop file to do it.</span><br />
<span style="background-color: white;"><br /></span>
<span style="font-size: large;"><span style="background-color: white;">Make the Desktop File</span></span><br />
<span style="background-color: white;">.desktop files are what control launching desktop applications on Linux. When you see "Files" and a picture of a filing cabinet that launches nautilus, for instance, that's the result of a Desktop File. We can make our own desktop file to launch Minecraft with that code above. One caveat is that Desktop files aren't run like normal terminal commands, so we have to give our command up there a shell, since it has it change its working directory.</span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;">The content of the Minecraft.desktop file should be as follows: </span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: #eeeeee;">#!/usr/bin/env xdg-open</span><br />
<span style="background-color: #eeeeee;"><br /></span>
<span style="background-color: #eeeeee;">[Desktop Entry]</span><br />
<span style="background-color: #eeeeee;">Version=1.0</span><br />
<span style="background-color: #eeeeee;">Terminal=false</span><br />
<span style="background-color: #eeeeee;">Type=Application</span><br />
<span style="background-color: #eeeeee;">Name=Minecraft</span><br />
<span style="background-color: #eeeeee;">Exec=bash -c "cd /usr/java/jre*; bin/java -jar ~/Downloads/Minecraft.jar"</span><br />
<span style="background-color: #eeeeee;">Icon=~/Downloads/minecraft.png</span><br />
<span style="background-color: #eeeeee;">NoDisplay=true</span><br />
<br />
<span style="background-color: #eeeeee;">Name[en_US]=Minecraft</span><br />
<div>
<br /></div>
<div>
<span style="background-color: white;">which you can write in almost any text editor. This expects there to be an icon for Minecraft in your Downloads folder, but it will launch the game even if there's not.</span></div>
<div>
<span style="background-color: white;"><br /></span></div>
<div>
<span style="background-color: white;">Great! Now...</span></div>
<div>
<span style="background-color: white;"><br /></span></div>
<div>
<span style="background-color: white;"><span style="font-size: large;">Install the Desktop File</span></span><br />
<span style="background-color: white;">Move the file into <b>/usr/share/Applications/</b>. This will install the Minecraft launcher system-wide. It may take a reboot for this to actually work.</span></div>
<div>
<br />
And you're ready to roll! Have fun</div>
shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com2tag:blogger.com,1999:blog-2466616284663617777.post-21027743888382929992016-07-01T08:13:00.000-07:002016-07-01T08:13:03.999-07:00How To: Set up timestamps in Emacs DocumentsThis will be a pretty straightforward how-to guide on how to implement timestamping in Emacs. This will insert the time directly into the document, under the cursor, so if you want something fancier than unfortunately the GNU Emacs Documentation will have to hold you over.<br />
<br />
<span style="font-size: large;">The Command</span><br />
The command to actually insert the time into the document is this:<br />
<span style="background-color: #eeeeee;"><br /></span>
<span style="background-color: #eeeeee;">(insert (current-time-string))</span><br />
<span style="background-color: #eeeeee;"><br /></span>
<span style="background-color: white; font-size: large;">The Keybind</span><br />
<span style="background-color: white;">Now, if it doesn't exactly sound like your cup of tea to have to copy-and-paste that Lisp command every time you want to insert the timestamp, open up your .emacs file (or wherever you store your Emacs configuration file. If you don't have one, you can just create a file called ".emacs" in your home directory).</span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;">Insert this line:</span><br />
<span style="background-color: #eeeeee;"><br /></span>
<span style="background-color: #eeeeee;">(global-set-key (kbd "C-c C-c") (lambda () (interactive) (insert (current-time-string)))</span><br />
<span style="background-color: #eeeeee;"><br /></span>
<span style="background-color: white;">This tells Emacs that whenever you press Control-C, Control-C, it should insert the default time string (which looks like: </span><br />
<br />
<b>Fri Jul 1 10:57:35 2016</b><br />
<b><br /></b>
Note the (lambda (interactive()). This is only required because global-set-key expects interactive commands.<br />
<br />
<span style="font-size: large;">Modifying the Time</span><br />
Obviously, having a string that long doesn't work for everybody. Maybe you don't want the day of the week to show, or you only care about the year, etc. Luckily, Emacs comes with a command called <b>format-time-string</b> which allows us to control what kind of format the date will be output as. So, let's change up that <b>(current-time-string)</b>!<br />
<br />
<span style="background-color: #eeeeee;">(global-set-key (kbd "C-c C-c") (lambda () (interactive) (insert (format-time-string "%I:%M:%S%p"))))</span><br />
<br />
This will give you just the 12-hour time (i.e "10:57:35pm"). To see a list of all the options you can use with format-time-string, either run <b>man strftime</b> (on linux) or go to <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Time-Parsing.html">The GNU Documentation</a> on the function.<br />
<br />
<span style="font-size: large;">Only in Certain Modes</span><br />
Now, in my case, I only want time-stamping to be enabled when I'm in Markdown Mode. The code (still using the 12-hour time format) would be this:<br />
<br />
<span style="background-color: #eeeeee;">(add-hook 'markdown-mode-hook (global-set-key (kbd "C-c C-c") (lambda () (interactive) (insert (format-time-string "%I:%M:%S%p")))))</span><br />
<span style="background-color: #eeeeee;"><br /></span>
<span style="background-color: white;">There are a <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Hooks.html">ton</a> of hooks out of the box, and even more in the thousands of MELPA packages, so you can modify <b>'markdown-mode-hook</b> to be anything.</span>shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0tag:blogger.com,1999:blog-2466616284663617777.post-88993378976681452722016-06-30T21:29:00.002-07:002016-06-30T21:29:20.674-07:00Deploying a ASP.NET MVC Application on MonoEver tried to deploy an ASP.NET MVC application before? Well, it's the bee's knees... on Windows, where most Visual Studio project types are first class citizens of the ecosystem (sorry, F#). However, things get a tad trickier on Linux / Mono, so let's run through the very basics of setting up an environment like this.<br />
<br />
This post will not cover advanced topics, such as setting up an SSL certificate or linking with a database. It will just get the barebones ASP.NET server deployed. Note, however, that there are better ways to deploy an ASP.NET MVC service than what this post describes (through <a href="http://www.mono-project.com/docs/web/fastcgi/">fastcgi</a> or <a href="http://www.mono-project.com/docs/web/mod_mono/">mod_mono</a>), so if you're concerned about the RIGHT way of doing things rather than the FAST way of doing things, follow that link.<br />
<br />
<span style="font-size: large;">Structure - Skip if you have a project</span><br />
Let's make ourselves an ASP.NET MVC application in Monodevelop. If you don't already have monodevelop, you'll need to install the following packages:<br />
<br />
<ul>
<li>monodevelop</li>
<li>xsp</li>
<li>mono-devel</li>
</ul>
from your distribution's repository. If some of those aren't found, it may be okay, as both tend to be bundled with monodevelop itself. Now, make an ASP.NET MVC project with Razor<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJZGgjepELRI_YNiF8YsGtvaf4-FoquFni2wYg2Do3p5BYZFLNX6lG5mnQbqLZTpdg0oknmyHyU1eajlbbuO4LgqM4N-4dqJg-nyXUAeVM9Qv1xIHa3SP8s4E35Yyl99-yVttzXijUI8c/s1600/Screenshot+from+2016-07-01+00-15-04.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJZGgjepELRI_YNiF8YsGtvaf4-FoquFni2wYg2Do3p5BYZFLNX6lG5mnQbqLZTpdg0oknmyHyU1eajlbbuO4LgqM4N-4dqJg-nyXUAeVM9Qv1xIHa3SP8s4E35Yyl99-yVttzXijUI8c/s320/Screenshot+from+2016-07-01+00-15-04.png" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw7seY9d5MTN4MQOnu2FxCqK21XEHWyMKfxQ723eUJkiOSbPxQrJgsRiZeVDbya6jhDwZlU6rLrjpP1WzA-NMwz4RL-F6eGq0BZT5QDs__FegUEUjznXLIyLhn-ic30Om5I-cx3IQdAEg/s1600/Screenshot+from+2016-07-01+00-15-17.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw7seY9d5MTN4MQOnu2FxCqK21XEHWyMKfxQ723eUJkiOSbPxQrJgsRiZeVDbya6jhDwZlU6rLrjpP1WzA-NMwz4RL-F6eGq0BZT5QDs__FegUEUjznXLIyLhn-ic30Om5I-cx3IQdAEg/s320/Screenshot+from+2016-07-01+00-15-17.png" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
this should create an ASP.NET MVC project that's ready for deploying.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Compiling</span></div>
<div class="separator" style="clear: both; text-align: left;">
Now, it's time to compile the project. This is where a program from <b>mono-devel</b> comes into play. <b>xbuild</b>, an implementation of <b>msbuild</b> (<a href="https://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx">link</a>) is what will generate what the web server runs. The binaries are generated from the .sln or .csproj file itself.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
So, open up a terminal and go to the project root, where your project file is.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipe3ORDoQGZpf4vnWEkqG3ejpTKH8WMFCZMhRVXcHaOTJjye1r7hxR2bqUCk5-BmxILBbKTNzSIp076hVnsdgvOo2pY0BNhZSKnfWLpWhfOBK65zxZjwv4t61TNXNMLdqjSkpzOWG1QIk/s1600/Screenshot+from+2016-07-01+00-19-42.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="67" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipe3ORDoQGZpf4vnWEkqG3ejpTKH8WMFCZMhRVXcHaOTJjye1r7hxR2bqUCk5-BmxILBbKTNzSIp076hVnsdgvOo2pY0BNhZSKnfWLpWhfOBK65zxZjwv4t61TNXNMLdqjSkpzOWG1QIk/s320/Screenshot+from+2016-07-01+00-19-42.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
Then issue the "xbuild" command on your file. This will build all targets for the project, which are Debug and Release by default in Monodevelop</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: #eeeeee;">xbuild {file.sln}</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrzXXbOWdB7eUcZu0JWTfGZhh0DGwtRvxa04x0jE-Z_itiOM_PvPEnIsUkz2AmTIJdNGHJ0wyogzJE2OBS3K6w0jnyT1DqlNyOZFgdl_yxqFKNlgRKqKtXkaN34kswqngeBPiWAXqazHI/s1600/Screenshot+from+2016-07-01+00-20-19.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="181" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrzXXbOWdB7eUcZu0JWTfGZhh0DGwtRvxa04x0jE-Z_itiOM_PvPEnIsUkz2AmTIJdNGHJ0wyogzJE2OBS3K6w0jnyT1DqlNyOZFgdl_yxqFKNlgRKqKtXkaN34kswqngeBPiWAXqazHI/s320/Screenshot+from+2016-07-01+00-20-19.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
Wonderful! If everything in your project passes, you have successfully built your ASP.NET MVC application</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Deploying</span></div>
<div class="separator" style="clear: both; text-align: left;">
Now, here are where the tough decisions are made. If you are truly deploying a production service, you should do the following things:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<ul>
<li>Secure a webserver, preferably a dedicated virtual machine</li>
<li>Generate SSL certificates / other cryptographic keys</li>
<li>Create a user for running your service</li>
<li>Install the fastcgi-mono or mod_mono (apache) modules and run your service from Apache</li>
</ul>
<br /><br />
<div class="separator" style="clear: both; text-align: left;">
However, the quick-n'-dirty way I do it is with <b>xsp4</b>. <b>xsp</b> is yet another pet project of Mono's, that aims to be a fast ASP.NET web server for development. However, there is nothing that says you can't use it in production. It allows SSL certificates, variable ports, etc. so you won't find yourself missing <i>too</i> many features from Apache.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Running xsp4 is dead simple. Go to the build directory (the one under your project root) and run "</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: #eeeeee;">xsp4 --port 80"</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
if all goes well with this, you should have a full-fledged ASP.NET MVC 4 application deployed under Linux, and available on the standard http port. This is, of course, the unsecure, bare-bones deployment with xsp4. But it's a good starting point. To find out how to make xsp4 handle errors, set up your certificates, etc. issue the command </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: #eeeeee;">xsp4 --help</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: #eeeeee;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white;">Hope you found this useful!</span></div>
<br />shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com9tag:blogger.com,1999:blog-2466616284663617777.post-63276615064307136422016-06-29T07:27:00.001-07:002016-06-29T07:27:06.242-07:00Using SQLite server with C# / Mono on LinuxIf you've arrived on this post, it means that you're using Mono on Linux and attempting to use SQLite, and having a bit of difficulty. That's understandable. This is not a tutorial on SQL / Mono / Entity or anything of the sort. This will get a barebones implementation of a server working with mono.<br />
<br />
<span style="font-size: large;">The Problem</span><br />
<span style="font-size: large;"><span style="font-size: small;">The problem is that Mono comes with <b>Mono.Data.Sqlite</b>.</span> </span>Yet, if you're looking for information on using SQLite in C#, you will be directed to use <b>System.Data.Sqlite</b>, which is included in the nuget library. You can add this using Xamarin's tools successfully. Intellisense should work, and most functions in System.Data.Sqlite should work as well... except for one: <b>SQLiteConnection</b>, which is used to connect to the database.<br />
<br />
I'm not 100% positive on the nature of the problem, as it stands, in mono right now. I can narrow it down to (at least in my case) some kerfuffle regarding <b>sqlite.interop.dll</b> not playing nicely with my architecture of choice (x86_64).<br />
<br />
<span style="font-size: large;">The Fix</span><br />
<span style="font-size: large;"><span style="font-size: small;">The best fix for this is to... use <b>Mono.Data.Sqlite</b>. However, this has some downsides.</span></span><br />
<ul>
<li><span style="font-size: large;"><span style="font-size: small;">Using a Mono library breaks compatibility with .NET... ouch.</span></span></li>
<li><span style="font-size: large;"><span style="font-size: small;">Mono.Data.Sqlite, for whatever reason, is not a drop-in replacement of System.Data.Sqlite.</span></span></li>
</ul>
<span style="font-size: large;"><span style="font-size: small;">with these things in mind, let's do it.</span></span><br />
<br />
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: #f3f3f3;"><span>using System;</span></span></span></span><br />
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: #f3f3f3;"><span>using Mono.Data.Sqlite;</span></span></span></span><br />
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: #f3f3f3;"><span>namespace SQLITETEST {</span></span></span></span><br />
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: #f3f3f3;"><span> class MainClass {</span></span></span></span><br />
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: #f3f3f3;"><span> SqliteConnection db = new SqliteConnection("Data Source={filename.sqlite};Version=3;");</span></span></span></span><br />
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: #f3f3f3;"><span> db.Open();</span></span></span></span><br />
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: #f3f3f3;"><span> SqliteDataReader reader = new SqliteCommand("SELECT x FROM y WHERE z = zz;", db).ExecuteReader();</span></span></span></span><br />
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: #f3f3f3;"><span> while (reader.Read()) { Console.WriteLine(reader.GetString(0));}</span></span></span></span><br />
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: #f3f3f3;"><span><br /></span></span></span></span>
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: #f3f3f3;"><span><span style="background-color: white;"><span>and there you go. This code will connect to a database {filename}, run a query, and return the results. If you have experience with <b>System.Data.Sqlite</b>, you should notice that the SYNTAX of <b>Mono.Data.Sqlite</b> doesn't differ from it too much... but the spelling does. <b>System.Data.Sqlite</b> prefers to use classes spelled as "SQLiteDataReader, SQLiteConnection", etc. while Mono uses "SqliteDataReader"... </span></span></span></span></span></span><br />
<br />
<span style="font-size: large;"><span style="font-size: small;"><span style="background-color: #f3f3f3;"><span><span style="background-color: white;"><span>While this seemingly unnecessary difference is annoying, it's negligible. Enjoy kludging through Sqlite and Mono further!</span></span> </span></span></span></span>shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com2tag:blogger.com,1999:blog-2466616284663617777.post-5033550616172688802014-06-28T10:24:00.004-07:002016-07-30T09:36:52.259-07:00Rust note 6: Checking to see if a file exists in Rust<span style="background-color: #cccccc;">use std::path;</span><br />
<span style="background-color: #cccccc;">fn alreadyExists(items: Vec<Path>, quer: &str) -> bool {<br /> items.iter().any(|nms: &Path| -> (bool) {nms == &Path::new(quer)})<br />}</span><br />
<br />
This searches over the items iterator, checking each path against a filename, and returns "true" if the file exists in the directory, or "false" otherwise. It does this by way of a higher-order function (.any) that takes individual &Path's and checking them against a temporary reference to a Path that has the same file name as what is being searched.<br />
<br />
This approach is a tad bit intensive, since you will be putting a lot of temporary objects on the heap. However, the overall net effect on memory should be 0 since they all fall out of scope during each iteration of the iterator.shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0tag:blogger.com,1999:blog-2466616284663617777.post-47216849012579938302014-06-28T09:18:00.000-07:002014-06-28T09:18:12.506-07:00Rust Note 5: Keyboard input in RustRustlang is all about its functions. You barely have to run your program to make sure it works, and when you do, you write <a href="http://profectium.blogspot.com/2014/06/rust-note-4-rust-unit-tests.html">unit tests</a> for them. But, what about good old days of taking keyboard input and faffing about without end in your program? Here's how to bring that back in Rust.<br />
<br />
<b>The Program</b><br />
This program will take input and parrot it back to you. It's as simple as simple gets.<br />
<b> </b><br />
<b><span style="background-color: #999999;">use std::io;<br /><br />fn main(){<br /> print!("Input: ");<br /> println!("{}", io::stdin().read_line().unwrap());<br />}</span><br /> </b><br />
io::stdin() returns a <a href="http://doc.rust-lang.org/std/io/struct.BufferedReader.html">BufferedReader</a> on stdio (the input stream).<b> </b>read_line() returns an IoResult (just used for handling some errors) that .unwrap() turns into a normal string. That is then printed by the println! macro.<br />
<br />
Just be careful with .unwrap(). Part of Rust's power is being able to match against errors, and you lose that with .unwrap().<br />
<b> </b>shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0tag:blogger.com,1999:blog-2466616284663617777.post-75420560800360996912014-06-26T16:01:00.002-07:002014-06-26T16:04:13.824-07:00Rust note 4: Rust unit testsUnit tests are a crucial part of "real world" development. Manually testing code in some kind of REPL (which rust no longer has) is time-consuming and cannot be verified across distributions of your code. Luckily, rust provides unit testing right inside of its compiler, so you don't even need a third-party solution to bolster your code. Here's how to do it.<br />
<br />
<b>The assert! Macro</b><br />
assert! is a simple concept that can be used in complex ways. It tests to see if a boolean is true, and, if it is, does nothing. Otherwise, it will call the fail!() macro, causing the program to terminate.<br />
<b> </b><br />
<b>The test function</b><br />
So, before we can test anything we need functions.<br />
<b> </b><br />
<span style="background-color: #999999;">fn add_one(x: int) -> int { x + 1 }</span><br />
<span style="background-color: #999999;">fn subtract_one(x: int) -> int { x - 1}</span><br />
<br />
<br />
Obviously, add_one(1) will be 2. And subtract_one(1) is zero. So, we put these <b>assertions</b> in a function called "test", which takes no arguments and returns nothing.<br />
<br />
<span style="background-color: #999999;">#[test]</span><br />
<span style="background-color: #999999;">fn test(){</span><br />
<span style="background-color: #999999;"> assert!(add_one(1) == 2, "It's all gone wrong!");</span><br />
<span style="background-color: #999999;"> assert!(subtract_one(1) == 0);</span><br />
<span style="background-color: #999999;"> assert!(add_one(subtract_one(1)) == 1);</span><br />
<span style="background-color: #999999;">}</span><br />
<br />
<span style="background-color: #999999;"><span style="background-color: white;">The test pragma ("#[test]") will tell rustc that this is a test. The function that tests the code can be named anything, as long as it returns nothing and takes no arguments. The tests inside of the function are just standard boolean expressions, and an optional message for if the code fails ("It's all gone wrong!"). Now, compile put this in a file and compile it with <span style="background-color: #999999;">rustc --test file.rs. <span style="background-color: white;"> </span></span></span></span><br />
<br />
<span style="background-color: #999999;"><span style="background-color: white;"><span style="background-color: #999999;"><span style="background-color: white;">Run the resulting executable. It should say "test result: ok. 1 passed, 0 failed; 0 ignored; 0 measured". The number of passed tests refers to how many #[test] pragmas are found. There can be a variable number of tests, so try to group up tests of a related domain under a single function. </span></span></span></span><br />
<br />
<span style="background-color: #999999;"><span style="background-color: white;"><span style="background-color: #999999;"><span style="background-color: white;">Just out of curiosity, what would happen if you made the test fail? Well, it's not pretty. </span></span></span></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://i.imgur.com/thhoYH0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://i.imgur.com/thhoYH0.png" height="122" width="320" /></a></div>
shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0tag:blogger.com,1999:blog-2466616284663617777.post-79425140892054656722014-06-26T15:48:00.003-07:002014-06-26T15:48:59.605-07:00Rust Note 3: For loops in RustRust is a very progressive language. It tries to not make the same mistake that D made, and include parts of the language just because its predecessors had them. One such removal is the <b>for loop</b>.<br />
<br />
For the uninformed, a for loop syntax in most languages is as such: for(declaration; guard; statement). An example:<br />
<br />
<span style="background-color: #999999;">for(int x = 0; x < 100; x++){;} </span><br />
<br />
This for loop will do nothing 100 times. But, Rust doesn't have a for loop? How can you do an equal amount of nothing? The answer is to use the <b>range()</b> function of the standard library. Range() is an <b>iterator</b>, meaning that the rust version of the for loop can act over it. You can generate a list of numbers with <b>range(<i>lowerBounds, higherBounds)</i></b> and iterate over it. Here's the translation of that loop from above:<br />
<br />
<span style="background-color: #999999;">for x in range (0, 100){ }</span><br />
<br />
Splendid! You're doing nothing just as efficiently as in a traditional language. However, what if you want to do something other than increment x by one each time? Well, you're in luck. You could either<br />
<ul>
<li>Implement the iterator trait for the type of data you're working on</li>
<li>Do it the lazy way</li>
</ul>
Lazy sounds easy, so here's how to get every third number in a for loop in rust.<br />
<br />
<span style="background-color: #999999;">let mut x: int = 0;</span><br />
<span style="background-color: #999999;">while x < 100{</span><br />
<span style="background-color: #999999;"> // Awesome stuff here </span><br />
<span style="background-color: #999999;"> x = x + 3</span><span style="background-color: #999999;"><br /></span><br />
<span style="background-color: #999999;">} </span>shoehttp://www.blogger.com/profile/11337246456578874002noreply@blogger.com0