Install dymo labelwriter on debian / linux & print from shell

apt-get install cups

scarico driver da dymo
cerchi so google dymo linux e esce la pagina, copi il link e…
wget http://download.dymo.com/Software/Linux/dymo-cups-drivers-1.4.0.tar.gz

Uncompress:
tar -zxvf dymo-cups-drivers-1.4.0.tar.gz

install dependencies
sudo apt-get install libcups2-dev
sudo apt-get install libcupsimage2-dev

Complile:
./configure
make
sudo make install

Configuring cups from web interface

for access to web interface from others machine in the lan:

edit /etc/cups/cupsd.conf  and replace:

Listen localhost:631

with

port 631

Add allow machine from lan in cupsd.conf (Allow From 192.168.1.0/255.255.255.0) :

# Limita l'accesso al server....
# Il default permette solo a locahost di accedre
<Location />
   Order allow,deny
   Allow From localhost
   Allow From 192.168.1.0/255.255.255.0
</Location>

# Limita l'accesso alla pagina di amministrazione...
<Location /admin>
   # La cifratura è disbilitata di default
   #Encryption Required
   Order allow,deny
   Allow From localhost
   Allow From 192.168.1.0/255.255.255.0

# Limita l'accesso alla pagina di configurazione...
<Location /admin/conf>
   AuthType Basic
   Require user @SYSTEM
   Order allow,deny
   Allow From localhost
   Allow From 192.168.1.0/255.255.255.0
</Location>

access to web interface with http://<ipmachine>:631

2015-03-26 19_16_25-Amministrazione - CUPS 1.5.3

2015-03-26 19_17_18-Aggiungi stampante - CUPS 1.5.3

2015-03-26 19_18_03-Aggiungi stampante - CUPS 1.5.3

2015-03-26 19_18_57-Aggiungi stampante - CUPS 1.5.3

2015-03-26 19_19_46-Imposta opzioni stampante - CUPS 1.5.3

For print image from shell:
lpr -P DYMO -o ppi=300 targa.bmp

For see the options of printer:
lpoptions -p PRINTER_NAME -l

Linear distance of two world coordinates

dist = arccos( sin(minlat) * sin(maxlat) + cos(minlat) * cos(maxlat) * cos(maxlon – minlon) ) * 6371

<?php
//coordinates of point 1
$lat1=45.12345;
$lon1=10.12345; 

//coordinates of point 2
$lat2=46.12345;
$lon2=11.12345; 

$distance = (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180); 

echo $distance;
?>

Descrizione Comandi

This post is in italian language


 

– Testo isolato, senza [] , {} , <>, digitare come tale
– Testo tra parentesi quadrati [] è facoltativo
– Testo tra parentesi graffe {} contiene le scelte da fare.
le scelte sono separate da | (pipe
) o da virgola ,
comando -{a|b} ciò comando -a o comando -b ma non comando -ab
– Testo tra parentesi uncinate <> deve essere sostituito col testo appropriato.
– I parentesi (…), usati per i parametri tale i nomi dei file
– I parentesi quadrati [] e I parentesi uncinate <> possono essere combinati
[<nome_file>] – facoltativo ma se gli usi devi scrivere il nome del file
– I parentesi quadrati [] e I parentesi graffe {} possono essere combinati
[–opzione={a|b|c}]

 

Remove comments in a php script

This script remove a comments from another php script.
Run script from shell and add name of the php script as argument.

<?php
    $source = $argv[1];
    $fileStr = file_get_contents($source);
    $newStr  = '';
 
    $commentTokens = array(T_COMMENT);
 
    if (defined('T_DOC_COMMENT'))
        $commentTokens[] = T_DOC_COMMENT;   
	
	if (defined('T_ML_COMMENT'))
        $commentTokens[] = T_ML_COMMENT;
    
	$tokens = token_get_all($fileStr);
 
    foreach ($tokens as $token) {
        if (is_array($token)) {
			if (in_array($token[0], $commentTokens))
				continue;
	 
			$token = $token[1];
        }
 
        $newStr .= $token;
    }
 
    $handle = fopen($source, "w");
    if($handle){
        fwrite($handle, $newStr);
        fclose($handle);
        //echo "open";
    }else{
        echo "no fucking handle!!";
    }
?>
telegram_logo

Set telegram-cli as daemon in debian based distro

Create a bash script in /etc/init.d with name telegramd

/etc/init.d/telegramd

#! /bin/sh
### BEGIN INIT INFO
# Provides:          telegram
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Commandline interface for Telegram
# Description:       Telegram-cli is a (unofficial) cli version of Telegram to chat from your console.
#                    This is an init script do make it a daemon.
#                    When used as daemon in conjuction  with LUA (scripting) you can use it to send your system
#                    commands to execute via other Telegram apps (PC - Phone - Web or other) while not
#                    logged in to the system.
#                    See: https://github.com/vysheng/tg for more information.
### END INIT INFO

DESC="Telegram Cli Daemon"
NAME=telegramd
PIDFILE=/var/run/$NAME.pid

. /lib/lsb/init-functions

