Reference Chunks

Programming and data notes

Forward Flask Server Through NAT Virtualbox Guest

if you’ve setup port forwarding but you cannot see the content that the flask server is supposedly serving on port 5000, even though ports like 80 or 22 are working it might be because (as outlined in the docs) flask, by default, serves only on the localhost.

Check that ports are set up

Make sure that you’ve set up the portforwarding appropriately on the host…

1
VBoxManage.exe modifyvm "VMnameInQuotes" --natpf1 "guestFlask,tcp,,5555,,5000"

Check the ports on the guest Check…

1
netstat -nao

or…

1
netstat -nao | grep 5000

While the server is running and you should see a line like this…

1
tcp        0      0 127.0.0.1:5000          0.0.0.0:*               LISTEN      off (0.00/0/0)

Change the flask files

To be able to load the app on that port in your host machine…

Stop the server with Ctrl-C.

then change your

1
app.run()

to

1
app.run(host="0.0.0.0")

and restart the server

netstat should now show

1
tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      off (0.00/0/0)

and you should be able to access the guest server from the host using localhost:5555 (or whatever other port you forwarded it to)

References https://groups.google.com/forum/?fromgroups#!topic/utahpython/RFFdwBVKWz0 http://flask.pocoo.org/docs/quickstart/#a-minimal-application

Mysql Reset Root Passwords

user$sudo service mysql stop

user$sudo -u mysql -s

mysql$mysqld --skip-grant-tables --skip-networking

mysql>UPDATE mysql.user SET Password=PASSWORD('something') WHERE User='someone'

mysql>FLUSH PRIVILEGES

mysql>exit;

mysql$exit

user$sudo kill 'mysql process'

user$sudo service mysql restart# How does it work?

Mysql Get All Table Row Counts

Command line mysql for row counts for all tables in a database

NB count is approximate for innodb tables

1
SELECT table_name, TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{your_db}';

Changing Linux Terminal Highlighting for File Types

Included file ‘JB/setup’ not found in _includes directory

Alter colors for file types in linux terminal

The blue on green highlighting that results in a default debian color scheme when it is displaying VirtualBox Shared folders is hard to read.

To change it you need to create a new .dircolors file in ~/ by using dircolors -p > ~./dircolors.

Then edit the color specifications for OTHER_WRITEABLE (non-sticky) to something more suitable.

The man page says a ~/.dir_colors file will be recognized and used but the cruchbang (and maybe debian) .bashrc looks for a ~/.dircolors file intead. Change the color file name or edit the .bashrc to make it work.

I use a white text with a blue background for the directories, which looks like

OTHER_WRITEABLE 37;44

source .bashrc when you’re done editing.

Explanation at Ask Ubuntu
Debian User Forum Example
dircolors man page

Get Decimal Results in Python Division

Included file ‘JB/setup’ not found in _includes directory

Use float() to get decimal answers to division fuctions in python

some_data_value = 100
1 / float(some_data_value) #returns 0.01
1 / 100.0 #also returns 0.01
float(1/100) #returns 0.0, which is a float, but might not be what you wanted

Debian Rc Local Example for Automounting Virtualbox Shared Folders

Included file ‘JB/setup’ not found in _includes directory

Automatically mounting virtuabox shared folders when the guest starts, with read and write permissions

Add this to your /etc/rc.local for each directory you want to have automatically available

mount.vboxsf -w -o fmode=0777,dmode=0777 proj /home/dnfehren/projects

Reference

Ubuntu Forums

Rake on Crunchbang

Included file ‘JB/setup’ not found in _includes directory

I don’t plan to do a lot with Ruby right now so to get it working on my Crunchbang install I used…

sudo apt-get install rubygems rake

This might change in the future when I need better controll over the ruby environment but I dont want to deal with it now.

Clamscan Has No Log File by Default

Included file ‘JB/setup’ not found in _includes directory

clamwin’s clamscan command line tool reports all results on stdout, this will probably result in a list too long for finding infected files when it is complete.

using the -i option will only print infected files to stdout. using the -l [FILE] option will write a log to the specified file.