What is the @ sign in java used for?

The @ symbol denotes a Java Annotation. What a Java annotation does, is that it adds a special attribute to the variable, method, class, interface, or other language elements.

“In the Java computer programming language, an annotation is a form of syntactic metadata that can be added to Java source code. “

https://en.wikipedia.org/wiki/Java_annotation

Git and Github cheatsheet

Getting started:

1. Installing Git

sudo apt-get install git

2. Configuring Git

$ git config --global user.name "My Name"

3. Creating a new repository – git init

$ cd Desktop/git_exercise/
$ git init

4. Checking the status – git status

This command will return the current branch as well as it’s status compared to the head.

$ git status

5. Staging

The following command add the file hello.txt to git. This file will mbe included in the next commit.

$ git add hello.txt

or

$ git add -A

equivalent to

$ git add .

The two commands above add all files to git, except the files that are excluded due to git ignore rules.

6. Committing

$ git commit -m "Initial commit."

7. Modify the last commit message:

$ git commit --ammend

Start your Git repo anew

To remove the git file and create anew in the repo:

cd /path/to/your/repo
rm -rf .git
git init

Add a remote repository

In general:

$ git remote add origin https://github.com/user/repo.git

See https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories for more details.

Push to remote:

If it’s a commit on the master branch:

$ git push origin master

If it’s a commit on some branch named “some-branch”:

$ git push origin some-branch

Pull request

In our workflow we shall send code to CR (code review) before it goes to QA.

Create a branch

For that you create a branch, then push the code to your branch and the pull request is done in the master branch dashboard.

$ git branch some-feature 
$ git checkout some-feature

You can create the branch and go in the branch in command:

$ git checkout -b some-feature

# Edit some code

$ git commit -a -m "Add first draft of some feature"
$ git push origin some-branch

“After Bitbucket has her feature branch, Mary can create the pull request through her Bitbucket account by navigating to her forked repository and” clicking on Pull requests in the side bar and then “clicking the Pull request button in the top-right corner.“

Source: https://www.atlassian.com/git/tutorials/making-a-pull-request

More reading: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests

Set gitignore

https://www.atlassian.com/git/tutorials/saving-changes/gitignore

https://git-scm.com/docs/gitignore

touch ~/.gitignore
git config --global core.excludesFile ~/.gitignore
sudo vim ~/.gitignore

edit file with:

*.css.map

to exclude all files ending with .css.map

for a local approach simply create and edit the .gitignore file in the affected local repository.

If the file has already been staged, remove it by using:

$ git restore --staged <file>.

All those worked:

/source
*/.sass-cache
*/codeStyles
.gitignore

the directory tree was:

|

|-source

|-.sass-cache

|-.idea

|-codeStyles

If you accidentally sync and can’t push anymore:

hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

create a force push:

git push -f origin branchname

Set git Locally

https://docs.github.com/en/github/getting-started-with-github/setting-your-username-in-git

cd in the folder were you want to clone the repo:

$ cd directory/you/clone
$ git init
$ git config user.name “Your-Username” #can be different from your github username
$ git config user.email “your.email@example.com
$ ssh-keygen -t rsa -C “your.email@example.com

Enter file in which to save the key (/home/username/.ssh/id_rsa): /home/username.ssh/id_rsa

copy the content of the id_rsa.pub in your github settings in your profile.

Set github local authentication to be able to clone and push:

http://kbroman.org/github_tutorial/pages/first_time.html

List branches

List local branches

$git branch

List remote branches

$git branch -r

List all remote and local branches

$git branch -a

See what branch you are on:

$git status

Set local branch to be exactly as remote branch

git fetch origin 
git reset --hard origin/master

git clone a specific branch

git clone -b <branch> <remote_repo>

Delete a local branch:

git branch -d branch-name

or

git branch -D branch-name

in case the branch to be deleted is not fully merged.

Find a file in linux terminal

There are three useful command to find a file from the terminal in a linux system.

$ find /path/ -iname filename

$ locate -i filename

or just

$ locate filename

and you have grep

$ grep -r -i “searchterm” /path/to/search

-r make the search recursive and -i make it case insensitive.

To locate a program:

$ whereis programName

Facebook Pixel implementation: some references.

Implementation

Implementation – Facebook Pixel

Cookie consent and GDPR

If you plan to serve European Union you will need to implement GDPR.

General Data Protection Regulation (GDPR) | Facebook for Business

Which means you will need to ask for user consent before tracking their activity on your website that involves personal data. Fortunately Facebook offers an API to pause Pixel from firing and fires once consent is granted:

fbq('consent', 'revoke');
fbq('consent', 'grant');

General Data Protection Regulation – Facebook Pixel

You can also use a tag manager for that purpose.

Tracking Events

Facebook Pixel API offers a wide range of standard events to track.

