Monday, March 21, 2022

BusyBox HTTP Daemon not recognizing mime types

Busybox is a collection of very small linux tools that can be helpful when you want to build a very small system. Among them there is a httpd server that can serve static pages. You can use this server to serve files from a folder.

My problem was trying to serve some wasm+javascript files built from rust code: the MIME type for the .wasm file was not sent.

I fixed this by creating a httpd.conf file and added these lines to it:

.wasm:application/wasm 
.js:text/javascript
.json:application/json
.html:text/html

.html was probably not necessary :-) .

Starting the server:
$ busybox httpd -p 127.0.0.1:8080 -h ./ -c httpd.conf

Sunday, August 30, 2020

lxd notes

# set password on server 
lxc config set core.trust_password .........passwordhere....
  
# lxd define a remote: remotename is a string, the name by which you want to use the remote, arbitrary
lxc remote add remotename 192.168.10.4 
# you'll be asked for a password after enter

# then list containers on that remote
lxc list remotename: 

# list images on that remote
lxc list remotename:

# get the result of a command in a particular format
lxc list remotename: --format=json 
lxc list remotename: --format=cvs
lxc list remotename: --format=yaml 

# rename container 
lxc stop old_container_name
lxc move old_container_name new_container_name 

  

Monday, September 30, 2019

anycubic i3 mega-s, cura 4.2.1 and Linux Mint 19.1 Tessa

Bought myself a Anycubic i3 Mega-S. Not sure why, probably ramping up to a midlife crisis or something.

Downloaded the Linux version of Cura 4.2.1 from Ultimaker.

Printed a few things from thingiverse. Learned enough Freecad to design simple brackets, screws and clamps.

Spent the last few days trying to make Cura see the printer from Linux. It turns out that the solution was very simple, at least on Linux Mint 19.1: all I had to do was to add my user to the "dialout" group and then restart the X server and log back in to Mate.

Wednesday, July 10, 2019

zug.tap updated with example about how to run dlang TAP tests with Perl's prove

What is "prove": prove on perldoc.perl.org

zug.tap is my implementation of a TAP producer in dlang zug.tap in the official Dub repo

contents of .proverc:


-e '/usr/bin/rdmd -I./source/ -I../../source/'
--ext '.d'


all options in the command line:

prove -e '/usr/bin/rdmd -I./source/ -I../../source/' --ext '.d' -v



emilper@home ~/work/zug_project_dlang/zug-tap/examples/run_with_Perl5_prove $ prove
t/t0001_tests_pass.d ................. ok
t/t0002_tests_fail.d ................. Failed 5/5 subtests
t/t0003_tests_some_fail_some_pass.d .. Failed 2/5 subtests

Test Summary Report
-------------------
t/t0002_tests_fail.d (Wstat: 0 Tests: 5 Failed: 5)
Failed tests: 1-5
t/t0003_tests_some_fail_some_pass.d (Wstat: 0 Tests: 5 Failed: 2)
Failed tests: 4-5
Files=3, Tests=15, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.02 cusr 0.00 csys = 0.04 CPU)
Result: FAIL
emilper@home ~/work/zug_project_dlang/zug-tap/examples/run_with_Perl5_prove $ prove -v
t/t0001_tests_pass.d .................
1..5
ok 1 should pass 1
ok 2 should pass 2
ok 3 should pass 3
ok 4 should pass 4
ok 5 should pass 5
ok
t/t0002_tests_fail.d .................
1..5
not ok 1 should fail 1
not ok 2 should fail 2
not ok 3 should fail 3
not ok 4 should fail 4
not ok 5 should fail 5
Failed 5/5 subtests
t/t0003_tests_some_fail_some_pass.d ..
1..5
ok 1 should pass 1
ok 2 should pass 2
ok 3 should pass 3
not ok 4 should fail 4
not ok 5 should fail 5
Failed 2/5 subtests

