Friday, December 15, 2017

[JAVASCRIPT] - Finally method using Promise

While don't have finally method on Promise you need to use this trick to run on "finally" of your promise.
var out = false;

var promise = new Promise(function(resolve, reject) {

  if (out) {

    reject();

  } else {

    resolve();

  }

}).then(() => alert('Promise Resolved'))

.catch(() => alert('Promise Failed'))

.then(() => alert('Run this code always - simulate Finally method'));

Monday, November 6, 2017

[mysql] - How to change root Password via command line

Stop current MySQL process
sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
Now open another shell/terminal window, and log in without a password as root:
mysql -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password';
Change the lowercase ‘new-password’ to your new password – and keep the single quotes.
\q
Start MySQL
sudo /usr/local/mysql/support-files/mysql.server start

Tuesday, October 3, 2017

How to change hidden file to unhidden chflags nohidden

How to change hidden file attribute to unhidden on terminal


1. Open terminal and write 

chflags nohidden PATH-TO-YOUR-FILE

Example:


chflags nohidden /Volume/pen/hidden-file.doc

Friday, July 21, 2017

sudo: /etc/sudoers is world writable

How to solve error message on terminal when you execute command with sudo on Mac


1. Open terminal and make a copy of sudoers file

cp /etc/sudoers /etc/sudoers.bck

2. Check the current permissions

ls -l /etc/sudoe*

result:
-rwxrwxrwx+ 1 root wheel 1563 Jul 17 11:07 /etc/sudoers



3. 
Write su and after prompt put the administrator password
su

4. Change the permissions of file to -r--r---- using the command 

chmod 440 /etc/sudoers

5. Exit su 

exit

6. Check again the permissions

ls -l /etc/sudoe*

result:
-r--r-----+ 1 root wheel 1563 Jul 17 11:07 /etc/sudoers

Friday, June 23, 2017

Change default location of screenshots

Change default location of your screenshots on Mac

open terminal and write:

defaults write com.apple.screencapture location ~/Documents/Screenshots

Thursday, June 22, 2017

Friday, June 9, 2017

[TERMINAL] - Remove last char from filename


Rename all PDF* files inside folder and prevent first 15 chars:

for file in *pdf; do mv "$file" "${file::15}".pdf; done

* you can change this value to other one

ex: 

for doc files prevent 5 first chars

for file in *doc; do mv "$file" "${file::5}".pdf; done

Wednesday, May 24, 2017

[TERMINAL] - Move file to folder based by name file.

This command iterate over all PDF files, create a folder with same name of file and move the file to inside.

for i in *.pdf; do folderName=`echo "$i"|cut -d- -f1`; mkdir -p "$folderName"; mv "$i" "$folderName"; done

You can use for PDF or other extension file, just change *.pdf to *.doc, or *.jpg, ...

Monday, May 22, 2017

SOAPUI 5.x.x crashes on OSX


SOAPUI crashes after start (version > 5)


  1. Force Kill all soapUI Processes. Start ‘Activity Monitor’ select soapUI process and kill all. 
  2. Open Finder and navigate to application folder, /Applications/SoapUI-5.x.x.app, right button and select option "Show Package Contents". 
  3. Navigate to /Contents/java/app/bin/ and edit file soapui.sh 
  4. Find and uncomment this line # JAVA_OPTS="$JAVA_OPTS -Dsoapui.browser.disabled=true and save file.
  5. Navigate to /Contents and edit file vmoptions.txt 
  6. Add at end of document insert line -Dsoapui.browser.disabled=true 
  7. Close all documents and start again your SoapUI.


This steps worked for me OS X 10.11.6.
Hope this helps

Replace soapUI-5.x.x.app with your application version, my version is soapUI-5.3.0.app

Friday, May 19, 2017

[HTTPS] - Force Chrome accept self-signed localhost certificate

Open Chrome and paste this code on address bar:
chrome://flags/#allow-insecure-localhost
You should see highlighted text saying: "Allow invalid certificates for resources loaded from localhost"
Click Enable.
IMPORTANT: do this is only for LOCALHOST

Thursday, May 18, 2017

[SVN] - Commands from coomand lin

List of useful commands to use SVN from command line.
svn info
Display information about a local or remote item.

svn list
Display list of directories in the repository.

svn up
Update your code from repository.

svn co http://your-svn-repo/your-project-name/[trunk]
Checkout project from server

svn propget svn:externals . > ext.txt
Get externals from folder to file [ext.txt]

svn propset svn:externals -F ext.txt .
Set ignore list of files to commit [need create file with name .svnignore on base folder]

svn propset svn:ignore -F .svnignore .
Set global (recursive) ignore list of files to commit [need create file with name .svnignore on base folder]

svn propset svn:global-ignore -F .svnignore .
Commit only externals from folder
svn commit --depth empty . -m 'Modify externals definition'
Delete property

svn propdel [svn:externals | svn:ignore | ...]
Set externals from file [ext.txt] to folder
svn commit [path-of-files-to-commit] -m 'YOUR COMMENT'
Submit your changes to repository


svn sw http://your-svn-repo/your-project-name/[branch / tag]
Switch your code to another path


svn log --limit 10 | svn log -l 10
Get the last 10 commits 

Local SSL websites on mac OSX


These instructions will guide you through the process of setting up local, trusted websites on your own computer.

Configuring SSL

Within Terminal, create an SSL directory.
sudo mkdir /etc/apache2/ssl
Next, generate a private key and certificate for your site.
sudo openssl genrsa -out /etc/apache2/ssl/localhost.key 2048
sudo openssl req -new -x509 -key /etc/apache2/ssl/localhost.key -out /etc/apache2/ssl/localhost.crt -days 3650 -subj /CN=localhost
Finally, add the certificate to Keychain Access.
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /etc/apache2/ssl/localhost.crt

Configuring SSL: Setting up a Trusted Virtual Host

Within Terminal, edit the Apache Configuration.
edit /etc/apache2/httpd.conf
Within the editor, uncomment lines 89 and 143 to enable modules required by HTTPS.
LoadModule socache_shmcb_module libexec/apache2/mod_socache_shmcb.so
LoadModule ssl_module libexec/apache2/mod_ssl.so
Next, uncomment line 516 to enable Trusted Virtual Hosts.
Include /private/etc/apache2/extra/httpd-ssl.conf
Back in Terminal, edit the Virtual Hosts configuration.
edit /etc/apache2/extra/httpd-vhosts.conf
Within the editor, add a 443 VirtualHost Name and localhost Directive at the end of the file, replacing indieweb with your user name.
<VirtualHost *:443>
    ServerName localhost
    DocumentRoot "/Users/indieweb/Sites/localhost"

    SSLEngine on
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    SSLCertificateFile /etc/apache2/ssl/localhost.crt
    SSLCertificateKeyFile /etc/apache2/ssl/localhost.key

    <Directory "/Users/indieweb/Sites/localhost">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>
Back in Terminal, edit the SSL configuration.
edit /private/etc/apache2/extra/httpd-ssl.conf
Next, comment lines above to skip the default Server Certificate and Server Private Key.
#SSLCertificateFile "/private/etc/apache2/server.crt"
#SSLCertificateKeyFile "/private/etc/apache2/server.key"
Next, beneath the commented certificates or keys, add references to your certificate and key.
SSLCertificateFile "/etc/apache2/ssl/localhost.crt"
SSLCertificateKeyFile "/etc/apache2/ssl/localhost.key"
Back in Terminal, restart Apache.
sudo apachectl restart
Now, in a web browser, visit https://localhost. The domain should appear trusted, and you should see a message stating that localhost works!.