Sunday, December 15, 2013

How To: Set up Hotmail in Mutt

I like to think of Microsoft's email infrastructure as a bad bowl of spaghetti. Ever since they came out with outlook, live, and hotmail, doing anything with the server configuration is a pain. When using thunderbird, which configures your mail for you automatically, it's fine, but with a program like mutt things get a bit harder. This is how to set up hotmail and mutt.

The important parts of any mutt configuration file are imap_user, imap_pass, smtp_url, smtp_pass, from, and realname. Here is what that section of the file should look like for you:

 set imap_user = "YOUR_EMAIL@hotmail.com"
 set imap_pass = "YOUR_PASSWORD"
 set smtp_url = "smtp://YOUR_EMAIL@hotmail.com@smtp.live.com:587/"
 set smtp_pass = "YOUR_PASSWORD"
 set from = "YOUR_EMAIL@hotmail.com"
 set realname = "FIRST LAST"
 set ssl_force_tls = yes

Note, smtp_url has two "@" symbols. Without this, sending mail will fail with an SASL error. For the curious, the rest of my configuration file is below:

 # The editor to edit the plaintext of the email in
 set editor = "emacs"

 set folder = "imaps://imap-mail.outlook.com:993"
 set spoolfile = "+INBOX"
 set imap_check_subscribed
 set hostname = hotmail.com
 set mail_check = 25
 set timeout = 300
 set imap_keepalive = 300
 set postponed = "+[hotmail]/Drafts"
 set record = "+[hotmail]/Sent Mail"
 set header_cache=~/.mutt/cache/headers
 set message_cachedir=~/.mutt/cache/bodies
 set certificate_file=~/.mutt/certificates
 set move = no
 set include
 set sort = 'threads'
 set sort_aux = 'reverse-last-date-received'
 set auto_tag = yes
 ignore "Authentication-Results:"
 ignore "DomainKey-Signature:"
 ignore "DKIM-Signature:"
 hdr_order Date From To Cc
 alternative_order text/plain text/html *
 auto_view text/html
 bind editor <Tab> complete-query
 bind editor ^T complete
 bind editor <space> noop

 # Gmail-style keyboard shortcuts
 macro index,pager y "<enter-command>unset trash\n <delete-message>" "Gmail archive message"
 macro index,pager d "<enter-command>set trash=\"imaps://imap.googlemail.com/[GMail]/Bin\"\n <delete-message>" "Gmail delete message"
 macro index,pager gi "<change-folder>=INBOX<enter>" "Go to inbox"
 macro index,pager ga "<change-folder>=[Gmail]/All Mail<enter>" "Go to all mail"
 macro index,pager gs "<change-folder>=[Gmail]/Starred<enter>" "Go to starred messages"
 macro index,pager gd "<change-folder>=[Gmail]/Drafts<enter>" "Go to drafts"

Friday, December 6, 2013

Looping in Haskell

When I first started out with Haskell, some things were made very clear: it was a pure language, it was expressive, and it told what data was, not what it did. However, coming from imperative languages like Java and C, I found myself wanting to know how to loop in Haskell. This was a basic want, because looping is one of the big concepts in programming those languages (along with conditionals and blocking). So, here are some correct ways to "loop" in Haskell, using higher-order functions and recursion.


Tail Call Recursion
Tail Call Recursion is a particularly efficient method of traversing data. The basic structure of a tail-recursive function is:

  1. Check the base-case
  2. Perform some action
  3. Set up the tail call.
The base case is what happens when you no longer want to recurse. If you're moving over a list of Ints, adding 1 to everything, this could be when the list is [] (empty).

In this case, the action would be adding one to a value, and appending it to the next call of the function.

The tail-call would then be the same function, but with the head of the list cut off.

The add-one-to-all numbers function would look something like this:

add-one-to-all :: [Int] -> [Int]
add-one-to-all [] = []
add-one-to-all (x:xs) = 1 + x : add-one-to-all xs

Here, when the list pattern matches [] (an empty list), an empty list is returned. Only when this happens will the function "snap back", collecting the other values from the list.

Higher-Order Functions
The entire point of a higher-order function is to be able to pass functions as parameters to other functions, or to return them from functions. In traversing a list, for instance, you could make a function that takes a function and a list, and then apply that with a function that adds one to a number.

traverse :: (a -> b) -> [a] -> [b]
traverse _ [] = []
traverse f (x:xs) = f x : traverse xs

add-one :: Int -> Int
add-one x = x + 1

add-one-to-all :: [Int] -> [Int]
add-one-to-all x = traverse add-one x

Here, you can see that the function "f" of traverse (type: (a -> b)) is applied recursively to a list. a and b are just type parameters, which are helpful for generic abstractions like this. Then, add-one is defined, and finally mapped over the list in add-one-to-all. The function "traverse" actually already exists in Prelude as the function map.

A bit extra
Haskell does something called currying, which allows the partial application of functions. Discussion on currying is outside the scope of this simple tutorial, but here is a very small implementation of add-one-to-all

add-one-to-all :: [Int] -> [Int]
add-one-to-all = map (+1)

Tuesday, December 3, 2013

Take a Function as a parameter in D

D is an improvement over C++. However, because of the lack of documentation, you need to be studious to use these improvements. One of the features that D introduces is an alias parameter, which we can use to make higher-order functions. If you're familiar with function pointers, these can be used as well, however, there is an alternative in D called delegates.

Without further adieu, here is an implementation of map, a function that takes another function and applies it to an array.

T[] map(alias func, T)(T[] data}{
if(data.length == 1) return func(data[0]);
else return [func(data[0])] ~ map!(func,T)(data[1..$]);
}

The noteworthy chunk of this code is "(alias func, T)". This is a declaration to "capture" an alias and some type when the function is called, and to take and return a dynamic array of type T, whatever type it is. The generic is important in this instance, since dynamic arrays are a container for any type.