Test Summary Report
-------------------
t/t0002_tests_fail.d (Wstat: 0 Tests: 5 Failed: 5)
Failed tests: 1-5
t/t0003_tests_some_fail_some_pass.d (Wstat: 0 Tests: 5 Failed: 2)
Failed tests: 4-5
Files=3, Tests=15, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.01 cusr 0.01 csys = 0.05 CPU)
Result: FAIL

Monday, March 11, 2019

remote backup script via ssh, new version

#!/bin/bash -x

SITE=$1
if [ -z "$SITE" ]
  then
    echo "no site supplied"
    exit
fi
echo SITE IS $SITE
ACCOUNT=root@$SITE
COMMAND="/bin/tar czf - /home "
BACKUP_FOLDER=~/backup
DATE=`date +%Y-%m-%d_%H-%M-%S`
echo DATE IS $DATE
DESTINATION=$BACKUP_FOLDER/$SITE/home_$DATE.tar.gz
mkdir -p $BACKUP_FOLDER/$SITE/

/usr/bin/ssh $ACCOUNT $COMMAND > $DESTINATION 

echo DONE

Saturday, January 12, 2019

vector operations in D

Up to a few years ago I was of the breed that spawns code fated to wait for requests for most of it's life so really bothering with optimizing it is not cost effective. Then I stumbled into the one million to one situations which warranted a lecture about how many of my monthly wages a server upgrade is worth. It was revealed to me that adding more memory to that particular server was worth what was spent on me over more than 6 months, and as a result I had suddenly become interested in optimization. The story ended with that particular call being upgraded from finishing in more than 4 hours to finishing in less than 5 minutes and in me starting to have real doubts about the meme regarding the cost ratio hardware/developer time.

This is the context. The meat of the issue is Dlang has a very easy to use way to let the compiler decide how operations on arrays should be done based on what is available to it at compile time: Array Operations . Testing the performance gains was done according to Other Dev tools: Valgrind Helper . Screenshots are of KCachegrind.

The code:

module tests.vector_operations;

void main(){
    test_loop();
    test_vector();
}

void test_vector() {
    int[1000000] test;
    int[] result;
    result[] = test[] + 1;
}

void test_loop() {
    int[1000000] test;
    int[1000000] result;
    for (size_t i = 0; i < test.length; i++) {
        result[i] = test[i] + 1;
    }
}
Compiling, running valgrind, demangling
$ dmd -g vector_operations.d 
$ valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes --callgrind-out-file=callgrind_out ./vector_operations
$ ddemangle callgrind_out > callgrind_out.demangled
Inspecting the results in KCachegrind:

Wednesday, January 9, 2019

porting old code from Note.js to D v2

Since about august I started porting code from Node.js to Dlang. Node.js is nice enough but the ecosystem has a Jurassic-going-on-Cretacic flavour to it.

I guess I no longer start drooling when I see templates and I don't swoon when having to deal with strong and strict typing, though templates help a lot and without them I'd have very probably given up and returned to Perl 5.

Here is the code: https://bitbucket.org/emilper/zug-matrix . I started with the naive algorithms from the original code and I am moving away to more formal ways of linear algebra, and already know more about it than I ever did. Again, dlang templates are worth *my* weight in gold :) , reusing code between more symbolic matrices and numeric matrices is worth the efort learning about dlang templates.



Friday, December 14, 2018

almost done with stretching matrices

Almost done with stretching (same as scaling but less high-brow) matrices https://bitbucket.org/emilper/zug-matrix.

Also perfected a method to write correct code while very tired: write tests with what you expect to get while still awake, then scramble the code around until you stumble upon a not-completely-disgusting solution and the tests pass. Maybe I should pattent it ?

Tuesday, October 2, 2018

DBD::mysql failing with mariadb on debian/ubuntu/friends

If installing DBD::mysql build fails on debian/ubuntu/etc. when you have mariadb-server installed, you might need libmariadb-dev-compat .

Monday, April 16, 2018

getting tired of being victimized by overeager JS developers I am taking a hard look at Javascript/Node environment

to keep it real and eat my own dog food I published some code on npm https://www.npmjs.com/package/matrix-mab

