My First Rust Crate

Feb 27

Today I created my first Rust Crate and published it on Crates.io! Check it out: https://crates.io/crates/changecase

I’m used to being able to change the case of strings in Python, but unfortunately Rust doesn’t provide an equivalent; you can only change case of individual characters. Clearly, the solution is to write a library for it.

Currently the library supports uppercase, lowercase, AlTeRnAtInG cAsE, inverting case, and capitalizing. Future work is to implement title case. I’ve already started to work on it by porting titlecase.py. The regex syntax is identical as far as ...

~ read more ~

My Attempt at Inbox Zero

Feb 21

I’ve taken a few steps today in an attempt at Inbox Zero. I tend to leave mail in my inbox to deal with it later, but it’s been bugging me lately and so I decided to do something about it.

Inbox Zero is an approach by Merlin Mann to maintain an empty (or almost empty) inbox. The benefit is that you get through your email more efficiently and spend less time thinking about it.

I’ve decided to go a bit further than only maintaining an empty inbox; I now aim to keep my entire mail account clean ...

~ read more ~

Getting That GitHub Green

Jan 29

Does your GitHub profile look empty? Want to appear productive, although you haven’t done anything all year? Fake those green boxes!

Git lets you amend old commits to change their dates, but you don’t really want to be ruining your repositories just for this, so set up a new repository and run the following script in it to generate a random number of commits for each day in the past year.

touch dates;
for x in {365..0}; do
    commit_date=$(date --date="$x days ago" --rfc-2822);
    num_commits=$(awk 'BEGIN{srand();print int(rand()*100) }');
    for ((n=0; n ...
~ read more ~

Rust Echo Server Example

Jan 21

There are many examples of TCP servers in Rust, and even echo servers, but I found many of them to be too complex. I think echo servers to be the best example for getting started writing servers in a new language, so I figured I’d write my own.

Note: A lot of this stuff is marked ‘unstable’, so you’ll get compiler warnings. If they turn into errors, please let me know so I can update the example.

The code itself should be fairly self-explanatory:

use std::net::{TcpListener, TcpStream};
use std::thread::Thread;

// traits
use std::io::Read ...
~ read more ~

A New Year

Jan 01

Resolutions? Me?? Just what are you implying? That I need to change?? Well, buddy, as far as I’m concerned, I’m perfect the way I am! — Calvin

Instead of making any sort of New Year’s resolution, I think I’ll come up with a list of things I want to learn in 2015. Progress will be difficult to measure (and not very meaningful), so my only goal is: don’t stagnate.

The first thing to learn more of is systems programming. I’ve already worked with Linux kernel modules and the networking subsystem, as well as having written ...

~ read more ~

Calling Rust from C

Dec 23

To call a Rust function in C, we’ll compile the Rust library to a shared object file, and link it to our C code.

First, the Rust code. This is the same as the “Calling Rust from Python” article.

// we want a .so file
#![crate_type = "dylib"]

// no_mangle lets us find the name in the symbol table
// extern makes the function externally visible
#[no_mangle]
pub extern fn square(x: i32) -> i32 {
    x * x
}

Save that as rmath.rs, and compile it:

rustc rmath.rs

The rmath.rs file will be compiled to librmath.so. This is the file we’ll ...

~ read more ~

Calling Rust from Python

Dec 23

To call a Rust function from Python, we’ll use the same method as calling C from Python: ctypes. For this we need to get the Rust compiler to make a shared object file from our Rust library, which we’ll link to in Python.

Alright, enough talk, here’s the code:

// we want a .so file
#![crate_type = "dylib"]

// no_mangle lets us find the name in the symbol table
// extern makes the function externally visible
#[no_mangle]
pub extern fn square(x: i32) -> i32 {
    x * x
}

Save that as rmath.rs, and compile it:

rustc rmath.rs

The rmath.rs file ...

~ read more ~

Migrating Your Flask App from SQLite3 to MySQL

Dec 08

So you’ve written your Flask app in Python 3, and have some data in an SQLite3 database which you’d prefer not to lose. This guide will walk you through setting up MySQL on a Ubuntu 14.04 server, transferring data from SQLite3 to MySQL, and connecting Flask-SQLAlchemy to the MySQL server.

Setting up MySQL

First, you’ll need to get the package installed:

sudo apt-get install mysql-server

Next, we need to create the user. We’ll assume the user is called “demo-user”, will only be connecting through localhost, and will use PASSWORD as its password. We’ll also ...

~ read more ~

Search History in Bash

Nov 28

Using the up and down keys lets you go scroll through your Bash history, but quite often you want to want a previous call to a certain program.

For example, you’ve got the following things in your history:

1 find . -type f | wc -l
2 cd ..
3 cd somedir

And you want to go back to the find.

You can hit the up key a couple times and you’ve got the find, but sometimes you’ve got a more complex history and you don’t want to keep pressing up till you get to the command you want ...

~ read more ~
Page 1 / 4   older »