Calling higher-order functions in D
To call this function, one would use "map!(name_of_function,type)(list)". Where name_of_function is either the name of a function or a function literal, and type is any type, user-defined or not. An example, done completely with literals:

Calling with literals
map!(((y) {return 10-y;}),int)([1,2,3,4,5,6,7,8,9]) // Returns [9,8,7,6,5,4,3,2,1]

Here, the syntax ((y) {return 10-y;}) is a function literal, called a lambda is some languages.

===tags(ignore)===
higher-order functions in D
D higher-order functions
D lambdas
lambda D

Sunday, December 1, 2013

Is D worth learning?

D has been intriguing to me lately. The language saw a surge in popularity in October of 2013, when Andrei Alexandrescu commit 5112 lines of D to Facebook's repository, and posted about it on the dlang forums. The forum users were ecstatic, going as far of calling this commit the "new age of D". It was hard to ignore that there was something big happening in the D world, so I've taken four days to learn the basics of the language. This is my experience, and my opinion on the practicality and roadmap for D and its future.

Why use D?
D is an attempted improvement over its competitor, C++. C++ was made to stop the C preprocessor hacks that were dividing the language in the same way that the Lisp world was fragmented before Common Lisp. Because of this, C++ became a hodge-podge language, where everything under the sun was thrown in in no particular order to please everyone. D is a re-imagining of C++, with some added features from Java and the functional paradigm.

D is fast: In a trivial program, D executed only .001 seconds slower than C++, while the source code was 30 bytes smaller.

D is coherent: Lambdas, a much-loved feature in C++, were an afterthought. In D, the syntax for lambdas integrates well with the language, and how it handles blocks and values. There are tons of examples of afterthoughts from C++ being first-class citizens of D.

D is compatible: Concepts from C++ carry over well into D. Generics, pointers, structs, classes, etc. It's all there. D can also call C or C++ code with an extern statement, or embed assembly.

D is innovative: Supercompilation, the complicated process that D uses to compile itself, introduces some interesting features. Alias types that refer to any named D object (even functions) can be passed in to other functions as parameters, or instantiated. This, combined with mixins (the ability to turn any string known at compile-time into executable D code) gives the user levels of customization only rivaled by Template Haskell or Lisp.

What drawbacks are there to D?
If you read the last section about D's merits, you may be thinking that it sounds too good to be true. There must be some drawbacks to D, or else everybody would already be using it! Well, it turns out that there are some downsides to the usage of D, but not the language itself.

In the past, the D community was fragmented between two standard libraries. This fragmentation hurt D. In D2.0, the latest revision of the language, massive changes were made to the language, making obsolete the already sparse amount of tutorials on D out there. That leads into the next downer with D.

D has mainly been an enthusiast language. There is little information out there to help if you hit a snag, so you'll often have to turn to human resources to get the help you need. The amount of tutorials is minuscule compared to languages like Java or C.

D is not hard to learn. It's a familiar language, and the book "The D Programming Language" is a wonderful introduction to D, as well as one of the best books about object oriented programming ever written (in my opinion, but this is shared by many, even outside of the D community). However, if your program doesn't compile, and just spits out some obscure dmd error message, you could be out of luck finding another user who has run into your exact problem. With D, you're on the "last frontier" of meaningful documentation.

Due to the previous lack of interest, there is also a lack of third-party support. An emacs mode exists, and so do plugins for popular IDE's, but I found both to be lacking. It took about 200 lines of lisp additions to d-mode.el before I felt D was ready to be used with my editor.

So, should I learn D?
If you are looking to venture into the world of Object Oriented programming, and want to use D as a way of doing that, absolutely! If you are already an object-oriented programmer, and want to expand your horizons, D will give you the power to do just that. If you are a project manager, looking to modularize dying C++ code, or catch the wave of new technology, go ahead.

The only people I would not recommend D to are very new programmers. For me, it took a background of functional programming and Object-oriented design to be able to read the tutorials and books that are out there. There's no "A gentle introduction to programming, using D" style book out there. If you are a new programmer and feel adventurous, you really won't go wrong with D. If you can learn it, you'll utilize it a hell of a lot more than Java as a first language.

Friday, October 11, 2013

How do I Hack?

"How do I hack? / How to hack?" is the question that spawns an interest in the field of computer science moreso than any other curiosity. The quest to find this information out almost always ends in failure. This "tutorial" is here to explain the difference between the different types of hacking, cracking techniques, and notes on the ethical implication of using "hacker" tools.
http://i7.photobucket.com/albums/y260/Alosel/Neo.jpg














What is Hacking?


Many people want to hack, but very few are sure what hacking truly is. At its core, hacking is changing something to work for your devices. Richard Stallman defines hacking as "Playful cleverness". What most people searching for hacking information truly want is information on cracking.

So then, what is cracking?
Cracking is the deliberate breaking of computer security for either a gain in information, or modification of an external source. When you hear of a database of passwords being dumped on pastebin, that's a crack. For most of the article, "hack" and "crack" will be used interchangeably, but there are many people who very vehemently reject the second definition, so that social hacking can remain pure.

The Meat - An overview of a hack
So, you've read about the differences between hacking and cracking, and you're sure of what you want to do. These are the steps that a hack could follow, but there are multiple types of attacks. We will talk about two here.

0-day route
Bugs are serious business in high-security situations. Most bugs are patched, but it wasn't always like this. Around the time of the advent of computers, knowledge was enough to "tear the internet to shreds", according to an Anonymous member of a hacking group. Bugs can take years to be fixed, and many are undetected, and lie waiting in the code to strike. These undetected bugs are called 0-days, because they have been in the "to-do" list of the bug fixers for exactly 0 days. By exploiting a 0-day, you are essentially stabbing your target in its back.

