• All articles on this website are done with Debian squeeze/wheezy unless otherwise stated. Some of the articles expect you to have a basic understanding of the bash shell as well.

c – find and replace character program

This is just going to be a collection of programs that i randomly make as i learn c, free to use.
i very much welcome suggestions on improvements. :)

This program finds and replaces characters in a file and writes the changes

/*Written by Michael Drahony*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
int i = 0;
char *buff1 = malloc(1000*4);
FILE *file1;
char *help = "--help";

if(*argv[1] == *help){
printf("Usage: prog-name <filename> <arg1> <arg2>\n");
exit(0);
}

file1 = fopen(argv[1], "r+");
if(file1 == NULL){
perror("Error");
exit(0);
}
fread(buff1, sizeof(char), 1000, file1);

fclose(file1);
file1 = fopen(argv[1], "w");
if(file1 == NULL){
perror("Error: Cannot write to file! - ");
exit(0);
}

i = 0;
while(buff1[i] != EOF){
if(buff1[i] == *argv[2]){
buff1[i] = *argv[3];
++i;
}else{
++i;
}
}
fwrite(buff1, sizeof(char),1000, file1);
fclose(file1);
return 0;
}

 

Posted in c programming, Linux, Projects | Tagged , , , , , | Leave a comment

Debain + Xmonad and Minecraft resize solution

To fix the resize issue with minecraft remove openjdk-7-jre and install openjdk-6-jre instead.

Posted in Linux | Tagged , , , , , , | Leave a comment

Generate a keyfile for a LUKS/dm-crypt encrypted drive

creating a keyfile for a LUKS/dm-crypt  encrypted drive is pretty straight forward.

ok the line belows just lets you create a 4096 bit key with random data, this will make it nice and strong to use.

 

$dd if=/dev/random of=~/keyfile bs=1024 count=4

and now you add the keyfile to your encrypted drive.

$cryptsetup luksAddkey /dev/sxx ~/keyfile

 

its up to you where you want to store your key, i prefer not to keep it on the actual computer as this reduces risk, a usb pen is good, just remember to have a copy of it somewhere else just in case you loose the usb pen, because once you lost your key, forget about getting your data back.

 

Posted in Commands, Linux | Tagged , , , , , , , | Leave a comment

Sed – part 3

ok a very short one this time, deleting the last line of a file & a line in between 2 other lines.

 

Delete the last line of a file

$sed '$d' fileold.txt > filenew.txt

This will remove line 2

$sed '1,3d' fileold.txt > filenew.txt
Posted in Commands, Linux | Leave a comment

Encrypt a Hard Disk with LUKS & dm-crypt

Simple and quick tutorial on disk encryption with LUKS & dm-crypt.

Read More »

Posted in Commands, Linux | Tagged , , , , , , , , | Leave a comment

Puppet – quick setup

Puppet is a cluster management system that allows you to configure and maintain thousands of computers or just a small handful, its worth checking out Puppet Labs to see what they have on offer.

Read More »

Posted in Commands, Linux | Tagged , , , , , , , | Leave a comment

Raspbian – minimal

This is just a list of packages you can remove from Raspbian to make it a little more minimal, this will let you start out semi fresh for building up the Pi the way you want.
This is aimed at people not planning to use any kind of GUI.

$apt-get autoremove gpicview galculator hicolor-icon-theme
cups-common samba-common smbclient wireless-tools wpasupplicant
alsa-base alsa-utils lxrandr lxsession lxtask lxterminal lxpanel lxappearance
desktop-base dillo penguinspuzzle gnome-icon-theme gnome-themes-standard
gtk2-engines smartsim scratch leafpad ed vim-tiny vim-common squeak-plugins-scratch
desktop-file-utils lxde-common lxde-icon-theme omxplayer x11-common
midori lxde python3 python3-minimal gcc-4.4-base:armhf gcc-4.5-base:armhf
gcc-4.6-base:armhf pcmanfm firmware-atheros firmware-brcm80211 firmware-libertas
firmware-ralink firmware-realtek lxpolkit x11-common xdg-utils netsurf-gtk netsurf-common
dbus-x11 lxsession-edit lxshortcut xarchiver menu-xdg sudo xauth libx11-data xkb-data

You can download a txt file of this below and just turn it into an shell script or copy and paste it into a terminal.

rpi-clean

If you have any other suggestions please leave a comment and i will conintue to add to the list.

 

Posted in Commands, Linux, Projects | Tagged , , , , , , , , | Leave a comment

Sed part 2

ok in part 2 of this tutorial we are going to remove a line from a text file with a couple of different methods.

Read More »

Posted in Commands, Linux | Tagged , , , , , | Leave a comment

Sed part 1

Sed is a stream editor, its a very simple yet a very powerful tool.
I will be covering many of the most useful aspects of sed in a multipart tutorial.
In part one we will be replacing a word in a text file.

Read More »

Posted in Commands, Linux | Tagged , , , , , , , | Leave a comment

Beowulf Cluster (Super computer) HowTo

This is the simplest way to setup a Beowulf Cluster at home, but this tutorial expects you to have some basic knowledge of the command shell and networking.

The version of MPI being used here is MPICH2 there is also OpenMPI and other variations, MPI stands for Message Passing Interface.
MPI is used in the scientific community for cancer research and in CERN facilities for particle physics and many other areas such as calculating prime numbers and so on.

Read More »

Posted in Linux | Tagged , , , , , , , , , , , | Leave a comment