may the FSM have mercy of my developer karma :)

Friday, August 11, 2017

dlang - retrieve struct from void pointer passed to extern (C) function

struct Data {
    int depth;
}

extern (C) void startElement(void* userData, const(char)* name, const(char*)* atts) nothrow
{

    Data user_data = (*cast(Data*) userData);
    user_data.depth++;
    // and so forth



I do not know if this is the right way to do it but it seems to work.

Sunday, July 16, 2017

backup sites with cron and ssh

# m h dom mon dow command

33 0 * * *   /usr/bin/ssh root@lunch-break.ro "/bin/tar czf - /home/www/bla " > \
 /home/emilper/backup/bla/www_bla_`date +\%Y-\%m-\%d_\%H-\%M-\%S`.tar.gz 2>>/tmp/cron.log 
52 0 * * *   /usr/bin/ssh root@lunch-break.ro "mysqldump -u root -pblabla --opt bla_db | \
 gzip -9c " > /home/emilper/backup/bla/bla_db_mysql_dump_`date +\%Y-\%m-\%d_\%H-\%M-\%S`.gz \
 2>>/tmp/cron.log 

Saturday, July 8, 2017

perl compiled under 5 minutes with perlbrew on a Ryzen 7



emilper@home ~ $ time perlbrew install -j8 -Dusethreads -Duselargefiles -Dcccdlflags=-fPIC -Duse64bitint -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Doptimize=-O2 -Duseshrplib perl-5.20.3
Installing /home/emilper/perl5/perlbrew/build/perl-5.20.3 into ~/perl5/perlbrew/perls/perl-5.20.3

This could take a while. You can run the following command on another shell to track the status:

tail -f ~/perl5/perlbrew/build.perl-5.20.3.log

perl-5.20.3 is successfully installed.

real 3m50.827s
user 10m8.356s
sys 0m39.784s

Sunday, May 21, 2017

upgraded to linux kernel 4.8

I upgraded my Linux Mint 18.1 to the 4.8 kernel and was left without network and sound. To fix that all I needed to do was to install the linux-image-extra, which I don't remember ever needing to install explicitly:


sudo apt-get install linux-image-extra-4.8.0-52-generic


Saving here because it took me a couple of hours until I got to this solution.

Wednesday, April 19, 2017

update on Gedit plugin to format JSON

what changed: $j->canonical([1]) - this will sort the keys in the json objects

#!/usr/bin/env perl 

use strict;
use JSON::XS;
local $/ = undef;
my $content = ;

my $j = JSON::XS->new->utf8->pretty(1);
$j->canonical([1]);
my $output = $j->encode($j->decode($content));

print $output;

Tuesday, October 11, 2016

build dstep on Linux Mint 17.2



while trying to build dstep (a tool to convert C header files to D modules):

$ dub
Running pre-generate commands for dstep...
Performing "debug" build using dmd for x86_64.
dstep 0.2.2+commit.121.gf55746e: building configuration "default"...
Linking...
/usr/bin/ld: cannot find -lclang
collect2: error: ld returned 1 exit status
--- errorlevel 1
dmd failed with exit code 1.

Had all the clang libs (including the *-dev packages) installed but it did not change. Here was the solution:

$sudo su -
#cd /usr/lib/x86_64-linux-gnu
#ln -s libclang.so.1 libclang.so

setting up printer Brother HL-1212W on Linux Mint 17.2

it was underwhelming:

Click on the Mint button-> search for Printers -> add printer -> Network -> wait 1 second until the printer is found and the name is shown -> add it -> pick the recommended driver -> print test page to make sure. Total time: about 3 minutes.

You need to configure it to connect to the wireless network from windows first though.

Tuesday, August 2, 2016

using UUIDs as primary keys in MySQL

Using uuids as primary keys efficiently in MySQL: see this Store UUID in an optimized way, it has benchmarks and everything you might need; apparently their way is a bit more efficient than using large integers and a lot more efficient than using the UUID strings.

Also interesting Storing UUID Values in MySQL Tables.