Entries filed under Tweaks

PHP + Laravel development Packages for atom.io

Posted on 30. Januar 2018 Comments

PHP CS Fixer

brew install php-cs-fixer

apm install php-cs-fixer

Settings:

php path: /usr/local/bin/php

php-cs-fixer path: /usr/local/bin/php-cs-fixer

PHP CS Fixer Rules: @PSR2,blank_line_after_opening_tag,whitespace_after_comma_in_array,blank_line_after_namespace

PHP CS Fixer Arguments: --using-cache=no, --no-interaction, --stop-on-violation

[x] Show Notifications

Ctrl+Cmd+S

Can also be used on commandline for folders, e.g.
$ php-cs-fixer fix app/ --rules=@PSR2,blank_line_after_opening_tag,whitespace_after_comma_in_array,blank_line_after_namespace

 

php-integrator-refactoring (php-integrator-base)

apm install php-integrator-base

apm install php-integrator-refactoring

Linting (also see linter(-php))

Sort use statements

 

linter and linter-php

apm install linter

apm install linter-php

In case linting with php-integrator-base does not work.

 

language-blade and language-vue

apm install language-blade

apm install language-vue

 

minimap

apm install minimap

Short overview over the code on the right side

 

highlight-selected

apm install highlight-selected

 

platform-ide-terminal

apm install platform-ide-terminal

Instead of switching windows, terminal right in atom

Cmd+Shift+T

 

symbols-tree-view

apm install symbols-tree-view

Structured overview on the right side over classes, constants, attributes, methods etc

 

hyperclick and hyperclick-php

apm install hyperclick

apm install hyperclick-php

Cmd+Click on classes, functions etc to go to origin.

Not needed if you installed atom-ide-ui

 

teletype

apm install teletype

Work on the same file with coworkers, encrypted via WebRTC

 

More dependencies might be installed with installing some of these packages

Quick and dirty redirect script for the fitting shipping provider

Posted on 2. März 2017 Comments

Another way to use the PHP library shipping-service-provider-check apart from fixing the shipping providers in the ERP Plentymarkets is a simple quick and dirty PHP script that redirects to the tracking page of a fitting shipping provider. You can find the whole sourcecode on GitHub.

Installation

If you don’t use some sort of MVC this is a quick way to do it. If you do, I suspect you’ll know how to alter this example to fit your system. Feel free to write me an e-mail or comment if you need help

  1. Log onto your server and create a folder
  2. Copy or git pull the files, including .htaccess
  3. Get Composer
  4. composer require repat/shipping-service-provider-check

Explanation of the code

The $trackingId variable is received via HTTP GET. This means the URL would be http://url.tld/trackingscriptfolder/script.php?tracking_id=123456 (or without the script.php in case of the .htaccess), where 123456 is the TrackingID. The rest is more or less just for debugging. The scripts returns a HTTP Code 422 and ends if there is no input given.

$trackingId = $_GET["tracking_id"];
if (empty($trackingId)) {
  $unprocessableEntity = 422;
  http_response_code($unprocessableEntity);
  echo "wrong input";
  return;
}

Next the URLs will be defined. The keys have to match the shipping providers so make sure the shipping providers are added at the library as well. The TrackingID will be added at the end of the URL, so make sure they have the right format.

$shippingProviderURLs = [
  "dhl" => 'https://nolp.dhl.de/nextt-online-public/set_identcodes.do?idc=',
...
];

Then follows the documented way of checking for the providers. It could technically be that at the same time a TrackingID is valid for more than one provider. To keep things simple, we’ll just use the first one (array_search instead of array_keys). In case there is none found, array_search returns false and the script continues. In case there is one found, the header() function is called to redirect the user to the correct provider page.

$checkedProvider = array_search(true, $result);
$urlOfCheckedProvider = $shippingProviderURLs[$checkedProvider];

if ($checkedProvider !== false) {
  header('location: ' . $urlOfCheckedProvider . $trackingId);
}

Now it’s up to you what you will do with the ones you can’t redirect. I decided to write a little skeleton.html file and include that with a simple message that the user could try the shipping providers where a check is not possible (no API, no website scraping, no regex). They are listed earlier:

