Site Sponsors:
Backing Up Files Across Multiple Devices 
There you have them - sitting in a box. --From lots of CDs / DVDs, to far too many USB sticks to contemplate.

Rather than sitting there - waiting for us to toss them out - wouldn't it be nice if we could use them to backup our 'stuff?

Backup Splits


Much like in the days when we had lots of drive-tapes, the challenge is to split a `too-big` collection of files, across a `too-small` series of media. A problem almost as old as computing itself, fortunately all POSIX systems come with a program called `tar`!

sudo mkdir /d_backup 2> /dev/null
sudo chmod 777 /d_backup
cp $0 /d_backup
cd /d_backup
name=`date +d_drive_%Y_%j.tar`
echo Creating $name from $0
tar -cf ./$name /d_drive/
split -d -b 4480m ./$name

In the above, my task is to routinely back-up /d_drive into a folder named /d_backup. Once created, I want to split a julian-dated backup file into 4GB slices, from there to manually burn them out to a 2nd generation DVD drive. (*)

Splits Restored


To restore the files, all we need do is to (1) undo the `split,` by copying (2) all of the media-content to the hard drive, then (3) un-tar the concatenation:

cat * > d_drive.tar
tar xvf d_drive.tar

(*) Note that while the above `split` uses 4480 for the splits, that one should adjust the size to match the least-common size-denominator for any and all external media.



Sharing is caring!


-Rn



[ add comment ] ( 27 views )   |  permalink  |  related link
FreeCAD: LED-Hacking an STL Figgurine 
The team & I had some fun over the weekend adding a coin-cell LED to a 3D model:


The challenge involved reverse engineering an STL so as to experiment with soft-drilling hex-holes, as well as using clear filaments.

The process was to import the STL, then rendering as a "mesh", so as to convert it to a "shape", then a "solid" in "Part" mode (phew!)

Fortunately, there is a plethora of information on how to do such things using FreeCAD.


(Yea - Testing GUI's is easy, by comparison =)

Then, of course, we had to "map" a "sketch" to the solid in "Part Design" mode so as to start soft-drilling the thing to accept a standard sized CR2032 coin cell battery, plus either a 5 or 6mm LED.



The neat discovery de-jure was centered around how using faceted drill holes scatter light far more brilliantly (pun intended) than simply drilling things out.

So if you have a 3D printer, then feel free to give our "Mr. Moai" remix a try. For best results:

(1) Rotate & print on the base. (No supports required!)
(2) Use 0% infill.
(3) Set your wall size to 4x your nozzle size. (e.g. Our 0.4mm nozzle meant that we used a 1.6mm wall size.)

--You could even have them print one up for you!


Enjoy,


-Rn

p.s: A few days later, we remixed another - this time with a video to show off the internal wire frame.

Unlike the above, this one allows several Moai to be wired together in a series.


[ add comment ] ( 28 views )   |  permalink  |  related link
An Easy PHP CRUD Example ... for SQL / Sqlite! 
When our needs are simple, then so should be our code.

For 100% of what we need to do at the moment (manage a massive collection of data across a local network,) this class will do what we need it to do: CRUD far too many rows consisting of TEXT / string values!


So, is DAO-generation necessary? When using a name-associated array in PHP 5, all we need do is to define our fields, and away we go!


class SqlStringRecord {

function get_file_name() {
return "default.sqlt3";
}

function get_table_name() {
return "contacts";
}

function get_columns() {
$data = array();
$data[0] = "Name";
$data[1] = "Address";
$data[2] = "Note";
return $data;
}

function delete_table() {
$db = new SQLite3($this->get_file_name());
$tbl = $this->get_table_name();
$db->exec("DROP TABLE IF EXISTS $tbl");
$db->close();
if ($db->lastErrorCode() != 0) {
return FALSE;
}
return TRUE;
}

function create_table() {
$this->delete_table();
$fields = $this->get_columns();
$tbl = $this->get_table_name();
$cmd = "CREATE TABLE $tbl (ID INTEGER PRIMARY KEY AUTOINCREMENT";
foreach ($fields as $field) {
$cmd .= ', ';
$cmd .= $field;
$cmd .= ' STRING';
}
$cmd .= ")";
$db = new SQLite3($this->get_file_name());
$db->exec($cmd);
$db->close();
if ($db->lastErrorCode() != 0) {
return FALSE;
}
return TRUE;
}

function count() {
$db = new SQLite3($this->get_file_name());
$tbl = $this->get_table_name();
$rs = $db->query("SELECT COUNT(*) FROM $tbl");
if ($rs == FALSE) {
return FALSE;
}
$data = $rs->fetchArray();
$db->close();
return $data[0];
}

function create($special) {
$cols = $this->get_columns();
$tbl = $this->get_table_name();
$cmd = "INSERT INTO $tbl (";
$bfirst = true;
foreach ($cols as $col) {
if ($bfirst == false) {
$cmd .= ", ";
}
$cmd .= $col;
$bfirst = false;
}
$cmd .= ") VALUES (";
$bfirst = true;
foreach ($cols as $col) {
if ($bfirst == false) {
$cmd .= ", ";
}
$cmd .= "'$special[$col]'";
$bfirst = false;
} $cmd .= ")";
echo "\n\n$cmd\n\n";
$db = new SQLite3($this->get_file_name());
$db->exec($cmd);
$db->close();
if ($db->lastErrorCode() != 0) {
return FALSE;
}
return $this->count();
}

function read($id) {
$db = new SQLite3($this->get_file_name());
$tbl = $this->get_table_name();
$cmd = "SELECT * FROM $tbl WHERE ID = $id LIMIT 1";
$rs = $db->query($cmd);
if ($rs == FALSE) {
return FALSE;
}
$results = $rs->fetchArray(SQLITE3_ASSOC);
$db->close();
return $results;
}

function update($id, $special) {
$tbl = $this->get_table_name();
$cmd = "UPDATE $tbl SET";
$cols = $this->get_columns();
$bfirst = TRUE;
foreach ($cols as $col) {
if ($bfirst == FALSE) {
$cmd .= ", ";
}
$cmd .= " $col = '$special[$col]'";
$bfirst = FALSE;
}
$cmd .= " WHERE ID = $id";
echo "\n\n$cmd\n\n";
$db = new SQLite3($this->get_file_name());
$db->exec($cmd);
$db->close();
if ($db->lastErrorCode() != 0) {
return FALSE;
}
return TRUE;
}

function delete($id) {
$tbl = $this->get_table_name();
$cmd = "DELETE FROM $tbl WHERE ID = $id";
$db = new SQLite3($this->get_file_name());
$db->exec($cmd);
$db->close();
if ($db->lastErrorCode() != 0) {
return FALSE;
}
return TRUE;
}

}


So feel free to update:

get_columns()
get_table_name() [optional]
get_file_name() [optional]

Then simply use associative arrays as your "data access object" - as returned from the read($id) operation - then accessed via your own get_columns() names - to see how easily (ahem) CRUD happens!

The complete code + test case is here.

[ add comment ] ( 33 views )   |  permalink  |  related link

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next> Last>>