0-days can be bought on some tor marketplaces for a couple thousand, to upwards of a couple million dollars, depending on the severity of the exploit and the implications of hacking it. They can also be found by reading the source code of the project you are trying to attack. Parts of the code relating to textual sanitization or risky memory allocation will provide the best chances of finding a 0-day bug. Don't hold your hopes up for large projects; many layers of security exist in modern operating systems to protect against even undocumented bugs. You're more likely to overflow the stack than hack the Gibson, but shoot for the stars.



http://www.hackerscenter.com/images/stories/sql.png

 Injection
Injection is the method of passing a string through a preprocessor, causing unpredictable side-effects. I define preprocessor as being any "parser" that works to interpret text, which most large projects have. 

An example of Injection would be exploiting a naive service that uses Lisp to serve web pages. What if the function looked like: (defun serve (x) (if (contains x (to-string "webserve")) (webserve x)) (EXT:SHELL x))

For any reader who doesn't know Lisp, this basically says "If the string is a web request, send it to further parsing. Otherwise, execute it as a shell command." Now, the world isn't this simple, but there are some surprisingly simple SQL injection attacks that can dump databases of Usernames, Passwords, Credit card numbers, etc.

Finding your Target
So, now you know the basic way to attack somebody. But how do you find the necessary information on your target? How do you send them the information required to perform the attack?

Assuming you are running on a Linux machine, prepare it for penetration testing. Please note: What you are about to do is not illegal, but it is frowned upon by most internet service providers. To protect yourself from trouble, run these commands on "localhost".

Before you continue, install the "nmap" package.

sudo apt-get install nmap

Nmap can coerce information from networks. To see a list of everything nmap can do, run it on your box:  nmap -A localhost

This will return all of the information nmap  can find about your network. Among this information, all udp and tcp/ip jobs will be displayed. These are the pathways you will use one of the two methods discussed earlier to exploit. If your target is running http, it is a good chance. http is the most compromised protocol, because it is usually succeptible to injection attacks. Using the command line tool curl, you can send raw data to the web server. (You will need to for attacks; rarely will a web browser be enough to attack a target, unless their SQL validation is laughably bad).

If you want to send data to another port, you can use dd like so:

dd if=/dev/zero bs=9000 count=1000 > /dev/tcp/$target_host/$port
 
 
 
In Conclusion
Attacking targets on the internet today is much more complex than it used to be. Exploits require knowledge of tons of frameworks, languages, and protocols to be used properly, and these exploits are hard to find, expensive, and may even have protection against them. Hopefully this guide is enough to deter the common "I want to hack" crowd off of the subject, and onto the "righteous path" of programming. However, if this still sounds like it floats your boat, you may be looking for a bright career in IT security.

 
 


Sunday, September 1, 2013

How remove wasted space in Weechat nicks

The short of it is, this command (inside of weechat) will cause the aligning of nicks to stop. This is helpful for when you're in a channel where there's the one user with the incredibly long name.

/set weechat.look.prefix_align none    
Note that the bar (or whatever your prefix_suffix is in your weechat configuration file) will not be displayed.

If you decide that you do not want weechat to remain this way, the margin can be set back with

/set weechat.look.prefix_align "default"

I'm mainly writing this for my own future reference, but hope that anyone else looking to set their margins in weechat will find this advice helpful.

Saturday, August 31, 2013

Exporting Data in Haskell Modules

Welcome to a straightforward and short blog post on how to export data in Haskell. When we speak of data, we mean types defined with the data keyword, and not type synonyms or any other related term. Typeclasses can also be exported in this way.


Exporting Data
For this example, let's define a simple data type, called Bit. Bit can hold either On or Off. The simple data declaration of bit is: data Bit = On | Off . In order to export this from our module, say, Binary.hs, we can either choose individual type constructors to export, or export them all by using the name of the Type followed by parenthesis and two dots.

To export just On: module Binary(Bit(On)) where

To export all of Bit's constructors: module Binary(Bit(On,Off)) where

To export all of Bit's constructors implicitly (The easy way, and what you will do 95% of the time): module Binary(Bit(..)) where

The (..) is basically saying "Export all of Bit's type constructors", which is good practice if you're using this type anywhere else.

Exporting Typeclasses
The same is true for Typeclasses. In exporting Typeclasses, you can choose individual Methods to export, or export them all with (..)


Friday, August 30, 2013

Scratching the surface of Emacs

Setting Emacs Up
----
This is an in-depth look at GNU/Emacs version 24.0, written in Emacs 24.0, and posted with Emacs 24.0. If you can't tell from that line alone, there is quite a bit to this monster of a text editor. Before it's possible to dive into specifics, it's important to understand the infrastructure that Emacs provides for extensions and customization, to see why it became the phenomena that it did.






Emacs is written in C at its core. However, it's fully extensible in a language called Emacs Lisp, which is a dialect of Scheme Lisp. One of the only functions of Emacs' core is to interprest this Emacs Lisp (abbreviated elisp) to create the user's text editing experience.

On a higher-level, the editor's "Prelude" supports various Modes. If you're editing C code, you're in c-mode (this can be invoked with the editor command M-x c-mode, where M is Alt). If you're editing Lisp, you will be in lisp-mode, etc. All of these mods and features can be invoked with the M-x command, which is basically a run dialog for the commands Emacs has at its core.

All of these modes are supplied via Elisp files, and before we can truly get started with Emacs we will want a package manager to install these little Elisp files. By default, Emacs has M-x package-install, which is what we will keep using, but it's recommended that you hook it up to the MELPA repositories. To do this, follow this quick 3-step guide here: http://profectium.blogspot.com/2013/07/how-to-install-melpa-in-gnu-emacs.html

