If you want to sort a class member with the functions uasort, uksort, usort (the u stands for user-defined comparison function) you have to take care of some things. bool uksort ( array &$array , callable $key_compare_func ) The function takes as first parameter the array you want to sort as reference. Thereby no copy is made to the function stack and any changes are directly made on… Read more →
Tutorials
WordPress change post_date for tests
If you want to create a post via the post factory in you tests you can do it like this:
1 2 3 4 | function test_getPostsInYear() { $post1_id = $this->factory->post->create( array( 'post_date' => date( '2010-04-08 13:46:43' ) ) ); $post2_id = $this->factory->post->create( array( 'post_date' => date( '2014-04-08 13:46:43' ) ) ); .. |
Make sure to pass a date! Unix timestamps or other formats won’t work. This creates 2 posts with different dates. You can test the function getPostsInYear(2014) as follows:
1 2 3 4 5 6 7 8 | $result = $this->plugin->getPostsInYear( 2014 ); $post_ids = array(); foreach ( $result as $post ) { $post_ids[] = $post->ID; } $this->assertNotContains( $post1_id, $post_ids ); $this->assertContains( $post2_id, $post_ids ); |
Post1 should not be returned by getPostsInYear( 2014 ) because… Read more →
Mirror site via wget
If you want to mirror a website to another location you can easily use wget as follows: Read more →
koding.io wordpress phpunit environment
If you want to use koding.io as wordpress plugin developer with tests (executed by phpunit) you can follow this guide. This guide illustrates how the test environment is set up on koding.io. You should already familiar with wordpress & testing to understand the tutorial. Read more →
How to install Scrapy
This line installs all requirements for pip first. After that you can install pip. With pip you can install Scrapy.
1 | sudo apt-get install build-essential libssl-dev libffi-dev libxml2-dev libxslt1-dev python-dev python-libxml && sudo apt-get install python-pip && sudo pip install Scrapy |
This should avoid errors like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | Downloading/unpacking lxml Running setup.py egg_info for package lxml /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url' warnings.warn(msg) Building lxml version 3.1.2. Building without Cython. Using build configuration of libxslt 1.1.26 Building against libxml2/libxslt in the following directory: /usr/lib warning: no files found matching '*.txt' under directory 'src/lxml/tests' Installing collected packages: lxml Running setup.py install for lxml /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url' warnings.warn(msg) Building lxml version 3.1.2. Building without Cython. Using build configuration of libxslt 1.1.26 Building against libxml2/libxslt in the following directory: /usr/lib building 'lxml.etree' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/home/admin/.virtualenvs/dev.actualito.com/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__getFilenameForFile': src/lxml/lxml.etree.c:26851:7: warning: variable '__pyx_clineno' set but not used [-Wunused-but-set-variable] src/lxml/lxml.etree.c:26850:15: warning: variable '__pyx_filename' set but not used [-Wunused-but-set-variable] src/lxml/lxml.etree.c:26849:7: warning: variable '__pyx_lineno' set but not used [-Wunused-but-set-variable] src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_4XSLT_18__call__': src/lxml/lxml.etree.c:138273:81: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default] src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *' src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__copyXSLT': src/lxml/lxml.etree.c:139667:79: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default] src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *' src/lxml/lxml.etree.c: At top level: src/lxml/lxml.etree.c:12384:13: warning: '__pyx_f_4lxml_5etree_displayNode' defined but not used [-Wunused-function] gcc: internal compiler error: Killed (program cc1) Please submit a full bug report, with preprocessed source if appropriate. See for instructions. error: command 'gcc' failed with exit status 4 Complete output from command /home/admin/.virtualenvs/dev.actualito.com/bin/python -c "import setuptools;__file__='/home/admin/.virtualenvs/dev.actualito.com/build/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-asDtN5-record/install-record.txt --single-version-externally-managed --install-headers /home/admin/.virtualenvs/dev.actualito.com/include/site/python2.7: /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url' warnings.warn(msg) Building lxml version 3.1.2. Building without Cython. Using build configuration of libxslt 1.1.26 Building against libxml2/libxslt in the following directory: /usr/lib running install running build running build_py copying src/lxml/includes/lxml-version.h -> build/lib.linux-x86_64-2.7/lxml/includes running build_ext building 'lxml.etree' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/home/admin/.virtualenvs/dev.actualito.com/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__getFilenameForFile': src/lxml/lxml.etree.c:26851:7: warning: variable '__pyx_clineno' set but not used [-Wunused-but-set-variable] src/lxml/lxml.etree.c:26850:15: warning: variable '__pyx_filename' set but not used [-Wunused-but-set-variable] src/lxml/lxml.etree.c:26849:7: warning: variable '__pyx_lineno' set but not used [-Wunused-but-set-variable] src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_4XSLT_18__call__': src/lxml/lxml.etree.c:138273:81: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default] src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *' src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__copyXSLT': src/lxml/lxml.etree.c:139667:79: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default] src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *' src/lxml/lxml.etree.c: At top level: src/lxml/lxml.etree.c:12384:13: warning: '__pyx_f_4lxml_5etree_displayNode' defined but not used [-Wunused-function] gcc: internal compiler error: Killed (program cc1) Please submit a full bug report, with preprocessed source if appropriate. See for instructions. error: command 'gcc' failed with exit status 4 ---------------------------------------- Command /home/admin/.virtualenvs/dev.actualito.com/bin/python -c "import setuptools;__file__='/home/admin/.virtualenvs/dev.actualito.com/build/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-asDtN5-record/install-record.txt --single-version-externally-managed --install-headers /home/admin/.virtualenvs/dev.actualito.com/include/site/python2.7 failed with error code 1 in /home/admin/.virtualenvs/dev.actualito.com/build/lxml Storing complete log in /home/admin/.pip/pip.log |
The reason for this error might be “out of memory”. Check the last lines of dmesg | tail Read more →
WordPress action or filter not called
If you are using the wordpress api to hook into actions or filters there are some pitfalls. But these pitfalls are not wordpress related but likely your faults. I wan’t to show how to NOT hook into wordpress. 1. add_action( "actionA", array( __CLASS__, "processA", 10, 3) ); Please check the array declaration. Stupid mistake, but it’s hard to locate the error. You can output $wp_filter and check… Read more →
Problems Solved for Setting Up Jenkins
You must set the %JAVA_HOME% and Path environment variables for jenkins. Otherwise you should get errors like:
1 2 3 4 | $ "C:\Program Files (x86)\Android\sdk/tools/android.bat" list target Der Befehl "C:\Windows\system32\java.exe" ist entweder falsch geschrieben oder konnte nicht gefunden werden. Ungültiger Pfad Das System kann den angegebenen Pfad nicht finden. |
To do so follow this steps: Create a %JAVA_HOME% var with path to the Java jdk/jre (without /bin) Add %JAVA_HOME% to the Path var. Extend the string with \bin now. Check the result by enter javac in the cmd. If something java… Read more →
toString(), equals() Contract
Any Object is an Object or a child of an Object as described in the Java Language Specification: The class Object is a super class (§8.1) of all other classes. A variable of type Object can hold a reference to the null reference or to any object, whether it is an instance of a class or an array (§10). All… Read more →
wget Seite rippen
Man kann perfekt alle Dateien eines Web-Verzeichnisses mit dem tool wget laden. Hier ein Beispiel:
1 2 3 4 | cd /home sudo mkdir mirror/ cd mirror/ sudo wget -v -r -A iso -c --http-user user --http-passwd password http://url |
1 2 3 4 5 6 7 8 9 10 11 | -v Ist verbose Mode -r rekursives Laden, folgen von Links (max 5 Ebenen) -A <list> Filter um nur iso zu laden -c Schaut ob die Dateien nicht schon vorhanden sind und versucht den Download wiederherzustellen, falls er abgebrochen war. --http-user und http-passwd werden nur benötigt, wenn das Verzeichnis einen Verzeichnisschutz hat. zu letzt die URL |
For – Know the difference
I would like to write some words about the difference of the for loop behaviour. At first you should read the code and notice 2 different for usages. Both should do the same. Do they?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | public class Main { /** * @param args */ public static void main(String[] args) { String[] blablubb = { "a", "b", "c" }; // 1) for(String s : blablubb) { s = "over"; } printArray(blablubb); // 2) for (int i = 0; i < blablubb.length; i++) { blablubb[i] = "over"; } printArray(blablubb); } public static void printArray(String[] arr) { for( String s : arr ) { System.out.println(s); } } } |
I assumed the first loop would also overwrite the string in the array – as the second one does. But it does not! –… Read more →