Entries filed under Linux

PHP Commandline Notification

Posted on 3. Januar 2018 Comments

When you run long (PHP) jobs it’s easy to forget about the terminal. That’s why I’ve created a small PHP package that will make a little sound. Because PHP itself doesn’t have this functionality anymore it’s possible to just echo the ASCII sign for BEL. Simply put this at the end of your PHP job:

use repat\CommandlineBell;
// flashes screen if possible, otherwise just bell()
CommandlineBell::flash();
// makes a beep sound
CommandlineBell::bell();

Under the hood it’s really just:
echo "0x07";

A good (non-PHP) alternative I found is brb by Viktor Fröberg, just run commands like this

php artisan migrate --seed ; brb

Of course it’s always possible to just run a TTS app on the commandline via exec() like this:

exec("say terminal task done");

Or you could do it similar to brb:

php artisan migrate --seed ; say seeding done

Source on GitHub

One Click Shadowsocks with no technical knowledge needed

Posted on 23. November 2017 Comments

Shadowsocks is a proxy that has been designed and used to circumvent censorship in China. So if it’s possible to get traffic across the Great Firewall of China it pretty much can be used anywhere, e.g. Egypt where VPNs are blocked since mid 2017.

Digital Ocean offers virtual servers for cheap with an easy to understand pricing model. Basically you pay either $5, $10, $20, $40, $80 or $160 per month, for more have a look at pricing at digitalocean.com. These server are general purpose servers, you can do everything with them, which also means, they don’t have anything installed and you need to do everything yourself.

oneclickshadowsocks.de is a service to install shadowsocks on DigitalOcean servers without having to actually login via SSH and entering lots of technical commands in the commandline. It uses the DigitalOcean API to create a Droplet (=server) with shadowsocks already set up and running. All you have to do is to enter the IP address you get via e-mail in your shadowsocks client and the password given to you on the website.

The code is open source and the website itself is hosted on GitHub Pages, which means, you can see the sourcecode of the page itself, running at that very moment. This way other people can verify they nothing shady is going on.

Commandline: Which programs are using network connection

Posted on 29. August 2017 Comments

lsof -P -i -n | cut -f 1 -d " " | uniq

lsof – list open files
-P list port numbers instead of service names
-i list all network files
-n IP addresses instead of host names

cut – cut output
-f specifies fields, separated in the input by the field delimiter character (-d)
-d delimiter

uniq – filters out repeated lines

Delete empty rows in CSV file with sed

Posted on 23. August 2017 Comments

This is for when you have empty lines (so lot’s of ,,,,,,) in your file.

MacOS

sed -i '' -e '/^,*$/d' filename.csv
find ./ -type f -exec sed -i '' -e '/^,*$/d' {} \;

Linux

sed -i '/^,*$/d' filename.csv
find ./ -type f -exec sed -i '/^,*$/d' {} \;

 

^ marks the beginning of a line
,* marks a possible infinite amount of commas
$ marks the end of a line

MySQL Workbench Error: line contains NULL byte

Posted on 21. April 2016 Comments

When importing CSV (or other) files into the database, scripts (especially PHP or C-related languages), will stop if there is – for whatever reason – a NULL byte in your file because it signals end of file/string, see Null bytes related issues.

So when importing a file like that with MySQL Workbench you will get this error:

line contains NULL byte

You can solve this by using the commandline tool tr (from coreutils):

tr < file-with-nulls -d '\000' > file-without-nulls

To check if there are any null bytes in your file, use the python IDE and type in:

open('filename.ext').read().index('\0')

Thanks to Pointy from Stackoverflow

ThinkPad Compact Bluetooth Keyboard with TrackPoint Einfügen beim Scrollen Fix Ubuntu 14.04

Posted on 16. Dezember 2015 Comments

Die ThinkPad Bluetooth Tastatur von Lenovo verursacht unter Ubuntu 14.04 einen Fehler, so dass beim Scrolling mit TrackPoint und mittlerer Maustaste gleichzeitig die Einfügen Operation ausgelöst wird. Ich will aber auf keinen Fall weder auf die Paste Funktion der mittleren Maustaste noch auf das Scrolling verzichte und habe lange gesucht bis ich die folgende Lösung gefunden habe: tp-compact-keyboard-backport.

  1. git clone https://github.com/mithro/tp-compact-keyboard-backport.git
  2. make
  3. make install
  4. hid-lenovo.ko in /lib/modules/3.19-*version*-generic/kernel/drivers/hid/ austauschen.
  5. (leider muss man das auch nach jedem Kernel Update machen, da sonst die mittlere Taste gar nicht mehr funktioniert)
  6. Neustart

Außerdem war noch tp-compact-keyboard hilfreich (daher habe ich auch das -backport repository). Ggf. ist dafür ein Kernel Update nötig bzw. einfacher als ein Kernel-Patch zu installieren.

Skript mit cat, unzip, grep und awk für eBays XML Responses

Posted on 7. Januar 2015 Comments

Wenn man bei eBay per API z.B. ein FixedPriceItem hinzufügt bekommt man die folgende Antwort nachdem der Prozess erst Scheduled und dann InProcess ist:

Status is Completed
Downloading fixed price item responses...Done
File downloaded to /tmp/add-fixed-price-item-responses-ABC123.zip
Unzip this file to obtain the fixed price item responses.

Den folgenden Code eine Datei schrieben, dann in /usr/local/bin verschieben und mit chmod +x Ausführrechte geben.

cat `unzip -o $1 | grep inflating |awk '{print $2}'`

Mit diesem Skript bekommt man zum debuggen eine schnelle Ausgabe der XML aus der Konsole bewirken:

debugebayxml /tmp/add-fixed-price-item-responses-ABC123.zip