Call   0208 3131682   Mon-Fri 9am-6pm
Category

Uncategorized

Buddypress cheat sheet

By | Uncategorized | No Comments

in Member loop / directory – show xprofile fields

Just find the field in wp-admin and pop into the function above and echo it.

 

Buddypress hide the top level tabs from users ( e.g. hide the group tab)

By | Uncategorized | No Comments

This is to hide the top level tabs from users. Based on this code from the buddypress forums.

buddypress pr

 

WordPress on Windows IIS permissions error – uploaded file could not be moved to wp-content/uploads

By | Uncategorized | No Comments

Recently I’ve been developing a WordPress Intranet for a company that runs on Windows hosting ( IIS 6 – Internet Information Services ).

I ran into a problem with file permissions and not being able to write to the wp-content/uploads directory, I’ve ran into the same problem with unix many times (which alittle bit of recursive chmoding usually sorts out or just chgrp www-data, the user many hosts run apache as ).

What I was trying todo was add a picture to a post and it gave me the error:  uploaded file could not be moved to wp-content/uploads

With Windows its alittle different, here’s what I did:Wordpress on Windows IIS file permissions error

  1. right clicked the wp-content folder and clicked properties
  2. selected security tab
  3. Added the Authenticated Users group
  4. Added Modify permission to that group ( this then applies this recursively through wp-content , uploads etc …)
  5. retried uploading a picture to post, and all good.

 

uploads file permission error

 

This is also a good resource I did roughly whats in step 1 here (except with a different group) https://www.itworld.com/article/2833144/windows/wordpress-on-iis—the-uploaded-file-could-not-be-moved–solved-.html , I didn’t need to apply step 2.

 

 

 

Installing ChromeDriver for WebDriver – For the Techies (Java)

By | Uncategorized | No Comments

If your using Webdriver to automate your web testing you’ll already know what a great tool it is.

This is a quick note on installing ChromeDriver for WebDriver (to test using the Chrome Browser).

1. get the latest version of chrome driver from this url http://chromedriver.storage.googleapis.com/index.html

2. unzip this and place it whenever you want

3. next in your java code tell it where to find the unzipped file (replace ‘path goes here’ with your location). And thats it job done 🙂

System.setProperty(“webdriver.chrome.driver”,     “/path goes here/chromedriver”); 

driver = new ChromeDriver(); 

 

I highly recommend installing ChromeDriver for WebDriver , especially if your only using one type of browser for your testing. Hopefully you found this useful.

Java Generics (2008)

By | Uncategorized | No Comments

Notes on SCJP I did in 2008

Generics

 

Straight forward Type Safe Collections

 

List<Animal> myList = new ArrayList<Animal>();

 

the generic type in the declaration must match on both side of = , in this case <String>

(unless a wildcard is used to the left of the equals OR the ref has no gen type eg List myList).

 

can only add <Animal> or subtypes to myList

eg

 

myList.add(new Animal()); // GOOD

myList.add(new Dog()); // GOOD

 

myList.add(new Integer()); //ERROR

 

Passing / Returning from method

void myMeth(List<Animal> animals){ …

 

can accept

List<Animal>, Vector<Animal> // GOOD

 

cannot accept

List<Dog>, ArrayLis<Cat> // ERROR

 

 

Mixing Old and New Collections

List<Integer> list = new ArrayList<Integer>();

 

oldClass.alterList(list)

class OldClass{

    void alterList(List List){

       list.add(” a string ! “); // works

   }

 

Its not until someone calls a Integer method on the String obj in the collection that it will blow up ! 

However the compiler will issue a warning.

 

 

Type Safe Collections with wildcards

When you dont need to add to a collection

void lookAtThis(List<? extends Animal>){ …

 

can take:

 

List<Animal>

ArrayList<Dog>

Vector<Lion>

etc

 

can also take class type that implements an interface. [eg Animal implements ManEater]

 

List<? extends Animal> li = new ArrayList<Dog>(); // GOOD

this means assign anything to li that is Animal or subclass BUT will not be able to add to it

 

List<?> list is equivalent to : List<? extends Object>

 

Wildcards when you need to add to a collection 

void addTo(List<? super Dog> list){ …

 

this can take:

 

List<Dog>

List<Animal>

List<Object>

 

adding to:

 

list.add(new Dog()); // GOOD

 

list.add(new Object()); // ERROR

list.add(new Animal()); // ERROR

 

 

List<? super Dog> li = new ArrayList<Animal>(); // GOOD, looks abit weird usually more specific on right eg List l = new ArrayList();

li.add(new Animal()); // ERROR weird but true

li.add(new Alsatian()); // GOOD

 

Summary:

When see a ref that has notation like List<?> this can take list of any type but cannot add to it.

 

Generic Type ReferenceTaskis task valid?Notes
 
List<Animal> listlist.add(new Dog());YOK add

NOT OK poly pass list type

pass this to it List <Dog>N
list.add(new Animal());Y
 
List<? extends Animal> listlist.add(anything);NOK pass poly generic subtypes

CAN NOT add to

pass ArrayList<Dog>Y
pass List<Alsatian> listY
 
List<? super Dog> listlist.add(new Dog());YOK pass generic supertype to it

OK ADD only the generic type to it

list.add(new Animal());N
pass List<Dog>Y
pass List<Animal>Y

 

 

Templating your own Classes  

 A class can be templated (such as the collections classes have been in the API). Instance vars, method pass and return types can all be templated eg:

 

class GenExample<T>{

    T obj;

    List<T> myList;

 

    void meth1(T var){

       this.obj = var;

    }

 

    List<T> getList(){

       return myList;

    }

 

    T getObj(){

       return obj;

    }

}

 

if the class above was instantiated as  GenExample<String> eg = new GenExample<String>();

it would produce an instan ce of the class below. 

 

class GenExample<String>{

    String obj;

    List<String> myList;

 

    void meth1(String var){

       this.obj = var;

    }

 

    List<String> getList(){

       return myList;

    }

 

    String getObj(){

       return obj;

    }

}

 

Templating your own Methods 

 if you done need to template a whole class you could just template one method eg

 

public <T> void aMethod(T obj){ ….

 

here the template type MUST come before anything else including the return type.

 

For both class and methods you can put boundaries on them e.g.

 

public <T extends CharSequence> void aMethod(T obj){ ….

 

note the syntax is slightly different to that used when declaring a generice reference to something e.g. List<? extends Object> list