Now that you have Melpa installed, you'll have a much easier time installing modes and tools for the languages and workflow that you desire. The only extensions that I personally use are ghc-mod, haskell-mode, scion, and the Zenburn theme. Themes can be customized in your .emacs file, or from the graphical frontend from the Emacs menu bar (Options -> Customize Emacs -> Custom Themes).

Speaking of Options, before you even start editing text, it is a good time to run through and set all the options you want. Go through the options menu, tick what you like, untick what you don't, and when you're done click Options -> Save Options. I recommend Highlighting matching parenthesis, hiding the Tool Bar, showing Column, Lines, and Size, and using a monospace font.

Navigating Files
---
Unlike Vim, which is a modal editor, Emacs is always in editing mode. You can just start typing into a new file (which you make with C-x C-f, followed by the name of the file). This will write your text to the Emacs buffer, which can be flushed with C-x C-s. This will save the file you're working on. To navigate Emacs like you would vim, there are a certain set of keybindings every user should memorize (trust me, it's VERY hard at first, but more rewarding than the arrow keys once you get it down). The following key bindings are ordered by category. Remember that for the same modifier key, you don't have to lift your finger up.

C-p: Move one line up
C-n: Move one line down
C-a: Move to the beginning of the line
C-e: Move to the end of the line

M->: Move to the end of the buffer (Alt+Shift+Greater Than)
M-<: Move to the end of the buffer (Alt+Shift+Less Than)

C-f: Move one character forward
C-b: Move one character back

M-f: Move one word forward (a word is considered to start at punctuation or a space. Contiguous punctuation is considered one stop)
M-b: Move one word back

===Copying and Pasting
C-y: Copy selected text to the system clipboard
C-w: Cut
M-w: Paste
C-x h: Select all

===Killing and Deleting
C-d: Same as the delete key
C-k: Kill the line from the current point

===Editor functions
C-s: Search for text from the current point
C-g: Kill the M-x minibuffer


===Windows
C-x o: Switch between Windows
C-x 2: Horizontally split window, making one new one.
C-x 3: Vertically split window, making one new one.
C-x 0: Kill the current window, but do not close the buffer.

===Buffers (think of these like open files, or tabs in Notepad++)
C-x (Arrow key left or right): Next or Previous buffer
C-x b: Select buffer by name (like everything in Emacs, supports tab completion)
C-x k
---

With these keyboard shortcuts, you will have solid usage ability within the Emacs editor. It will take a while to gain the muscle memory to learn these commands, but they're much worth learning. Many IDE's and Web Browsers (namely firefox) have support for these Emacs keybindings. You can also set what each key binding does yourself if you have a bone to pick with one of the defaults. Every keyboard command can also be accessed through M-x. M-x Tab will show a list of every command in the Emacs editor, so pull up a chair, and experiment with some of the ones that sound interesting.

Emacs offers a lot more than this simple tutorial covers. This is meant to cover the simple commands used in editing a file. However, Emacs can be made to be your IRC client, Email client, Web Browser, Git interface, Media Player, terminal... Whatever you want it to be, really. There have even been experimental  window managers for Emacs. Some of these functions are installed by default under the Tools menu, and can be accessed by way of M-x.

P.S: For a persistant text editing session, Emacs can be run as a server.

And, for whatever reason, if you want to close Emacs you can type C-x C-c.


Here is a small look at Emac's power:



How to Overload functions in Haskell

Haskell is a difficult language to get coming from imperative languages. In languages like C++ and Java, we can say this:

addOne(int x){ return x + 1;}
addOne(double x) { return x + 1.0;}

Here, addOne works on different types, but is still the same function name. This is called Overloading, and it's somewhat more difficult to do in Haskell. In order to overload functions, you will need to define a Typeclass (With the FlexibleInstances Program) to work on the types you want. You can indeed get this to work on generics.

To get this to work, we'll use an example. Think of the function "after". If you said after "profectium" 'f' , you would expect to get "ectium". The type signature for this function is after :: (Eq a) => [a] -> a -> [a]. However, there are cases where you may supply a list to the second argument of after, like in this example: after "profectium" "pro" in order to get the same output. This last example could be useful for sanitation purposes, and to avoid false positives.

The typeclass to get these two functions work will be called "Continuous". Here is the class definition: 

class Continuous list part where
  after :: list -> part -> list


In both instances of after, you take two arguments and return a sublist of a greater argument. So in order to become part of class Continuous, they have to satisfy an implementation of this function. To make out lives easier, we can use generics instead of individual types in our instance declarations. Everything that is part of the Eq typeclass will automatically qualify for class Continuous.

Here are some helper functions, ignore them if you're unconcerned with implementation specifics: 
sub :: (Eq a) => [a] -> Int -> [a]
sub [] _ = []
sub x 0 = x
sub (x:xs) c = sub xs (c - 1)

pos :: (Eq a) => [a] -> a -> Int
pos [] _ = 0
pos (x:xs) c
  | x == c = 0
  | otherwise = 1 + pos xs c



These will be used to define the after functions. The two headers for after are:


instance (Eq a) => Continuous [a] a
instance (Eq a) => Continuous [a] [a]


This is barring the implementations. Because of the requirements pos (and, by proxy, sub) to have the Eq typeclass, we constrain it in the instance declaration. We also set this up to work with Generics. This will now work. The full file text for the After library is as follows: 

{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}

