Sonntag, 17. Januar 2016

GitHub not accepting public SSH key: fix it by switching from HTTP(S) to SSH in the Git repository config

If you clone a Git repository from GitHub via the HTTPS URL, which is placed in the section as shown below, than your public SSH key will not be recognized by GitHub.

You can test your public SSH key for GitHub usage by the following command:
ssh -T git@github.com

If you have chosen the wrong HTTPS option before (it must be SSH), you can fix that by the following steps.
  1. Open the file at .git/config
  2. Look for 
    url = http://github.com/path/to/repository 
    or url = https://github.com/path/to/repository
  3. Replace it by
    url = ssh://git@github.com/path/to/repository
  4. Save the file and GitHub will accept the public SSH key on the next push. No username and password typing anymore.


Freitag, 8. Januar 2016

Fix Line Endings Between Various File Systems

If you work sometimes on Windows, sometimes on Mac and sometimes on Linux, you can get troubles with line endings. Programs which aren't smart enough to detect line endings by them self, will display the text as if the file contained no line breaks at all.

  • Windows, and DOS before uses a pair of CR and LF characters to terminate lines
  • UNIX (Including Linux and FreeBSD) uses an LF character only. 
  • OS X also uses a single LF character 
  • Classic Mac operating system used a single CR character for line breaks. 
That's tricky. A tool for fixing line endings is "SFK - The Swiss File Knife File Tree Processor". It's mentioned at http://stackoverflow.com/questions/7068179/convert-line-endlings-for-whole-directory-tree-git/16886243#16886243.

All you have is to use the following command for converting to Mac OSX:
sfk remcr -dir your_project_directory

The project homepage is at http://stahlworks.com/dev/index.php?tool=remcrlf



Mittwoch, 16. Dezember 2015

Rsync two folders via SSH and exclude multiple folders

Here is an example command:

rsync -a --progress source-folder/ --exclude=sites/default/files/ --exclude=ru/ --exclude=us/ --exclude=.idea/ --exclude=.vagrant/ --exclude=provisioning/ --exclude=.git ssh-user@some-host.com:/destination/folder

Freitag, 11. Dezember 2015

Git: Fixing "error: src refspec BRANCHNAME matches more than one."

Sometimes it happens, that there're more heads with the same name in the Git repository. That can happen by copy and pasting folders. To delete any duplicate head, the following command can be used.


git push origin --delete refs/heads/BRANCHNAME

Then

git push origin BRANCHNAME

should work again.

Donnerstag, 30. Juli 2015

Yii2: Bring the assets from your module to your view

If you want to ship assets (JavaScript, CSS files) from your Yii2 module to your view, you can do that elegant with a couple of simple steps.

1., Folder structure

We assume that your Yii2 module is located at

/yii-base-folder/modules/YOUR-YII-MODULE-FOLDER

The assets are at

/yii-base-folder/modules/YOUR-YII-MODULE-FOLDER/assets

So the JavaScript files are at

/yii-base-folder/modules/YOUR-YII-MODULE-FOLDER/assets/js

2., Set an alias to your assets in your Module.php in your module (/yii-base-folder/modules/YOUR-YII-MODULE-FOLDER/Module.php)


3., Put your asset class into your assets folder to setup your "assets bundle"

We name a bunch of assets "assets bundle". Here you declare your files and make it accessible to your view.

4., Now you can access your assets from your view

We assume that your view's index.php file is located at /yii-base-folder/modules/YOUR-MODULE/views/ANY-VIEWS-SUBFOLDER/index.php

5., Conclusion

Now Yii2 puts your CSS and JavaScript files nicely into your HTML. By default the JavaScript files will be put nicely into the footer of your HTML. Also the CSS and JavaScript files will be copied into your web-accessible assets folder. The users from your webpage will not be allowed to get info about your Yii project folder structure. So the path to your JavaScript file will look like that: 

The path in your project's directory will be:
/YOUR-Yii2-PROJECT/web/assets/3598bbc6/js/YOUR-JavaScript-File.js

Also the PHP asset class will be copied from your module's folder:
/YOUR-Yii2-PROJECT/web/assets/3598bbc6/YourAssetsPhpClass.php

Don't forget to not modify the files at /YOUR-Yii2-PROJECT/web/assets/3598bbc6/ manually, because they're created automatically by the Yii2 framework.

6., Learn more

The "The Definitive Guide to Yii 2.0" is mostly the best first place to learn about Yii2. So you find more detailed information about the assets functionality at the assets chapter. I recommend also to read the excellent PHP class comments in the Yii2 core. Like f.e. /YOUR-Yii2-PROJECT/vendor/yiisoft/yii2/web/AssetBundle.php. Yii2 is one of the few OpenSource projects where the PHP code itself can often lead you to your goals.

Montag, 27. Juli 2015

MySQL: Dump database and compress it from command line via mysqldump

The following command does the job:

mysqldump -uUSERNAME -pPASSWORD --databases DATABASE --lock-all-tables | gzip -9 -c > DATABASE.sql.gz

If the database is very big and you want to check the created SQL, use the following command after unpacking the Gzip archive:

head -n 10 DATABASE.sql

Samstag, 25. Juli 2015

Yii2: Access your services within your module

There're some ways to declare the service in your config file for global use, but I wanted a way to setup my service in my module. Well, it took me a while so I write the way down here to look back in future to not search around the web.

Firstly you need to declare the service in your module:
Afterwards you can access your module wherever you want to (note the cast for handier usage in your IDE):