Examples:

fbq('track', 'Purchase', {currency: "USD", value: 30.00});
fbq('track', 'AddToCart', {currency: "USD", value: 30.00});
fbq('track', 'PageView');

You will find the complete list of standard event here Reference – Facebook Pixel.

Custom Events

fbq('trackCustom', 'ShareDiscount', {promotion: 'share_discount_10%'});

Conversion Tracking – Facebook Pixel

Parameters and Object properties

In the examples above you may have notice that some code got additional information beside the event name.

{currency: "USD", value: 30.00}
{promotion: 'share_discount_10%'}

Those are optional parameters written as JSON-formatted objects and allow to include additional information to your events.

We have seen value parameters and promotion but you might want to add the category where the event took place

{content_category: "name_of_category"}

You can just as easily create custom parameters.

{custom_parameters: "some_value"}

or even more complex objects:

{contents: [
      {
        id: '301',
        quantity: 1
      },
      {
        id: '401',
        quantity: 2
      }]}

You will find more information on the link above where parameters are treated, plus you have some example above.

Migrating a static site to WordPress CMS

In this article we will consider that you have already finalize your site on WordPress on a development server, backed up your production site and that you are ready to do the transfer. We will simply mention that once you have finalized you site on the development site don’t forget to redirect your page through .htaccess.

Redirections

Your .htaccess will look like that:

<IfModule mod_rewrite.c>
RewriteEngine On

</IfModule>

# BEGIN WordPress
# Rivit, jotka ovat "BEGIN WordPress" ja "END WordPress" välissä on luotu dynaamisesti ja niitä tulee muokata vain WordPressin filttereillä. Kaikki manuaaliset muutokset riveihin tullaan yliajamaan.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /

#My redirect

RewriteRule ^some_url.html$ https://www.example.com/some/new_url/ [L,R=301,NC]

#End redirect

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
#BEGIN CUSTOM

Note that the simple 301 redirect:

 Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html Redirect 301 /oldpage2.html http://www.yoursite.com/folder/

as described here, won’t work as is in the WordPress .htaccess, hence the use of the previous method. Not that the URL being redirected does not use the domain name.

If you have to redirect files and folders that are hosted in a subdomain, make sure to modify the .htaccess accordingly in the affected directory.

We also recommend that you redirect your image to not lose any image traffic.

Moving WordPress

WordPress.org has a good documentation about moving wordpress:

https://wordpress.org/support/article/moving-wordpress/

In our case study, the paragraph about changing domain name and URLs is particularly of interest to us.

One thing that is not explicitly mentioned is that the column guid in the wp_posts column in the database won’t change and still refer to your development server. To solve this you might think of running an SQL command to update the gui to your new domain name:

UPDATE wp_posts SET guid = REPLACE(guid, "old[DOT]com",  "new[DOT]com");

but this operation is not recommended due to data serialization issue. I tested one of the recommended plugin in the article (better search replace) and it worked well.

Uninstall problematic plugins before migration

Note that some plugins might cause issue during the migration because they have hardcoded your previous domain (the development one). In that case you might want to uninstall them before migration. Some plugins doesn’t do proper garbage management and you might need to do some manual cleaning.

In my case, I had to uninstall Wordfence and manually clean the database and some files and folders. You will find all required information on Wordfence site. There is an advance uninstall option that is suppose to do that for you, but I was not aware of it at the time. It seems to be a separate plugin:

YITH WooCommerce Wishlist caused also issue by requiring a file that was not there (and also missing in the dev site but without causing issue). So you can also just uninstall it before backing up for migration and reinstall it once migration is complete. In my case I commented out the incriminated line which allow me to access the dashboard and updated the plugin, which solved the issue.

Minimizing down time

If your site have a large amount of pictures and you want to minimize downtime, we recommend that you upload your picture before hand on the production site ahead of the migration.

If you have followed the moving WordPress tutorial, you have done a backup of your development site and its database, changed the URLs in wp settings – general, which leads to a 404, backup your dev site and its database after the change you can upload the following folder to your production site, without interrupting production: wp-admin, wp-content, wp-includes.

Make sure you have php version compatible with wordpress on your production site.

Create a database to upload the database of your dev site (the one you did after changing the domain in the settings). Note the user name, use password, database name and host as you will need it later.

Finalize migration

Once you have finished transferring your pictures and the WordPress folders and imported your database table in the production database, you are ready to finalize the migration. Delete the folders related to the previous version of your site and upload all the WordPress files that lies at the root of your dev site.

robots.txt

Check that your site is discoverable in WP Reading Settings and double check the robots.txt and do your redirect as indicated at the beginning of the article.

Google search console

Make sure to update your site map URL in case it differs from the version prior to migration.

Analytics

And finally add your analytics tracking code to your new site.

Profit.