module Cookbook.Continuous(
sub :: (Eq a) => [a] -> Int -> [a]
sub [] _ = []
sub x 0 = x
sub (x:xs) c = sub xs (c - 1)

pos :: (Eq a) => [a] -> a -> Int
pos [] _ = 0
pos (x:xs) c
  | x == c = 0
  | otherwise = 1 + pos xs c


class Continuous list part where
  after :: list -> part -> list

instance (Eq a) => Continuous [a] a where
  after x c = sub x (1+(pos x c))

instance (Eq a) => Continuous [a] [a] where
  after [] _ = []
  after x c
    | take (length c) x == c = sub x ((length c))
    | otherwise = after (tail x) c


Note the language pragmas at the top. They are required for this to work. Pragmas just enable features of ghc that are turned off by default.
 

Tuesday, August 27, 2013

How to stop xmobar from going below windows

If you are like me, you tried to use xmobar but whenever you open a window it falls below it. Or, worse yet, xmobar forces itself on TOP of the Windows you're trying to open. There are ways to change the behavior of xmobar by editing some Haskell code, but most people aren't comfortable doing that. There is a perfectly acceptable alternative (even if it is a hack) that I read from a forum somewhere that I now forget. Whoever originally discovered this, I thank you.

Fixing Xmobar with Trayer
There is a program called Trayer that will properly reserve the space for xmobar. Trayer is originally a system tray, but we will not being using it that way (we won't see trayer at all, actually). Install trayer and Install xmobar, then open up a file called xmobarFix.sh

The text for the file should be as follows:

trayer --edge top --height 14 &
xmobar &


If your xmobar is configured to be on the bottom, then change --edge top to --edge bottom.

Make the file executable with chmod +x xmobarFix.sh 

Lastly, copy the file to /usr/bin with sudo mv xmobarFix.sh /usr/bin/xmobarF   

You can now properly launch xmobar by calling "xmobarF &" from the command line. 

My displaytrays:



 

 

How to change weather location in xmobar

Xmobar is the default bar of the xmonad Window Manager. It defaults to Glassgow, Scotland, as a little homage to the Glassgow Haskell Compiler, the compiler which xmonad was compiled in. However, for most users, Glassgow is not the city that we want to see displayed for our weather (if it is, you really did luck out with that one, huh?).

So, to change the location displayed, you just have to change four letters in you ~/.xmobarrc. You will see near the "commands" words "[ Run Weather "XXXX""

That four letter code is an ICAO code. The ICAO (International Civil Aviation Organization) provides information about where to look the weather up. Weather stations around the world use this as the standard for displaying local weather. Issue a google search for "ICAO [name of your town]" toget the code, and then replace the 4 letters between the quote with the ICAO you get. Restart xmobar, and the changes will take effect immediately.

To get my configuration, which defaults to Millville, New Jersey's airport, copy and paste this into a file in your home directory called .xmobarrc: (this is a good starting point if you don't have a file already, or you broke yours with hacks and tweaking)

Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
       , bgColor = "#0a0a0a"
       , fgColor = "#558e7d"
       , position = Bottom
       , lowerOnStart = False
       , commands = [ Run Weather "KMIV" ["-t","<station>: <tempF>F","-L","18","-H","25","--normal","green","--high","red","--low","lightblue"] 36000
                    , Run Network "eth0" ["-L","0","-H","32","--normal","green","--high","red"] 10
                    , Run Network "eth1" ["-L","0","-H","32","--normal","green","--high","red"] 10
                    , Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
                    , Run Memory ["-t","Mem: <usedratio>%"] 10
                    , Run Com "uname" ["-s","-r"] "" 36000
                    , Run Date "%a %b %_d %Y %H-> %l:%M:%S" "date" 10
                    ]
       , sepChar = "%"
       , alignSep = "}{"
       , template = "%cpu% | %memory% | %eth0% - %eth1% }{ <fc=#ee9a00>%date%</fc>| %KMIV% | %uname%"
       }      
  

It is also available as a raw file on my github. These commands will install that file (ASSUMING YOU ARE IN YOUR HOME DIRECTORY):

rm .xmobarrc
wget https://raw.github.com/dymatic/dotfiles/master/xmobar/.xmobarrc

If you aren't in your home directory, this will work.

rm ~/.xmobarrc
wget https://raw.github.com/dymatic/dotfiles/master/xmobar/.xmobarrc -o ~/.xmobarrc


How to get 12-hour clock in i3

At the beginning of our look into some neat tricks with i3, we are going to see how to get a 12 hour clock (with seconds) under i3. This assumes that you have the proper packages installed

  • i3-wm (sometimes called i3, either as a standalone or meta package)
  • i3status
  • i3bar
We are going to edit the global configuration file for i3status, a program that creates a status line for i3bar. The file is located over at /etc/i3status.conf, in case you know what you're doing and want to jump ahead of this article.

Open that file as root, and you should see something that looks like this:

Where it says time{format = "_"}, that is where the magic happens. The string supplied here is passed through a C function called strftime, which is the standard timestamp formatting tool across all Unix-like systems. The format they use with 24-hour clocks has the "%H" in the string. Find where it says "%H" inside of that string, and change it to "%l" to get the 12-hour time.

To see all of the options available, type "man strftime" at your terminal emulator.



 The format I use across all of my bars and time-tools is "%a %b %_d %Y %H-> %l:%M:%S", which comes across like this:

Friday, August 23, 2013

Higher-level scripting: bpp


If  you are like me, you make Bash or Zsh scripts to make your life easier with those small computing tasks. One of my favorite uses of Bash automation is the creation of Debian packages, which requires a LOT of work in directories. When you're typing in the waves of "mkdir" and "cd" into a bash script, it's easy to get lost, and that efficiency you felt while making the script goes out the window.

For the first time ever, there is now a solution: bpp. Bash PreProcessor reads a .bpp file, which is formatted plain text, and creates a bash script. The bpp language was designed with ease-of-use and visual perception in mind. How would you describe a directory layout to somebody through text? My answer to this question looked something like this:

|home
||Pictures
|||Vacation
|||Cats
||Documents
|||Document.txt
|bin
||ghc
||boy