# Carry out specific functions when asked to by the system
case "$1" in

    start)
        echo -n "Starting $DESC ... "
        start-stop-daemon --start --background --make-pidfile $PIDFILE --pidfile $PIDFILE \
            --exec /usr/bin/telegram -- -k /etc/telegram/server.pub -c /etc/telegram/telegram-cli/config -s /etc/telegram/action.lua -d -vvvv -E -R -D -C -P 2301 || true
        echo "Done."
    ;;

    stop)
        echo -n "Stopping $DESC ... "
        start-stop-daemon --stop --retry 2 --pidfile $PIDFILE \
            --exec /usr/bin/telegram || true
    echo "Done."

    ;;
    restart)
        echo -n "Restarting $DESC "
        start-stop-daemon --stop --retry 2 --pidfile $PIDFILE \
            --exec /usr/bin/telegram || true
        start-stop-daemon --start --background --make-pidfile $PIDFILE --pidfile $PIDFILE \
            --exec /usr/bin/telegram -- -k /etc/telegram/server.pub -c /etc/telegram/telegram-cli/config -s /etc/telegram/action.lua -d -vvvv -E -R -D -C -P 2301 || true
        echo "Done."
    ;;

    status)
        status_of_proc -p $PIDFILE telegram $NAME && exit 0 || exit $?
    ;;

    *)
        N=/etc/init.d/$NAME
        echo "Usage $NAME: /etc/init.d/telegramd {start|stop|restart|status}"
        exit 1
    ;;

esac

set correct permission:
chmod 755 telegramd

set the service for automatic start
update-rc.d telegramd default

Use:
service telegramd start
service telegramd stop
service telegramd status

for send message from shell or another script use
echo "msg CONTACT_NAME text" | nc -w 5 localhost 2301

lua script for telegram-cli, process incoming messages

Install library:
apt-get install lua-lgi libjson-glib-dev

process.lua:

function on_msg_receive (msg)
  if started == 0 then
    return
  end
  if msg.out then
    return
  end


  if (msg.text == 'ping') then
    if (msg.to.id == our_id) then
      send_msg (msg.from.print_name, 'pong', ok_cb, false)
    else
      send_msg (msg.to.print_name, 'pong', ok_cb, false)
    end
    return
  end
  if (msg.text == 'PING') then
    if (msg.to.id == our_id) then
      fwd_msg (msg.from.print_name, msg.id, ok_cb, false)
    else
      fwd_msg (msg.to.print_name, msg.id, ok_cb, false)
    end
    return
  end
end

function on_our_id (id)
  our_id = id
end

function on_user_update (user, what)
  --vardump (user)
end

function on_chat_update (chat, what)
  --vardump (chat)
end

function on_secret_chat_update (schat, what)
  --vardump (schat)
end

function on_get_difference_end ()
end

function cron()
  -- do something
  postpone (cron, false, 1.0)
end

function on_binlog_replay_end ()
  started = 1
  postpone (cron, false, 1.0)
end

Use:
telegram -k /etc/telegram/server.pub -c /etc/telegram/telegram-cli/config -s /etc/telegram/process.lua

script shell send telegram msg with expect

First read this post for install and configure telegram

Create a new script named sendtg:

#!/usr/bin/expect
set timeout 2
set msg [lindex $argv 1]
set dest [lindex $argv 0]
spawn telegram -k /etc/telegram/server.pub -c /etc/telegram/telegram-cli/config -W
expect "> "
sleep 10
send "\rmsg $dest $msg\r"
expect "> "
expect eof

Config

move the script in /usr/bin:
mv sendtg /usr/bin/sendtg

and set correct permission:
chmod +x /usr/bin/sendtg

Usage

sendtg User “message to send”

Update ip of wordpress in ksweb webserver

If you need a wordpress blog locally on phone,
you could install ksweb on android.

But you phone have a different ip each wireless, then wordpress don’t work because he use absolute path.

you need change ip before using the blog.

You could make a php file that change ip.

<?php
define( 'DB_HOST', 'localhost' );
define( 'DB_USER', 'blog_user' );
define( 'DB_PASSWORD', 'blog_pass');
define( 'DB_NAME', 'blog' );

$i=$_GET['i'];
//connessione al db
$conn_id = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die ('KO|500|Internal Server Error');
@mysql_select_db(DB_NAME, $conn_id) or die ('KO|500|Internal Server Error');
// @mysql_query("SET NAMES '".DB_CHARSET."'", $conn_id) or die ('KO|500|Internal Server Error');
 
$query = "update wp_options set option_value='".$i."' where option_id = 1;";
 mysql_query($query, $conn_id);
 
$query = "update wp_options set option_value='".$i."' where option_id = 2;";
 mysql_query($query, $conn_id);
?>

run script before launch blog with:

http://localhost/script.php?i=192.168.0.100

see next post for launch it with tasker

Calculate md5 in windows

Microsoft (R) File Checksum Integrity Verifier V2.05

Download the file attached

Syntax

Usage:  fciv.exe [Commands] <Options>

Commands: ( Default -add )

-add    <file | dir> : Compute hash and send to output (default screen).

dir options:
-r       : recursive.
-type    : ex: -type *.exe.
-exc file: list of directories that should not be computed.
-wp      : Without full path name. ( Default store full path)
-bp      : base path. The base path is removed from the path name of each entry

-list            : List entries in the database.

-v               : Verify hashes.
: Option: -bp basepath.

-? -h -help      : Extended Help.

Options:
-md5 | -sha1 | -both    : Specify hashtype, default md5.
-xml db                 : Specify database format and name.

To display the MD5 hash of a file, type fciv.exe filename

Compute hashes:
fciv.exe c:\mydir\myfile.dll
fciv.exe c:\ -r -exc exceptions.txt -sha1 -xml dbsha.xml
fciv.exe c:\mydir -type *.exe
fciv.exe c:\mydir -wp -both -xml db.xml

List hashes stored in database:
fciv.exe -list -sha1 -xml db.xml

Verifications:
fciv.exe -v -sha1 -xml db.xml
fciv.exe -v -bp c:\mydir -sha1 -xml db.xml

Download

download fciv tool