$shippingProviderURLsNoCheck = [
  "DPD" => 'https://tracking.dpd.de/parcelstatus?query=',
...

Fix shipping providers for FBA orders in Plentymarkets

Posted on 27. Februar 2017 Comments

The popular ERP Plentymarkes let’s you send your orders via the Fulfillment by Amazon program to your customers. Amazon is just used as a logistics partner, the order doesn’t have to come via Amazon. It could e.g. be a Rakuten or eBay order. The problem that Plentymarkets didn’t address at all and is discussed in the private forums, is that Amazon chooses whatever shipping company they seem fit.

Every order has a standard shipping provider and with it comes a URL for tracking the package. Most of the vendors would implement an event procedure („Ereignisaktion“) that sends an email to the customer containing the order and the TrackingID as soon as it’s shipped. The TrackingIDs are directly imported from Amazon. Unfortunately Plentymarkets does not change the shipping provider in case it’s not the default one (which is often the case). So the customer gets wrong information.

In one of last last blogposts I introduced a PHP package to check which shipping provider a TrackingID belongs to by either scraping their website or using a regular expression and filtering for common patterns. In this blog post I want to explain how to use it to fix those orders. You will need a webserver with PHP and MySQL and a little knowledge of programming and Linux.

You can find some simplified code examples on GitHub soon.

  1. Take your FBA orders out of the event procedures that sends the email to the customers, filter e.g. via WarehouseID
  2. Instead, use an event procedure to mark those orders with a flag, e.g. a star (ID 2)
  3. Create a DynamicExport of the type OrderComplete. Filter for your Sent Status (usually 7) and WarehouseID of FBA orders. Include these fields:
    1. OrderID
    2. OrderPackageNo
    3. OrderParcelServiceID
    4. OrderParcelServicePresetID
    5. OrderLastUpdateTimestamp
  4. Implement the SOAP Call GetDynamicExport (will be replaced by REST via Plugin mid-2017)
  5. Write a Cronjob that calls the GetDynamicExport script with the FormatID of the DynamicExport from #2
  6. Create a database table called ‚pm_shipping_providers_check‚ with the fields from #2
  7. Write a script that imports the CSV you downloaded with the GetDynamicExport call into your MySQL database
  8. Create another DynamicExport, this time of the type Order. Include these fields:
    1. OrderID (Synchronisation)
    2. ParcelServiceID (Import)
    3. ParcelServicePresetID (Import)
    4. PackageNo (Import)
  9. Create a table with these fields called ‚pm_shipping_providers_correction
  10. Create a script, that uses the shipping-service-provider-check library to check the every PackageNo in ‚pm_shipping_providers_check‘ and – if the provider is different from the default one – writes it into ‚pm_shipping_providers_correction‘
  11. Implement the SOAP Call SetDynamicImport (see #3)
  12. Write a script that exports the table ‚pm_shipping_providers_correction‘ into a (semicolon seperated) CSV.
  13. Create a cronjob that uploads the file regularly
  14. Create an event procedure on the event PackageNo that sends out emails, but only for the previously flagged orders

Use ssh-agent for atom.io remote-sync under MacOS

Posted on 22. Januar 2017 Comments

If you use the IDE atom.io with some sort of remote sync/scp/sftp package you can’t just use ssh-keys out of the box, if you set them up with a passphrase (which you should!). Here’s the 3 options most plugins offer:

  1. Use password (unless you disabled the option on the server)
  2. Use ssh-key
  3. Use ssh-agent

The problem with #2 is, that you would have to save your passphrase in a clear-text file which is never a good idea. But you can use the ssh-agent on MacOS the following way:

  1. create a ~/.ssh/config file
  2. add this line: AddKeysToAgent yes
  3. $ ssh-add .ssh/id_rsa
  4. restart atom

Screenshots don’t show up on the desktop anymore on MacOS

Posted on 19. Januar 2017 Comments

This is a bug in finder, the files are being stored and will show up in the console with the ls command. However, to see them in finder, click on the Apple symbol on the top left corner, select Force Quit and then Finder. It probably would also help to just reboot.

 

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.

Domain von Domain Offensive bei Heroku nutzen

Posted on 24. Januar 2015 Comments

Ich habe neulich die Domain morsecode-api.de bei Domain Offensive erworben und wollte nun diese Domain mit meiner Heroku App für Morsecode As A Service nutzen. Allerdings bietet Heroku nicht die Möglichkeit an, A Resource Records oder AAAA Resource Records (für IPv6) zu benutzen. Stattdessen empfehlen sie einen CNAME Record. Nun ist es von der IETF aber nicht empfohlen bzw. gegen den Standard CNAME Records für root Domain Namen zu verwenden und viele Hoster unterstützen dies auch nicht. Wie der Name schon andeutet sind diese Einträge für weitere anerkannte Namen der selben Domain gedacht (z.B. .net und .com für denselben Namen).

Der Workaround funktioniert bei do.de also folgendermaßen:

  1. In den do.de Domaineinstellungen wird eine Weiterleitung eingerichtet auf www.example.com/
  2. Nach einer Weile ist es möglich unter DNS (Zonen Details), die A bzw. AAAA Resource Records für *.example.com zu entfernen
  3. Außerdem muss man einen CNAME Eintrag für www.example.com anlegen, der auf example.herokuapp.com zeigt.

Der Ablauf ist dann folgender:

  1. Eine DNS Anfrage auf example.com wird gestellt
  2. Der DNS Server liefert einen A bzw. AAAA Resource Record für einen lighttpd Server von Domain Offensive zurück
  3. Dieser liefert dem Client eine HTTP Redirect 301 Message auf www.example.com/ zurück (s. 1. weiter oben)
  4. Eine DNS Anfrage auf www.example.com gestellt
  5. Auf diese antwortet ebenfalls do.de mit einem CNAME Eintrag auf example.herokuapp.com
  6. Die HTTP Anfrage wird an example.herokuapp.com gestellt.

Löscht man auch die A bzw. AAAA Resource Records, funktioniert die Domain nur über die Subdomain www.example.com.

Dies funktioniert nur für Webservices unter Port 80 via HTTP. Für andere Bereiche bleibt wohl nur übrig, auch die A bzw. AAAA Records auf example.com zu löschen und in den Anfragen nur die Subdomain www.example.com zu benutzen.

Ausprobieren kann man das nach ein bisschen Wartezeit mit z.B. cURL:

$ curl -vL example.com
$ curl -vL www.example.com

Bei meinem Beispiel sieht das wie folgt aus:

 

$ curl -vL morsecode-api.de/encode/A
* Hostname was NOT found in DNS cache
*   Trying 78.47.59.169...
* Connected to morsecode-api.de (78.47.59.169) port 80 (#0)
> GET /encode/A HTTP/1.1
> User-Agent: curl/7.35.0
> Host: morsecode-api.de
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Location: http://www.morsecode-api.de/encode/A
< Content-Length: 0
< Date: Sat, 24 Jan 2015 20:09:09 GMT
* Server lighttpd/1.4.28 is not blacklisted
< Server: lighttpd/1.4.28
< 
* Connection #0 to host morsecode-api.de left intact
* Issue another request to this URL: 'http://www.morsecode-api.de/encode/A'
* Hostname was NOT found in DNS cache
*   Trying 23.21.123.184...
* Connected to www.morsecode-api.de (23.21.123.184) port 80 (#1)
> GET /encode/A HTTP/1.1
> User-Agent: curl/7.35.0
> Host: www.morsecode-api.de
> Accept: */*
> 
< HTTP/1.1 200 OK
* Server Cowboy is not blacklisted
< Server: Cowboy
< Connection: keep-alive
< Content-Type: application/json
< Content-Length: 34
< Date: Sat, 24 Jan 2015 20:09:09 GMT
< Via: 1.1 vegur
< 
* Connection #1 to host www.morsecode-api.de left intact
{"plaintext":"A","morsecode":".-"}

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