I took this idea, and made a language with it. With the exception of Documents.txt, this is a valid bpp file that would create this directory layout, with proper nesting et al. Originally, this was as far as I was going to take the project. But I realized the need for creating content from within the script, so the next level of bpp was created. 4 special commands control the flow of a bpp file.

^file - Creates a file using touch

%command - Executes a shell command from the current directory

~file: line of text - Writes a line of text to a file.

~{file:
line1
line2
line3
} - Writes multiple lines to a file.

It is possible to do anything that Bash could with these commands. You can embed Bash scripts, or even embed Bash PreProcessor scripts with your PreProcessor scripts. This, paired with the directory layouts tool, creates a shell interface with an important feature: Modeling Power

A picture is worth a thousand words. A video is worth a lot more than that. Go watch bpp in action at the top of this article to see its capabilities. Since the making of this video, there has been the addition of one command, "jmp", which lets you jump between parts of the file like a goto statement.



Links
https://github.com/dymatic/bpp/tree/master/bpp 

Samples
https://github.com/dymatic/bpp/blob/master/bpp/sample.bpp


Monday, July 22, 2013

Ubuntu Edge crowdfunding gone live

Today, July 22nd 2013, Canonical announced their new phone, which they are calling the Ubuntu Edge.
Canonical changed their website for the announcement in an attempt to get viewers on their indiegogo page, which has a goal so high that it will double the previously highest crowdfunding goal every achieved; they want 32 million dollars in donations before they will roll the phone out. If Canonical cannot receive this funding, they will not make the Ubuntu Edge, but their phone Operating System (Ubuntu Touch) will still be released for existing compatible phones. Because of the open nature of Ubuntu Touch's development, many Android phones will have the operating system ported to it before and after the release of the finished product.


Features
The Ubuntu Phone features:
  1. 128 GB Storage
  2. 4     GB RAM
  3. Saphire-glass screen / camera, very hard to break and very resistant to scratching.
  4. 2 LTE Antennae
  5. Docking, which allows the phone to run Desktop Ubuntu.
  6. Silicon-Anode battery.
  7. Android Dual-Boot with their "Ubuntu for Android".
  8. Buttonless experience from Ubuntu Touch. Everything is done with gestures.
  9. Full Gnu/Linux system on the phone. Coreutils, terminal emulators, ssh tunnels, programming apps for the phone in Lisp / Haskell / Rust / Whatever the heck you want. It's all there.
  10. Access to Ubuntu ArmV7's repositories for tens of thousands of applications off the bat.




Speculation
Will they reach their goal of $42 million? Well, roughly an hour after the launch, at the time of me writing this news post, they have reached half a million dollars. If, on the 21st of August, it appears that they will not reach their goal, Shuttleworth could very easily cap off however much they need. Shuttleworth has shelled out $500 million dollars in the past to go to space, and his net worth is currently worth just as much as the trip to space. If IndieGoGo can get Canonical close to the goal, Shuttleworth will likely save the project from oblivion. So will the edge make it? Most definitely so.

Tuesday, July 16, 2013

Comparison of IRC clients

IRC, or Internet Relay Chat, is a protocol for transferring text to a server which will relay the text to everyone else connected to the room or user it was sent to. You can think of it like a chatroom.

k4tzz connected
k4tzz  | Sup guys?
melga| Hai k4tzz, haven't seen you around in ages.
* joeyB0y pets k4tzz

IRC is sometimes used to organize large open source projects, or to get technical assistance (irc.freenode.net do both of these things).

There are multiple clients that can interface with the protocol, and this is a comparison of those clients.

Xchat / Hexchat
This is the most popular of the IRC clients. Xchat and Hexchat are largely the same, but Hexchat sees more regular development, so it is encouraged to use it over Xchat. It is also in the process of developing a completely text version with ncurses, so if you're into that it's a solid client. Xchathas a list
of the connected list, a text box on the bottom, and a channel list on the left. The settings are completely graphical.

Xchat also supports buttons specifically for Operators, so if you're op on a channel, xchat is a very good moderation tool. Xchat also supports the same text commands you would find in a command-line IRC client. /join, /connect, etc.

It does have its shortcomings, though. Because Xchat is graphical, it cannot be embedded in a multiplexer. That means if you accidentally close the window (and kill the tray icon, since it supports that) you lose your IRC session. This doesn't make it a good choice for a user that may switch desktop environments often. Xchat also can't be configured very heavily, since it's graphical, but you can change the colors of the display.

Pidgin

Pidgin is a chatting client that supports a whole heap of protocols. MSN, AIM, Jabber, what have you, it's in Pidgin either officially or as a plugin. Pidgin originally developed LibPurple, which you've probably used if you were doing any network-heavy code on Linux.

As for an IRC client, it lacks. It has the very basic features of an IRC client, but no heavy configurability options (even less so than Xchat). It supports tabs, but for the serious IRC user, this is not an option.

irssi

 Irssi is the command-line option that most people turn to. It consumes very little RAM, all of the standard text commands of an IRC client, scrolling, acts (kind of like tabs), and most importantly, heavy configuration in its configuration files. Themes (in the .theme format) can adjust settings of irssi deeply, and because of how old it is, there are many of these around. Irssi isn't a spring chicken any more, though. The man file was last updated in 2002! That doesn't make this a poor choice, though. For a simple command-line IRC experience, this is the option of choice you should have.

weechat
Weechat is another command-line IRC client. Much alike irssi, it supports all of the commands, but allows you to set them per-server. So you can have different default nicks across servers, or on all servers with /set irc.server_default.

Also like irssi, it has the ability to be placed in a terminal multiplexer, which will be persistent as long as your computer is running. It is commonly updated, unlike irssi. It also supports extra features, like showing how many unread messages are in each act. It also has a nick list, which is a feature many people miss when they use irssi over something like xchat.

Weechat's configuration file is hundreds upon hundreds of lines. Every little aspect of this client can be configured. There are also some features that are turned off by default, that you can enable and enjoy. There aren't any shortcomings to weechat, except for a bit of wastes space on the right side of the screen. However, this space is negligible if you shorten your timestamp and remove the nick list.

erc
 Erc is an interesting IRC client. It supports all of Emacs keybindings by default, and there's a reason for that: it is contained within emacs. Erc can be installed from MELPA with M-x package-install [ret] ercn. ERC supports full configuration, but is very light by default. It would make as much sense to use Erc as your default IRC client as it would for you to use M-x shell for your default terminal emulator. If you are in Emacs all the time, give it a whirl. Otherwise, save this client for when you need programming help or someone to keep you occupied in long coding sessions.

Conclusion
Objectively, weechat is the best IRC client. It supports the most features, the best performance, and the highest configuration possibilities. However, each of these IRC clients server a particular niche. Xchat for ease-of-use, irssi for simplicity, weechat for heavy IRC users that don't mind getting their hands dirty with a bit of configuration, and Erc serves people that use Emacs constantly. Pidgin? Not even once, but I guess if you use Pidgin often, it's a viable solution. I recommend downloading all of these and trying them out for yourself, since they're all very small downloads. However, weechat is the "winner" of the irc clients.

Tuesday, July 9, 2013

How to install MELPA in GNU Emacs

MELPA, which stands for "Milkypostman’s Emacs Lisp Package Archive" is a third-party repository for package.el, a package manager for GNU Emacs. Melpa provides hundreds of third-party Emacs lisp extensions like haskell-mode, scion, and themes. Installing it can be a pain, especially since MELPA's installation tutorial is incomplete. Here are the steps for using MELPA.

 1. Modify emacs.d
 There is a file, called init.el, that dictates what Emacs does when you start it. However, the preferred method of installing MELPA is to create (or modify) your .emacs file in $HOME. Create the .emacs file and put these contents into it:

(require 'package)
(add-to-list 'package-archives
  '("melpa" . "http://melpa.milkbox.net/packages/") t)


If 'package is already (required), do not require it again.

2. List the Packages
The step that the official guide leaves out is the command M-x list-packages. This is similar to what "apt-get update" would do. It will read in the possible packages that are candidates for installation. Now you can install packages with package-install [Ret].

Saturday, June 29, 2013

Sublime Text 3 - Release information, features, and is it worth it?

Introduction
The popular text editor sublime text has just released its latest build of its public beta. Sublime text's claims-to-fame are its minimap, support for 45 languages and additional subsets, its built-in package manager, and other features.

Version 2 has been around for a few years, so 3 was made to add features that used to be supplied via Sublime packages. Sublime Text 3 isn't ready to be used in a production development environment due to being beta, but it's shaping up nicely.

Cost
As opposed to editors like Emacs and Vim, Sublime Text costs money. Sublime Text 3 is $70 normally, or $30 for an upgrade from Sublime Text 2. This is a nominal amount when developers are usually making $20+ an hour.

Features, bugs, etc.
Sublime Text 3 has not yet introduced many visible features, but a lot of stuff under the hood has changed. It now has an auto-updating system for Windows and Mac, many API introductions, and even an officially packaged .deb file, whereas before a Tarball is all that was included on the website (subl is the name of the executable after it is installed). Sublime Text has support for mainstream languages like HTML and Javascript, but also for languages that aren't as popular like Clojure and Haskell. If you use these languages and want to take a break from Emacs / Vim, then this is a very compelling feature.

Sublime also integrates with various build systems. Sublime knows how to compile ruby, python, java, erlang, c++, D, and Haskell executables. It can also integrate with Make, so the user can specify a build system for languages that aren't supported by the default builds. Sublime will end the days of saving a file and compiling / running it in a separate terminal.

The only bug I noticed while using it for Haskell development was that Untitled, the default buffer for a Sublime Text, ended up getting saved, making me "Save As" to name the file, and then delete Untitled. Bugs are being ironed out for release, and if you find any you can report them to the developer.

Competition
Is Sublime Text better than Emacs or Vim? That is largely opinion and it depends on your workflow. Sublime Text, especially 3, does not have nearly the plugin market the other development tools (Eclipse, Emacs, Vim) have. It is proprietary, which means that if there is a problem you are powerless to fix it. It also must be launched graphically, unlike its competition. Memory usage is even higher than Vim's, but tied with Emacs'.

But it does have more support out-of-the-box than any of the other editors mentioned. Whether or not you buy Sublime Text depends on how much time you want to spend configuring other editors. Emacs and Vim could certainly be made to do Sublime Text's job, but with much configuration. Consider this before shelling out $70 for a license.

Thursday, June 20, 2013

How to install D (dmd) in Fedora

Continuing our "Installing in Fedora" series is dmd, the compiler for the D programming language. Trying to install this in Fedora was a headache, but doable. How much trouble you have will vary but what system you're on.

x86-32
On a 32-bit system, all you need to do is
wget http://downloads.dlang.org.s3-website-us-east-1.amazonaws.com/releases/2013/dmd-2.063.2-0.fedora.i386.rpm
yum install libgcc glibc-devel
rpm -i ./dmd*

x86-64
On 64-bit systems, it gets more complicated. For some reason, you will need the 32-bit libraries (libgcc and glibc-devel) even if you have the 64-bit dependencies installed (which you probably do). The steps now become:
wget http://downloads.dlang.org.s3-website-us-east-1.amazonaws.com/releases/2013/dmd-2.063.2-0.fedora.i386.rpm
yum install libgcc.1686 glibc-devel.1686
rpm -i ./dmd*

Forcing the use of 32-bit packages on a 64-bit system is not recommended, but you shouldn't run into any problems with it. Now you can compile your D files with dmd from the command line.

Sunday, June 2, 2013

How to install Google Chrome in Fedora 19

I had some trouble installing Google Chrome within firefox. It downloaded the .rpm file to /var/temp, but was unable to install it with gPackageKit due to "insufficient permissions". If you have this error, or just want an easier way to install Google Chrome, here is how:
Dependencies
I had an issue as well with my package manager not automatically finding one of the dependencies, but this problem could have been on my end. To be safe, install the "lsb" package from your package manager.

The Command
This one-stop-shop command (as root) will Download and install the x86 version of Google Chrome.

wget https://dl.google.com/linux/direct/google-chrome-stable_current_i386.rpm && rpm -i google-chrome-stable_current_1386.rpm

For the x86_64 version:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm && rpm -i google-crhome-stable_current_x86_64.rpm

Of course, both of these commands assume that you have read the license agreement here: http://pastebin.com/ExXM86Y1

Congratulations, you are now the proud owner of a Google Chrome browser.

Saturday, June 1, 2013

Fedora 19 Beta Review

The Red-Hat sponsored, community-driven Fedora project is gearing up to release its 19th installation of their Operating System; it is named Schr√∂dinger's cat. In fact, there is a funny story regarding the name, and the first thing that this review will touch on. The name, containing the exotic √∂ unicode character, crashed the bug report system since it could not properly handle Unicode. It has yet to be seen whether or not this problem effects other software that will process the distribution's name, but it's impossible that the decision to put this character in the name will not cause any grief. It was silly to let something like a name cause technical uncertainty (they could have just as easily named it Schrodingers cat).

Now that that part of the review is out of the way, let's look at the meat and bones of the Fedora system.

If you do not already have the .iso, grab it here: http://fedoraproject.org/get-prerelease?anF19b. The .iso file is very large, coming in at 4.4 GiB (enough to fit on a DVD -- Barely. It will trim down a LOT after the release)

Installation
-----------------
I do not have pictures or video of the installation. In fact, this review is mostly text-based because of how little has changed from 18. The installer DID change in a positive way, however. My first impression was of a particularly weird boot with text that was semi-selected. I couldn't tell which option in the boot screen was selected, but I could tell if I was at the very top or bottom of the list, so it was enough information to boot the .iso.

The installer then presented the option to either install the system, or try and install the system. I chose installation. The installer is still similar to the installer from Fedora 18 (which caused a LOT of controversy for various reasons. Yes, it does still try to look pretty. Yes, the done buttons are in weird spots.) The installer felt snappy on my hardware, and it had some options I wouldn't have inspected, like installable software sources with really good developer support (like a patched Eclipse).

The disk partitioner didn't ask me what I wanted to do, but since I didn't have enough room to install the image (10 GiB for me when all was said and done) it dropped me into an advanced partitioning tool. In terms of aesthetics and ease-of-use, it was probably the easiest to use out of any of the major distros. Feature-wise it was lacking. I saw no option for full-disk encryption (but it may have it; I just didn't see it) and no option for BTRFS.

When the disks were set up, it began the installation with a slide-show down on the bottom of the screen like Ubuntu has. The slideshow's pictures were not antialiased, and the viewing window was unusually small, almost like an ad. Most of the screen space here was wasted, except for options to set the root password and set up users. The user setup was impressive, toting features like changing the username based on the real name in real-time. 

After-Installation
I installed the Gnome version, so if you went a different route that is where this guide will differ a bit from you. Later on it will converge, but I have to get a lot of Gnome stuff off my chest.

When you log into the desktop environment, there is a nice post-installation greeter (graphical) like (Arch|Crunch)bang's to let you move through some userland options. When all of that is done, it plays an annoying little Gnome video tutorial, which was unnecessary but helpful for people new to the system. Up to this point, all was going swimmingly. On the surface it was a good system, but Gnome had a way of ruining that.

Problems with Gnome
Why would I put this in the review? Well, Fedora is strongly tied to Gnome, therefore a majority of Fedora users will be running Gnome. I had a particular amount of trouble doing simple tasks, even logging out.

GNOME takes a weird approach when it concerns their users. GNOME believes that GNOME knows best, and that GNOME'S users are inherently stupid and need to be protected from their own idiocy. I have heard this grip from within the Linux community since 3.2, but it is only now in Gnome 3.8 that I have seen the effect full-on.

Problem 1: No Logout Button
Gnome has a policy now where it will not provide a logout button within the Desktop Environment unless more than one user exists. There's NO ESCAPE. Want to switch Desktop Environments? Nah, Gnome says you can get back to work in your crappy fisher-price diluted Environment that they give you. There are only a few ways to circumvent this, and more in-depth guides will come later. In short, running "sudo pkill gdm" in the terminal will terminate the display manager, which systemd will re-initialize, bringing you back to the login screen. This is a dangerous hack, but aside from adding a user it is the only way.

Warning: Technical
Installing Desktop Environments aside from GNOME is a whole other ordeal. Because of how gdm works, in some Desktop Environments X clients (windows) that are closed will remain drawn onto the screen. Completely changing the display manager is the only way I found to get around this. To do so, install one that you are comfortable with (lightdm is a good choice; I prefer lxdm) and then run "systemctl disable gdm.service && systemctl enable [your display manager].service" before rebooting. These are systemd commands that will disable gdm from booting and replace it with something else.

The Verdict
The Fedora Experience will vary judging by who is having it. Personally, I have very much liked the repositories, package manager, and some of the defaults that it came with, even if it was a pain for some reasons (i.e Chrome not being installed properly).

Technically this is not a production OS. TECHNICALLY. It is  strange, but I have had less usability and stability problems with Fedora 19 than I had with Fedora 18. Hats off to the volunteer developers and Red Hat backing for that one.

Fedora 19 could help Fedora regain its reputation after the crash that was 18.